Files
Huntarr.io/.github/workflows/docker-build-push.yml

97 lines
2.6 KiB
YAML

name: Build and Push Docker Image
on:
push:
branches:
- dev
tags:
- 'v*'
- '[0-9]*'
pull_request:
branches:
- main
- master
- dev
workflow_dispatch:
inputs:
tag:
description: 'Docker tag to publish (e.g. latest, beta, v1.2.3)'
required: true
default: 'latest'
type: string
permissions:
contents: read
packages: write
jobs:
build-and-push:
name: Build and Push Docker Image
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Determine tags
id: tags
run: |
IMAGES="huntarr/huntarr ghcr.io/plexguide/huntarr"
TAGS=""
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
# Manual release — use whatever tag the user specified
for img in $IMAGES; do
TAGS="${TAGS}${img}:${{ inputs.tag }}"$'\n'
done
elif [[ "${{ github.ref }}" == refs/heads/dev ]]; then
# dev branch → dev tag only
for img in $IMAGES; do
TAGS="${TAGS}${img}:dev"$'\n'
done
elif [[ "${{ github.ref }}" == refs/tags/* ]]; then
# Version tags → version tag only, NO latest
VERSION="${GITHUB_REF#refs/tags/}"
for img in $IMAGES; do
TAGS="${TAGS}${img}:${VERSION}"$'\n'
done
fi
# Remove trailing newline and set output
TAGS=$(echo "$TAGS" | sed '/^$/d')
echo "tags<<EOF" >> $GITHUB_OUTPUT
echo "$TAGS" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Login to DockerHub
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Login to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and Push
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.tags.outputs.tags }}
cache-from: type=gha
cache-to: type=gha,mode=max