Skip to content

Commit 2059019

Browse files
committed
ci(docker): add workflow_dispatch inputs for manual version tagging
Add `version` (string) and `latest` (bool) inputs so the Docker workflow can be manually re-run for a past release without moving any git tag. The input is passed verbatim into main.version via ldflags (preserving the leading `v` to match tag-push builds), while docker/metadata-action's semver parser normalizes it to bare-number image tags (1.0.3 / 1.0 / 1) per Docker convention.
1 parent ee5fdf4 commit 2059019

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

.github/workflows/docker.yml

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ on:
2323
- 'docker-entrypoint.sh'
2424
- '.github/workflows/docker.yml'
2525
workflow_dispatch:
26+
inputs:
27+
version:
28+
description: 'Version to tag the image with — use the same form as the matching git tag, e.g. v1.0.3 (leave blank to skip semver tags).'
29+
required: false
30+
type: string
31+
latest:
32+
description: 'Also tag this build as `latest`.'
33+
required: false
34+
type: boolean
35+
default: true
2636

2737
permissions:
2838
contents: read
@@ -41,7 +51,12 @@ jobs:
4151
- name: Resolve version
4252
id: ver
4353
run: |
44-
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
54+
manual="${{ inputs.version }}"
55+
if [[ -n "$manual" ]]; then
56+
# Keep the input verbatim so the in-binary version string matches
57+
# what tag-push builds produce (e.g. "v1.0.3", not "1.0.3").
58+
echo "version=${manual}" >> "$GITHUB_OUTPUT"
59+
elif [[ "${GITHUB_REF}" == refs/tags/* ]]; then
4560
echo "version=${GITHUB_REF#refs/tags/}" >> "$GITHUB_OUTPUT"
4661
else
4762
echo "version=dev-${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT"
@@ -64,13 +79,16 @@ jobs:
6479
with:
6580
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
6681
tags: |
67-
type=ref,event=branch
82+
type=ref,event=branch,enable=${{ github.event_name != 'workflow_dispatch' }}
6883
type=ref,event=pr
6984
type=semver,pattern={{version}}
7085
type=semver,pattern={{major}}.{{minor}}
7186
type=semver,pattern={{major}}
87+
type=semver,pattern={{version}},value=${{ inputs.version }},enable=${{ github.event_name == 'workflow_dispatch' && inputs.version != '' }}
88+
type=semver,pattern={{major}}.{{minor}},value=${{ inputs.version }},enable=${{ github.event_name == 'workflow_dispatch' && inputs.version != '' }}
89+
type=semver,pattern={{major}},value=${{ inputs.version }},enable=${{ github.event_name == 'workflow_dispatch' && inputs.version != '' }}
7290
type=sha,prefix=sha-,format=short
73-
type=raw,value=latest,enable={{is_default_branch}}
91+
type=raw,value=latest,enable=${{ (github.event_name == 'push' && github.ref == format('refs/heads/{0}', github.event.repository.default_branch)) || (github.event_name == 'workflow_dispatch' && inputs.latest) }}
7492
7593
- name: Build and push
7694
uses: docker/build-push-action@v6

0 commit comments

Comments
 (0)