Nightly Build and Release #71
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Nightly Build and Release | |
on: | |
schedule: | |
- cron: "0 0 * * *" # Runs every day at midnight UTC | |
workflow_dispatch: # Allows manual trigger | |
push: # Triggers on commits | |
branches: | |
- main | |
permissions: | |
contents: write | |
packages: write | |
security-events: write | |
jobs: | |
check-and-build: | |
runs-on: ubuntu-latest | |
outputs: | |
new_release: ${{ steps.set-output.outputs.new_release }} | |
latest_commit_hash: ${{ steps.set-output.outputs.latest_commit_hash }} | |
latest_server_tag: ${{ steps.set-output.outputs.latest_server_tag }} | |
steps: | |
# Step 1: Checkout repository | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
# Step 2: Set up Node.js | |
- name: Set up Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: '20' | |
# Step 3: Install dependencies | |
- name: Install dependencies | |
run: npm install | |
# Step 4: Fetch latest Stremio versions | |
- name: Fetch latest Stremio versions | |
run: node scripts/fetch-latest-stremio.js | |
# Step 5: Get the latest release description | |
- name: Get latest release | |
id: latest-release | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const fs = require('fs'); | |
try { | |
const latestRelease = await github.rest.repos.getLatestRelease({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
}); | |
const githubEnvPath = process.env.GITHUB_ENV; | |
const description = latestRelease.data.body || ''; | |
const escapedDescription = description.replace(/\n/g, '\\n').replace(/"/g, '\\"'); | |
fs.appendFileSync(githubEnvPath, `DESCRIPTION="${escapedDescription}"\n`); | |
fs.appendFileSync(githubEnvPath, `FOUND=true\n`); | |
} catch (error) { | |
if (error.status === 404) { | |
console.log('No releases found. This is the initial run.'); | |
const githubEnvPath = process.env.GITHUB_ENV; | |
fs.appendFileSync(githubEnvPath, `DESCRIPTION=''\n`); | |
fs.appendFileSync(githubEnvPath, `FOUND=false\n`); | |
} else { | |
throw error; | |
} | |
} | |
# Step 6: Compare fetched versions with release versions and set outputs | |
- name: Check for new versions and set outputs | |
id: set-output | |
run: | | |
if [ "$FOUND" != "true" ]; then | |
echo "new_release=true" >> $GITHUB_OUTPUT | |
else | |
if [[ "$DESCRIPTION" == *"$LATEST_COMMIT_HASH"* && "$DESCRIPTION" == *"$LATEST_SERVER_TAG"* ]]; then | |
echo "new_release=false" >> $GITHUB_OUTPUT | |
else | |
echo "new_release=true" >> $GITHUB_OUTPUT | |
fi | |
fi | |
echo "latest_commit_hash=$LATEST_COMMIT_HASH" >> $GITHUB_OUTPUT | |
echo "latest_server_tag=$LATEST_SERVER_TAG" >> $GITHUB_OUTPUT | |
- name: Debug Variables | |
run: | | |
echo "DESCRIPTION: $DESCRIPTION" | |
echo "FOUND: $FOUND" | |
echo "LATEST_COMMIT_HASH: $LATEST_COMMIT_HASH" | |
echo "LATEST_SERVER_TAG: $LATEST_SERVER_TAG" | |
# Step 7: Upload stremio-web and stremio-server as artifacts | |
- name: Upload stremio-web and stremio-server | |
if: ${{ steps.set-output.outputs.new_release == 'true' }} | |
uses: actions/upload-artifact@v4 | |
with: | |
name: stremio-artifacts | |
path: | | |
src/stremio-web | |
src/stremio-server | |
- name: Check trigger type | |
id: check-trigger | |
run: | | |
if [ "${{ github.event_name }}" == "push" ]; then | |
echo "new_release=true" >> $GITHUB_OUTPUT | |
echo "Triggered by push. Skipping version check." | |
else | |
echo "new_release=false" >> $GITHUB_OUTPUT | |
fi | |
build: | |
needs: check-and-build | |
if: ${{ needs.check-and-build.outputs.new_release == 'true' }} | |
strategy: | |
matrix: | |
os: [windows-latest, macos-latest, ubuntu-latest] | |
runs-on: ${{ matrix.os }} | |
steps: | |
# Step 1: Checkout repository | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
# Step 2: Download stremio-artifacts | |
- name: Download stremio-artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
name: stremio-artifacts | |
path: src | |
# Step 3: Set up Node.js | |
- name: Set up Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: '20' | |
# Step 4: Install dependencies | |
- name: Install dependencies | |
run: npm install | |
# Step 5: Build for platform and handle Windows ZIP and setup.exe | |
- name: Build for ${{ matrix.os }} | |
shell: bash | |
run: | | |
if [ "${{ matrix.os }}" == "windows-latest" ]; then | |
echo "Building for Windows..." | |
npm run make -- --platform=win32 | |
echo "Creating ZIP for Windows..." | |
mkdir -p out/windows/ | |
# Compress with PowerShell, excluding start.exe | |
pwsh -Command "Compress-Archive -Path 'out/stremio-web-desktop-win32-x64/*' -DestinationPath 'out/windows/stremio-web-desktop-win32-x64.zip'" | |
# Find the setup.exe with random name and copy to out/windows/ | |
setup_exe=$(find out/make/squirrel.windows/x64/ -type f -name "*.exe" | head -n 1) | |
cp "$setup_exe" out/windows/ | |
elif [ "${{ matrix.os }}" == "macos-latest" ]; then | |
echo "Building for macOS..." | |
npm run make -- --platform=darwin | |
elif [ "${{ matrix.os }}" == "ubuntu-latest" ]; then | |
echo "Building for Linux..." | |
npm run make -- --platform=linux | |
fi | |
# Step 6: Upload build artifacts | |
- name: Upload build artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: stremio-${{ matrix.os }} | |
path: | | |
# Windows: Upload ZIP and setup.exe | |
out/windows/*.zip | |
out/windows/*.exe | |
# macOS: Upload DMG | |
out/make/**/*.dmg | |
# Ubuntu: Upload DEB and RPM | |
out/make/**/*.deb | |
out/make/**/*.rpm | |
release: | |
needs: [build, check-and-build] | |
if: ${{ needs.check-and-build.outputs.new_release == 'true' }} | |
runs-on: ubuntu-latest | |
steps: | |
# Step 1: Checkout repository | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Debug Variables | |
run: echo '${{toJSON(needs.check-and-build.outputs)}}' | |
# Step 2: Download all artifacts | |
- name: Download Windows artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
name: stremio-windows-latest | |
path: out/windows | |
- name: Download macOS artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
name: stremio-macos-latest | |
path: out/macos | |
- name: Download Ubuntu artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
name: stremio-ubuntu-latest | |
path: out/ubuntu | |
# Step 3: Create GitHub Release | |
- name: Create GitHub Release | |
uses: ncipollo/[email protected] | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
tag: v${{ github.run_number }} | |
name: "Stremio Web Desktop v${{ github.run_number }}" | |
body: | | |
Web version: ${{needs.check-and-build.outputs.latest_commit_hash}} | |
Server version: ${{needs.check-and-build.outputs.latest_server_tag}} | |
artifacts: | | |
out/windows/**/*.zip | |
out/windows/**/*.exe | |
out/macos/**/*.dmg | |
out/ubuntu/**/*.deb | |
out/ubuntu/**/*.rpm |