77 workflow_dispatch :
88 inputs :
99 tag :
10- description : " 要发布的版本标签,例如 v0.1 .1"
10+ description : " 要发布的版本标签,可带或不带 v, 例如 0.3 .1"
1111 required : true
1212 type : string
1313
@@ -18,15 +18,19 @@ jobs:
1818 test :
1919 name : 测试 (${{ matrix.os }})
2020 runs-on : ${{ matrix.os }}
21+ env :
22+ RELEASE_TAG : ${{ github.event_name == 'workflow_dispatch' && (startsWith(inputs.tag, 'v') && inputs.tag || format('v{0}', inputs.tag)) || github.ref_name }}
2123 strategy :
2224 fail-fast : false
2325 matrix :
2426 os :
2527 - ubuntu-latest
2628 - windows-latest
2729 steps :
28- - uses : actions/checkout@v4
29- - uses : actions/setup-go@v5
30+ - uses : actions/checkout@v5
31+ with :
32+ ref : ${{ env.RELEASE_TAG }}
33+ - uses : actions/setup-go@v6
3034 with :
3135 go-version : " 1.23.x"
3236 - run : go test ./...
4145 name : ${{ matrix.goos }}-${{ matrix.goarch }}
4246 needs : test
4347 runs-on : ubuntu-latest
48+ env :
49+ RELEASE_TAG : ${{ github.event_name == 'workflow_dispatch' && (startsWith(inputs.tag, 'v') && inputs.tag || format('v{0}', inputs.tag)) || github.ref_name }}
4450 strategy :
4551 fail-fast : false
4652 matrix :
6672 extension : " "
6773 archive : tar.gz
6874 steps :
69- - uses : actions/checkout@v4
70- - uses : actions/setup-go@v5
75+ - uses : actions/checkout@v5
76+ with :
77+ ref : ${{ env.RELEASE_TAG }}
78+ - uses : actions/setup-go@v6
7179 with :
7280 go-version : " 1.23.x"
7381 - name : 构建并压缩
7684 GOARCH : ${{ matrix.goarch }}
7785 EXTENSION : ${{ matrix.extension }}
7886 ARCHIVE : ${{ matrix.archive }}
79- VERSION : ${{ inputs.tag || github.ref_name }}
87+ VERSION : ${{ env.RELEASE_TAG }}
8088 run : |
8189 VERSION="${VERSION#v}"
8290 mkdir -p dist
8694 else
8795 tar -C dist -czf "dist/certd-client-${GOOS}-${GOARCH}.tar.gz" "certd-client${EXTENSION}"
8896 fi
89- - uses : actions/upload-artifact@v4
97+ - uses : actions/upload-artifact@v5
9098 with :
9199 name : certd-client-${{ matrix.goos }}-${{ matrix.goarch }}
92100 path : dist/certd-client-${{ matrix.goos }}-${{ matrix.goarch }}.${{ matrix.archive }}
@@ -96,17 +104,19 @@ jobs:
96104 name : 创建 GitHub Release
97105 needs : build
98106 runs-on : ubuntu-latest
107+ env :
108+ RELEASE_TAG : ${{ github.event_name == 'workflow_dispatch' && (startsWith(inputs.tag, 'v') && inputs.tag || format('v{0}', inputs.tag)) || github.ref_name }}
99109 steps :
100- - uses : actions/checkout@v4
110+ - uses : actions/checkout@v5
101111 with :
102- ref : ${{ inputs.tag || github.ref }}
103- - uses : actions/download-artifact@v4
112+ ref : ${{ env.RELEASE_TAG }}
113+ - uses : actions/download-artifact@v5
104114 with :
105115 path : dist
106116 merge-multiple : true
107117 - name : 读取发布说明
108118 env :
109- TAG : ${{ inputs.tag || github.ref_name }}
119+ TAG : ${{ env.RELEASE_TAG }}
110120 run : |
111121 version="${TAG#v}"
112122 heading="## [${version}]"
@@ -121,7 +131,6 @@ jobs:
121131 ' CHANGELOG.md > release-notes.md
122132 - uses : softprops/action-gh-release@v2
123133 with :
124- tag_name : ${{ inputs.tag || github.ref_name }}
125- target_commitish : ${{ github.sha }}
134+ tag_name : ${{ env.RELEASE_TAG }}
126135 body_path : release-notes.md
127136 files : dist/*
0 commit comments