Skip to content

Commit 05935b9

Browse files
kalicyhsongpingan
andcommitted
🐎 ci(github-action): 优化docker打包
只在推送tag时打包 Co-Authored-By: kyjdzsm <[email protected]>
1 parent e926e5b commit 05935b9

File tree

1 file changed

+5
-26
lines changed

1 file changed

+5
-26
lines changed

.github/workflows/docker-image.yml

+5-26
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ name: Docker Image CI
22

33
on:
44
push:
5-
branches: [ "main" ]
6-
pull_request:
7-
branches: [ "main" ]
5+
tags:
6+
- 'v*.*.*' # 只在以 v 开头的标签推送时触发,例如 v1.0.0
87

98
jobs:
109
release:
@@ -30,30 +29,10 @@ jobs:
3029
username: ${{ github.actor }}
3130
password: ${{ secrets.TOKEN }}
3231

33-
- name: Extract version from package.json
32+
- name: Extract version from tag
3433
id: get_version
3534
run: |
36-
echo "VERSION=$(jq -r '.version' package.json)" >> $GITHUB_ENV
37-
38-
- name: Set Git user info
39-
run: |
40-
git config user.email "[email protected]"
41-
git config user.name "GitHub Actions"
42-
43-
- name: Delete existing tag if it exists
44-
run: |
45-
if git ls-remote --tags origin | grep "refs/tags/v${{ env.VERSION }}"; then
46-
git push origin --delete "v${{ env.VERSION }}"
47-
fi
48-
env:
49-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
50-
51-
- name: Create and push new tag
52-
run: |
53-
git tag -a "v${{ env.VERSION }}" -m "Release version ${{ env.VERSION }}"
54-
git push origin "v${{ env.VERSION }}"
55-
env:
56-
GITHUB_TOKEN: ${{ secrets.TOKEN }}
35+
echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
5736
5837
- name: Build and push Docker image
5938
id: build_push
@@ -64,4 +43,4 @@ jobs:
6443
tags: |
6544
ghcr.io/${{ github.repository }}:${{ env.VERSION }}
6645
ghcr.io/${{ github.repository }}:latest
67-
platforms: linux/amd64,linux/arm64
46+
platforms: linux/amd64,linux/arm64

0 commit comments

Comments
 (0)