Skip to content

Commit dd7397e

Browse files
committed
Add version input to Docker build workflow
- Add optional 'version' input parameter to workflow_dispatch - If version is provided, use it directly as the tag - If version is empty, fall back to automatic tag detection - Refactor tag determination logic for better flexibility
1 parent 783f688 commit dd7397e

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

.github/workflows/docker-build.yml

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ name: Build and Push Docker Image
33
on:
44
workflow_dispatch:
55
inputs:
6+
version:
7+
description: 'Version tag to build (leave empty to use latest)'
8+
required: false
9+
type: string
610
tag_as_latest:
711
description: 'Tag image as latest'
812
required: false
@@ -23,19 +27,29 @@ jobs:
2327

2428
- name: Get latest version tag
2529
id: get-tag
30+
if: inputs.version == ''
2631
run: |
2732
git fetch --tags
2833
29-
LATEST_TAG=$(git tag | grep '^v[0-9]\+\.[0-9]\+\.[0-9]\+(-rc\.[0-9]\+)?$' | sort -V | tail -1)
34+
LATEST_TAG=$(git tag | grep '^v[0-9]\+\.[0-9]\+\.[0-9]\+\(-rc\.[0-9]\+\)\?$' | sort -V | tail -1)
3035
if [ -z "$LATEST_TAG" ]; then
3136
echo "No version tags found"
3237
exit 1
3338
fi
3439
echo "tag=$LATEST_TAG" >> $GITHUB_OUTPUT
3540
41+
- name: Set version tag
42+
id: version-tag
43+
run: |
44+
if [ -n "${{ inputs.version }}" ]; then
45+
echo "tag=${{ inputs.version }}" >> $GITHUB_OUTPUT
46+
else
47+
echo "tag=${{ steps.get-tag.outputs.tag }}" >> $GITHUB_OUTPUT
48+
fi
49+
3650
- name: Checkout tag
3751
run: |
38-
git checkout ${{ steps.get-tag.outputs.tag }}
52+
git checkout ${{ steps.version-tag.outputs.tag }}
3953
4054
- name: Log in to GitHub Container Registry
4155
uses: docker/login-action@v3
@@ -50,7 +64,7 @@ jobs:
5064
with:
5165
images: ghcr.io/${{ github.repository }}
5266
tags: |
53-
type=raw,value=${{ steps.get-tag.outputs.tag }}
67+
type=raw,value=${{ steps.version-tag.outputs.tag }}
5468
type=raw,value=latest,enable=${{ inputs.tag_as_latest }}
5569
5670
- name: Build and push Docker image
@@ -61,4 +75,4 @@ jobs:
6175
tags: ${{ steps.meta.outputs.tags }}
6276
labels: ${{ steps.meta.outputs.labels }}
6377
build-args: |
64-
VERSION=${{ steps.get-tag.outputs.tag }}
78+
VERSION=${{ steps.version-tag.outputs.tag }}

0 commit comments

Comments
 (0)