Docker Build and Release #96
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: Docker 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: | |
fetch-and-check: | |
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 | |
docker-build-and-push: | |
needs: fetch-and-check | |
if: ${{ needs.fetch-and-check.outputs.new_release == 'true' }} | |
runs-on: ubuntu-latest | |
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 | |
- name: Docker Setup QEMU | |
uses: docker/setup-qemu-action@v3 | |
id: qemu | |
with: | |
platforms: amd64,arm64 | |
# Step 4: Log in to GitHub Container Registry | |
- name: Log into ghcr.io registry | |
uses: docker/[email protected] | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Set up Docker Buildx | |
uses: docker/[email protected] | |
# Step 5: Build and push Docker image to GHCR | |
- name: Build and push Docker image | |
uses: docker/[email protected] | |
with: | |
context: . | |
file: ./Dockerfile | |
platforms: linux/amd64,linux/arm64 | |
push: true | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
tags: | | |
ghcr.io/zaarrg/stremio-web-desktop:latest | |
ghcr.io/zaarrg/stremio-web-desktop:${{ needs.fetch-and-check.outputs.latest_commit_hash }}-${{ needs.fetch-and-check.outputs.latest_server_tag }} |