Skip to content

Commit aca3b3b

Browse files
committed
fix: improve Docker tagging strategy and auto-tag workflow
- Modify auto-tag.yml to use PAT_TOKEN for triggering downstream workflows - Add automatic CI/CD trigger after tag creation to ensure Docker images are built - Improve Docker tagging strategy in ci-cd.yml: - Separate main tag (branch pushes only) from release tags - Add stable tag as alias for latest - Add support for pre-release tags (beta, rc) - Exclude beta/rc from latest tag - Clarify tagging logic with improved comments
1 parent b01dca4 commit aca3b3b

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed

.github/workflows/auto-tag.yml

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ jobs:
2222
uses: actions/checkout@v4
2323
with:
2424
fetch-depth: 0
25+
token: ${{ secrets.PAT_TOKEN || secrets.GITHUB_TOKEN }}
2526

2627
- name: Set up Git
2728
run: |
@@ -67,9 +68,9 @@ jobs:
6768
# Add PR info to tag message
6869
TAG_MESSAGE="Release $NEW_TAG from PR #${{ steps.pr_info.outputs.pr_number }}: ${{ github.event.pull_request.title }}"
6970
70-
# Create and push tag
71+
# Create and push tag using PAT for workflow triggering
7172
git tag -a "$NEW_TAG" -m "$TAG_MESSAGE"
72-
git push origin "$NEW_TAG"
73+
git push https://x-access-token:${{ secrets.PAT_TOKEN || secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git "$NEW_TAG"
7374
7475
echo "new_tag=$NEW_TAG" >> $GITHUB_OUTPUT
7576
@@ -91,5 +92,22 @@ jobs:
9192
draft: false
9293
prerelease: false
9394
env:
94-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
95+
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN || secrets.GITHUB_TOKEN }}
96+
97+
- name: Trigger CI/CD for Docker Build
98+
uses: actions/github-script@v7
99+
with:
100+
github-token: ${{ secrets.PAT_TOKEN || secrets.GITHUB_TOKEN }}
101+
script: |
102+
const response = await github.rest.actions.createWorkflowDispatch({
103+
owner: context.repo.owner,
104+
repo: context.repo.repo,
105+
workflow_id: 'ci-cd.yml',
106+
ref: '${{ steps.tag.outputs.new_tag }}',
107+
inputs: {
108+
reason: 'Auto-triggered from release ${{ steps.tag.outputs.new_tag }}'
109+
}
110+
});
111+
console.log('Triggered CI/CD workflow for tag ${{ steps.tag.outputs.new_tag }}');
112+
console.log('Response:', response.status);
95113

.github/workflows/ci-cd.yml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,15 +149,20 @@ jobs:
149149
${{ env.REGISTRY_IMAGE }}
150150
${{ env.GITHUB_IMAGE }}
151151
tags: |
152-
# Latest tag - ONLY for git tags (semantic versions/releases)
153-
type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/v') }}
154-
# Main tag - for git tags (semantic versions) AND main branch pushes
155-
type=raw,value=main,enable=${{ startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main' }}
152+
# Latest tag - ONLY for git tags (semantic versions/releases) - points to the latest stable release
153+
type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/v') && !contains(github.ref, 'beta') && !contains(github.ref, 'rc') }}
154+
# Stable tag - alias for latest, easier to understand for users
155+
type=raw,value=stable,enable=${{ startsWith(github.ref, 'refs/tags/v') && !contains(github.ref, 'beta') && !contains(github.ref, 'rc') }}
156156
# Semantic version tag - ONLY for git tags (releases)
157157
type=raw,value=${{ needs.test-and-build.outputs.version }},enable=${{ startsWith(github.ref, 'refs/tags/v') }}
158-
# Develop branch tag
158+
# Main branch tag - ONLY for pushes to main branch (not for releases)
159+
type=raw,value=main,enable=${{ github.ref == 'refs/heads/main' }}
160+
# Develop branch tag - for pushes to develop branch
159161
type=raw,value=develop,enable=${{ github.ref == 'refs/heads/develop' }}
160-
# PR tags
162+
# Pre-release tags - for beta and RC versions
163+
type=raw,value=beta,enable=${{ startsWith(github.ref, 'refs/tags/v') && contains(github.ref, 'beta') }}
164+
type=raw,value=rc,enable=${{ startsWith(github.ref, 'refs/tags/v') && contains(github.ref, 'rc') }}
165+
# PR tags - for pull request testing
161166
type=ref,event=pr,prefix=PR-
162167
163168
- name: Log in to Docker Hub

0 commit comments

Comments
 (0)