Add version tag support to build workflow

Tag pushes (v*) now push an additional versioned image tag alongside
:latest and :<sha>. To release: git tag v1.2.0 && git push origin v1.2.0

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-08 21:04:50 -04:00
parent 65c17ab7e8
commit fbd5d04f6f
+19 -10
View File
@@ -1,19 +1,20 @@
# Runs only on pushes to main.
# Builds the Docker image and pushes it to the Forgejo container registry.
# Registry-side layer caching means unchanged layers (npm install, pip install)
# are reused between builds — typically cuts build time from ~4 min to ~45 sec.
# Runs on pushes to main and on version tags (v*).
#
# The resulting image can then be deployed manually via Portainer.
# Branch push (main): builds and pushes :latest + :<sha>
# Tag push (v1.2.0): builds and pushes :latest + :<sha> + :v1.2.0
#
# To cut a versioned release:
# git tag v1.2.0 && git push origin v1.2.0
#
# Required secrets (repo → Settings → Secrets → Actions):
# REGISTRY_USER — your Forgejo username
# REGISTRY_TOKEN — Forgejo PAT with write:packages scope (create at
# git.fabledsword.com → Settings → Applications → Generate Token)
# REGISTRY_TOKEN — Forgejo PAT with write:packages scope
name: Build & push image
on:
push:
branches: [main]
tags: ["v*"]
paths:
- "src/**"
- "frontend/**"
@@ -34,6 +35,16 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Generate image tags
id: tags
run: |
TAGS="${{ env.IMAGE }}:latest,${{ env.IMAGE }}:${{ github.sha }}"
if [[ "${{ github.ref }}" == refs/tags/* ]]; then
TAGS="$TAGS,${{ env.IMAGE }}:${{ github.ref_name }}"
echo "Releasing version ${{ github.ref_name }}"
fi
echo "value=$TAGS" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
@@ -49,8 +60,6 @@ jobs:
with:
context: .
push: true
tags: |
${{ env.IMAGE }}:latest
${{ env.IMAGE }}:${{ github.sha }}
tags: ${{ steps.tags.outputs.value }}
cache-from: type=registry,ref=${{ env.IMAGE }}:cache
cache-to: type=registry,ref=${{ env.IMAGE }}:cache,mode=max