Skip to content

Commit dbfe5c4

Browse files
committed
ci: 升级actions版本并优化版本标签处理逻辑
1 parent 6e61e4a commit dbfe5c4

3 files changed

Lines changed: 28 additions & 17 deletions

File tree

.github/workflows/release-to-atomgit.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,17 @@ jobs:
2727
GH_TOKEN: ${{ github.token }}
2828
TAG: ${{ inputs.tag || github.event.workflow_run.head_branch }}
2929
steps:
30-
- uses: actions/checkout@v4
30+
- uses: actions/checkout@v5
3131
- name: 确定发布标签
3232
shell: bash
3333
run: |
3434
set -euo pipefail
35-
if [[ ! "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+ ]]; then
35+
if [[ "$TAG" =~ ^[0-9]+\.[0-9]+\.[0-9]+([-.][0-9A-Za-z.-]+)?$ ]]; then
36+
TAG="v$TAG"
37+
elif [[ ! "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+([-.][0-9A-Za-z.-]+)?$ ]]; then
3638
TAG=$(gh api "repos/$GITHUB_REPOSITORY/releases?per_page=1" --jq '.[0].tag_name')
3739
fi
38-
if [[ -z "$TAG" || ! "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+ ]]; then
40+
if [[ -z "$TAG" || ! "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+([-.][0-9A-Za-z.-]+)?$ ]]; then
3941
echo "无法确定 GitHub Release 标签" >&2
4042
exit 1
4143
fi

.github/workflows/release.yml

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
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 ./...
@@ -41,6 +45,8 @@ jobs:
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:
@@ -66,8 +72,10 @@ jobs:
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: 构建并压缩
@@ -76,7 +84,7 @@ jobs:
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
@@ -86,7 +94,7 @@ jobs:
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/*

.github/workflows/sync-atomgit.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
ATOMGIT_REPOSITORY: ${{ vars.ATOMGIT_REPOSITORY || 'certd/certd-client' }}
1919
ATOMGIT_TOKEN: ${{ secrets.ATOMGIT_TOKEN }}
2020
steps:
21-
- uses: actions/checkout@v4
21+
- uses: actions/checkout@v5
2222
with:
2323
fetch-depth: 0
2424
persist-credentials: true

0 commit comments

Comments
 (0)