Skip to content

Commit ad97c06

Browse files
committed
feat: new ghcr tags
1 parent a90273a commit ad97c06

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

.github/workflows/ghcr.yaml

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
name: Build and Push Docker Image to GHCR
22

33
on:
4-
push:
5-
branches:
6-
- master
4+
workflow_run:
5+
workflows: ["Release"]
6+
types:
7+
- completed
78
workflow_dispatch: # 允许手动触发
89

910
jobs:
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
@@ -17,6 +20,8 @@ jobs:
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
@@ -46,6 +51,18 @@ jobs:
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:
@@ -55,6 +72,7 @@ jobs:
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

0 commit comments

Comments
 (0)