Refactor Docker workflow for tag handling

This commit is contained in:
Mike Brady
2026-02-14 12:40:23 +00:00
committed by GitHub
parent d6275eafef
commit 963380a832
+36 -12
View File
@@ -1,10 +1,10 @@
# Builds and pushes a docker image in the following scenarios:
# When a commit is made to 'master' or 'development'.
# Tag pattern
# 'master' - rolling, rolling-classic
# 'development' - development, development-classic
# When a tag is created.
# Tag pattern: '[tag]' & '[tag]-classic', plus 'latest' & 'classic'
# 'master' branch - rolling, rolling-classic (for commits)
# - [tag], [tag]-classic, latest, classic (for tags)
# 'development' branch - development, development-classic (for all pushes including tags)
# Builds but does not push a docker image for PRs.
name: Build and conditionally push docker image
on:
workflow_dispatch:
@@ -37,6 +37,27 @@ jobs:
SHAIRPORT_SYNC_BRANCH=.
NQPTP_BRANCH=${{ needs.docker-vars.outputs.nqptp_branch }}
steps:
- name: Checkout shairport sync repo
uses: actions/checkout@v6.0.2
with:
fetch-depth: 0
- name: Determine which branch the tag belongs to
id: determine_branch
if: github.ref_type == 'tag'
run: |
# Check which branch contains this tag
if git branch -r --contains ${{ github.sha }} | grep -q 'origin/master'; then
echo "branch=master" >> $GITHUB_OUTPUT
echo "Tag ${{ github.ref_name }} is on master branch"
elif git branch -r --contains ${{ github.sha }} | grep -q 'origin/development'; then
echo "branch=development" >> $GITHUB_OUTPUT
echo "Tag ${{ github.ref_name }} is on development branch"
else
echo "branch=unknown" >> $GITHUB_OUTPUT
echo "Warning: Tag ${{ github.ref_name }} is not on master or development branch"
fi
- name: Login to Docker Registry
uses: docker/login-action@v3.7.0
with:
@@ -44,14 +65,13 @@ jobs:
username: ${{ secrets.DOCKER_REGISTRY_USER }}
password: ${{ secrets.DOCKER_REGISTRY_TOKEN }}
if: needs.docker-vars.outputs.push_docker_image == 'true'
- name: Set up QEMU
uses: docker/setup-qemu-action@v3.7.0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3.12.0
- name: Checkout shairport sync repo
uses: actions/checkout@v6.0.2
with:
fetch-depth: 0
- name: Build and push ${{ matrix.name }}
uses: docker/build-push-action@v6.18.0
env:
@@ -67,17 +87,21 @@ jobs:
&& format('{0}:development', env.registry_and_name) || '' }}
${{ github.ref_type == 'branch' && github.ref_name == 'development' && matrix.name == 'classic'
&& format('{0}:development-classic', env.registry_and_name) || '' }}
${{ github.ref_type == 'tag' && steps.determine_branch.outputs.branch == 'development' && matrix.name == 'main'
&& format('{0}:development', env.registry_and_name) || '' }}
${{ github.ref_type == 'tag' && steps.determine_branch.outputs.branch == 'development' && matrix.name == 'classic'
&& format('{0}:development-classic', env.registry_and_name) || '' }}
${{ github.ref_type == 'branch' && github.ref_name == 'master' && matrix.name == 'main'
&& format('{0}:rolling', env.registry_and_name) || '' }}
${{ github.ref_type == 'branch' && github.ref_name == 'master' && matrix.name == 'classic'
&& format('{0}:rolling-classic', env.registry_and_name) || '' }}
${{ github.ref_type == 'tag' && matrix.name == 'main'
${{ github.ref_type == 'tag' && steps.determine_branch.outputs.branch == 'master' && matrix.name == 'main'
&& format('{0}:{1}', env.registry_and_name, github.ref_name) || '' }}
${{ github.ref_type == 'tag' && matrix.name == 'classic'
${{ github.ref_type == 'tag' && steps.determine_branch.outputs.branch == 'master' && matrix.name == 'classic'
&& format('{0}:{1}-classic', env.registry_and_name, github.ref_name) || '' }}
${{ github.ref_type == 'tag' && matrix.name == 'main'
${{ github.ref_type == 'tag' && steps.determine_branch.outputs.branch == 'master' && matrix.name == 'main'
&& format('{0}:latest', env.registry_and_name) || '' }}
${{ github.ref_type == 'tag' && matrix.name == 'classic'
${{ github.ref_type == 'tag' && steps.determine_branch.outputs.branch == 'master' && matrix.name == 'classic'
&& format('{0}:classic', env.registry_and_name) || '' }}
build-args: |
${{ matrix.build_args }}