107 lines
4.3 KiB
YAML
107 lines
4.3 KiB
YAML
name: Build Prowlarr Container
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
- develop
|
|
schedule:
|
|
- cron: '0 4 * * *' # Daily at 4:00 UTC
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
strategy:
|
|
matrix:
|
|
# On schedule/dispatch, build both branches; otherwise only the pushed branch
|
|
branch: ${{ github.event_name == 'schedule' && fromJson('["main", "develop"]') || fromJson(format('["{0}"]', github.ref_name)) }}
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
with:
|
|
ref: ${{ matrix.branch }}
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Set build variables
|
|
id: vars
|
|
run: |
|
|
# Date ISO 8601
|
|
echo "build_date=$(date -u +%Y-%m-%dT%H:%M:%S%z)" >> "$GITHUB_OUTPUT"
|
|
|
|
# Short SHA of docker-prowlarr repo
|
|
echo "sha_short=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT"
|
|
|
|
# Corresponding upstream Prowlarr branch
|
|
PROWLARR_BRANCH="develop"
|
|
if [ "${{ matrix.branch }}" = "main" ]; then
|
|
PROWLARR_BRANCH="master"
|
|
fi
|
|
echo "prowlarr_branch=${PROWLARR_BRANCH}" >> "$GITHUB_OUTPUT"
|
|
|
|
# Latest commit SHA on the upstream Prowlarr repo
|
|
UPSTREAM_SHA=$(git ls-remote https://github.com/Prowlarr/Prowlarr.git "refs/heads/${PROWLARR_BRANCH}" | awk '{print $1}')
|
|
UPSTREAM_SHA_SHORT=$(echo "${UPSTREAM_SHA}" | cut -c1-7)
|
|
echo "upstream_sha=${UPSTREAM_SHA}" >> "$GITHUB_OUTPUT"
|
|
echo "upstream_sha_short=${UPSTREAM_SHA_SHORT}" >> "$GITHUB_OUTPUT"
|
|
echo "Prowlarr upstream ${PROWLARR_BRANCH} is at ${UPSTREAM_SHA_SHORT}"
|
|
|
|
# Prowlarr version from upstream API
|
|
PROWLARR_VERSION=$(curl -sL "https://prowlarr.servarr.com/v1/update/${PROWLARR_BRANCH}/changes?runtime=netcore&os=linuxmusl" | jq -r '.[0].version')
|
|
echo "prowlarr_version=${PROWLARR_VERSION}" >> "$GITHUB_OUTPUT"
|
|
|
|
# Image name
|
|
REGISTRY="${{ vars.OCI_REGISTRY }}"
|
|
REGISTRY="${REGISTRY%/}"
|
|
echo "image_name=${REGISTRY}/prowlarr" >> "$GITHUB_OUTPUT"
|
|
|
|
# Channel tag: latest for main, develop for develop
|
|
if [ "${{ matrix.branch }}" = "main" ]; then
|
|
echo "channel_tag=latest" >> "$GITHUB_OUTPUT"
|
|
else
|
|
echo "channel_tag=develop" >> "$GITHUB_OUTPUT"
|
|
fi
|
|
|
|
- name: Login to OCI Registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ vars.OCI_REGISTRY }}
|
|
username: ${{ vars.OCI_USERNAME }}
|
|
password: ${{ vars.OCI_PASSWORD }}
|
|
|
|
- name: Check if upstream version already built
|
|
id: check
|
|
if: github.event_name == 'schedule'
|
|
run: |
|
|
# Check if an image tagged with the upstream SHA already exists
|
|
IMAGE="${{ steps.vars.outputs.image_name }}:${{ steps.vars.outputs.prowlarr_branch }}-${{ steps.vars.outputs.upstream_sha_short }}"
|
|
echo "Checking if ${IMAGE} already exists..."
|
|
if docker manifest inspect "${IMAGE}" > /dev/null 2>&1; then
|
|
echo "Image ${IMAGE} already exists — no upstream changes, skipping build."
|
|
echo "skip=true" >> "$GITHUB_OUTPUT"
|
|
else
|
|
echo "Image ${IMAGE} not found — upstream has changed, proceeding with build."
|
|
echo "skip=false" >> "$GITHUB_OUTPUT"
|
|
fi
|
|
|
|
- name: Build and push
|
|
if: steps.check.outputs.skip != 'true'
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
context: .
|
|
file: ./Dockerfile
|
|
push: true
|
|
build-args: |
|
|
BUILD_DATE=${{ steps.vars.outputs.build_date }}
|
|
VERSION=${{ steps.vars.outputs.prowlarr_version }}-custom
|
|
PROWLARR_BRANCH=${{ steps.vars.outputs.prowlarr_branch }}
|
|
tags: |
|
|
${{ steps.vars.outputs.image_name }}:${{ steps.vars.outputs.channel_tag }}
|
|
${{ steps.vars.outputs.image_name }}:${{ steps.vars.outputs.sha_short }}
|
|
${{ steps.vars.outputs.image_name }}:${{ steps.vars.outputs.prowlarr_version }}-custom
|
|
${{ steps.vars.outputs.image_name }}:${{ steps.vars.outputs.prowlarr_branch }}-${{ steps.vars.outputs.upstream_sha_short }}
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|