File tree Expand file tree Collapse file tree 1 file changed +21
-3
lines changed
Expand file tree Collapse file tree 1 file changed +21
-3
lines changed Original file line number Diff line number Diff line change 11name : Build and Push Docker Image to GHCR
22
33on :
4- push :
5- branches :
6- - master
4+ workflow_run :
5+ workflows : ["Release"]
6+ types :
7+ - completed
78 workflow_dispatch : # 允许手动触发
89
910jobs :
1011 build-and-push :
1112 runs-on : ubuntu-latest
13+ # 只有当 release 工作流成功完成时才执行
14+ if : ${{ github.event.workflow_run.conclusion == 'success' }}
1215
1316 permissions :
1417 contents : read
1720 steps :
1821 - name : Checkout code
1922 uses : actions/checkout@v4
23+ with :
24+ fetch-depth : 0 # 获取完整的 git 历史,包括标签
2025
2126 - name : Set up QEMU
2227 uses : docker/setup-qemu-action@v3
4651 - name : Build static files
4752 run : bun run docs:build
4853
54+ - name : Get version
55+ id : get_version
56+ run : |
57+ # 获取最新的 semantic-release 标签作为版本号
58+ VERSION=$(git describe --tags --abbrev=0 2>/dev/null)
59+ if [ -z "$VERSION" ]; then
60+ echo "No version tag found, using 'latest'"
61+ VERSION="latest"
62+ fi
63+ echo "version=$VERSION" >> $GITHUB_OUTPUT
64+ echo "Found version: $VERSION"
65+
4966 - name : Build and push Docker image
5067 uses : docker/build-push-action@v5
5168 with :
5572 push : true
5673 tags : |
5774 ghcr.io/${{ github.repository }}:latest
75+ ghcr.io/${{ github.repository }}:${{ steps.get_version.outputs.version }}
5876 ghcr.io/${{ github.repository }}:${{ github.sha }}
5977 cache-from : type=gha
6078 cache-to : type=gha,mode=max
You can’t perform that action at this time.
0 commit comments