ci: add GHCR publish workflow gated by tests
Some checks failed
CI / test (push) Has been cancelled

- build & push image on tag
- publish :latest only for semver tags
- multi-arch (amd64, arm64)

https://chatgpt.com/share/694ae4b0-ca28-800f-863c-0916a2f62a43
This commit is contained in:
Kevin Veen-Birkenbach
2025-12-23 19:51:10 +01:00
parent a2010cd914
commit bac453c435

74
.github/workflows/publish-image.yml vendored Normal file
View File

@@ -0,0 +1,74 @@
name: publish-image
on:
push:
tags:
- "*"
jobs:
tests:
uses: ./.github/workflows/reusable-test.yml
build-and-push:
needs: tests
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
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: Extract tag
id: meta
run: |
echo "tag=${GITHUB_REF_NAME}" >> "$GITHUB_OUTPUT"
- name: Check semver tag
id: semver
run: |
if [[ "${GITHUB_REF_NAME}" =~ ^v?[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "is_semver=true" >> "$GITHUB_OUTPUT"
else
echo "is_semver=false" >> "$GITHUB_OUTPUT"
fi
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push (tag)
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
push: true
platforms: linux/amd64,linux/arm64
tags: |
ghcr.io/${{ github.repository }}:${{ steps.meta.outputs.tag }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Build and push (latest)
if: steps.semver.outputs.is_semver == 'true'
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
push: true
platforms: linux/amd64,linux/arm64
tags: |
ghcr.io/${{ github.repository }}:latest
cache-from: type=gha
cache-to: type=gha,mode=max