name: Docker Republish
on:
workflow_dispatch:
inputs:
version:
description: 'Version tag to publish (e.g. 1.2.0)'
required: true
type: string
git_ref:
description: 'Git ref to build from (branch, tag, or commit SHA)'
required: true
default: master
type: string
publish_latest:
description: 'Also publish latest tag'
required: true
default: true
type: boolean
permissions:
contents: read
id-token: write
packages: write
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
publish-docker:
name: Docker
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.git_ref }}
- name: Parse version
id: semver
shell: bash
run: |
VERSION="${{ inputs.version }}"
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+([-.].+)?$ ]]; then
echo "::error::Invalid version '$VERSION'. Expected semver-like format (e.g. 1.2.0)."
exit 1
fi
CORE="${VERSION%%[-+]*}"
IFS='.' read -r MAJOR MINOR PATCH <<< "$CORE"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "major=$MAJOR" >> "$GITHUB_OUTPUT"
echo "major_minor=$MAJOR.$MINOR" >> "$GITHUB_OUTPUT"
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=${{ steps.semver.outputs.version }}
type=raw,value=${{ steps.semver.outputs.major_minor }}
type=raw,value=${{ steps.semver.outputs.major }}
type=raw,value=latest,enable=${{ inputs.publish_latest }}
- name: Build & push
uses: docker/build-push-action@v6
with:
context: .
push: true
platforms: linux/amd64,linux/arm64
build-args: VERSION=${{ steps.semver.outputs.version }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Summary
run: |
cat >> "$GITHUB_STEP_SUMMARY" <<EOF
## 🐳 Docker Image Republished
| | |
|---|---|
| **Ref** | \`${{ inputs.git_ref }}\` |
| **Version** | \`${{ steps.semver.outputs.version }}\` |
| **Image** | \`${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}\` |
| **Platforms** | linux/amd64, linux/arm64 |
| **Latest tag** | \`${{ inputs.publish_latest }}\` |
EOF