Skip to content

Commit 25b421e

Browse files
committed
ci: conditionally assign latest tag to dev builds or releases
- Add latest tag to main branch only when no version tags exist - Switch latest tag to version releases once they are available
1 parent bf80741 commit 25b421e

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

.github/workflows/docker-image.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ jobs:
4343
username: ${{ github.actor }}
4444
password: ${{ secrets.GITHUB_TOKEN }}
4545

46+
# Check if any version tags exist
47+
- name: Check for existing version tags
48+
id: check-tags
49+
run: |
50+
if git tag --list 'v*.*' | grep -q .; then
51+
echo "has_version_tags=true" >> $GITHUB_OUTPUT
52+
else
53+
echo "has_version_tags=false" >> $GITHUB_OUTPUT
54+
fi
55+
4656
# Extract metadata (tags, labels) for Docker
4757
# https://github.com/docker/metadata-action
4858
- name: Extract Docker metadata
@@ -52,7 +62,11 @@ jobs:
5262
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
5363
tags: |
5464
type=raw,value=testing-${{ github.ref_name }}
55-
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
65+
type=raw,value=testing-main,enable=${{ github.ref == 'refs/heads/main' }}
66+
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' && steps.check-tags.outputs.has_version_tags == 'false' }}
67+
type=semver,pattern={{version}}
68+
type=semver,pattern={{major}}.{{minor}}
69+
type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/v') }}
5670
5771
# Build and push Docker image with Buildx (don't push on PR)
5872
# https://github.com/docker/build-push-action

0 commit comments

Comments
 (0)