@@ -2,9 +2,8 @@ name: Docker Image CI
2
2
3
3
on :
4
4
push :
5
- branches : [ "main" ]
6
- pull_request :
7
- branches : [ "main" ]
5
+ tags :
6
+ - ' v*.*.*' # 只在以 v 开头的标签推送时触发,例如 v1.0.0
8
7
9
8
jobs :
10
9
release :
@@ -30,30 +29,10 @@ jobs:
30
29
username : ${{ github.actor }}
31
30
password : ${{ secrets.TOKEN }}
32
31
33
- - name : Extract version from package.json
32
+ - name : Extract version from tag
34
33
id : get_version
35
34
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
57
36
58
37
- name : Build and push Docker image
59
38
id : build_push
64
43
tags : |
65
44
ghcr.io/${{ github.repository }}:${{ env.VERSION }}
66
45
ghcr.io/${{ github.repository }}:latest
67
- platforms : linux/amd64,linux/arm64
46
+ platforms : linux/amd64,linux/arm64
0 commit comments