Skip to content

Commit 9afef0f

Browse files
authored
feat(release): 引入发布准备与手动发布 (#4)
feat(release): 自动准备版本 PR 并支持手动发布
2 parents e70b17a + a7fc29f commit 9afef0f

15 files changed

Lines changed: 880 additions & 94 deletions

‎.github/workflows/check.yaml‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,20 @@ on:
66
branches:
77
- '**'
88
workflow_call:
9+
inputs:
10+
ref:
11+
type: string
12+
required: true
13+
publish:
14+
type: boolean
15+
default: false
916

1017
permissions:
1118
contents: read
1219

1320
concurrency:
14-
group: check-${{ github.workflow }}-${{ github.ref }}
15-
cancel-in-progress: ${{ github.ref_type != 'tag' }}
21+
group: check-${{ github.workflow }}-${{ inputs.ref || github.ref }}
22+
cancel-in-progress: ${{ !inputs.publish }}
1623

1724
jobs:
1825
check:
@@ -29,6 +36,8 @@ jobs:
2936
steps:
3037
- name: 检出代码
3138
uses: actions/checkout@v5
39+
with:
40+
ref: ${{ inputs.ref || github.sha }}
3241
- name: 安装 JDK
3342
uses: actions/setup-java@v5
3443
with:
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Prepare Release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: '待发布的新版本(SemVer,不带 v,例如 0.1.0 或 0.1.0-rc.1)'
8+
required: true
9+
type: string
10+
11+
permissions:
12+
contents: write
13+
pull-requests: write
14+
15+
concurrency:
16+
group: prepare-release
17+
cancel-in-progress: false
18+
19+
jobs:
20+
prepare:
21+
name: 准备版本并创建发布 PR
22+
runs-on: ubuntu-24.04
23+
steps:
24+
- name: 限定主分支入口
25+
env:
26+
RELEASE_REF: ${{ github.ref }}
27+
run: |
28+
if [ "$RELEASE_REF" != 'refs/heads/master' ]; then
29+
echo '请从 master 手动运行 Prepare Release。'
30+
exit 1
31+
fi
32+
- uses: actions/checkout@v5
33+
with:
34+
ref: ${{ github.sha }}
35+
fetch-depth: 0
36+
- uses: oven-sh/setup-bun@v2
37+
with:
38+
bun-version-file: .bun-version
39+
- name: 创建或恢复发布准备 PR
40+
id: prepare
41+
env:
42+
GH_TOKEN: ${{ github.token }}
43+
RELEASE_VERSION: ${{ inputs.version }}
44+
run: bun scripts/prepare-release.ts

‎.github/workflows/publish.yaml‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Publish
2+
3+
on:
4+
workflow_dispatch:
5+
6+
permissions:
7+
contents: read
8+
9+
jobs:
10+
request:
11+
name: 确认发布入口
12+
runs-on: ubuntu-24.04
13+
steps:
14+
- name: 仅允许从 master 发布
15+
env:
16+
RELEASE_REF: ${{ github.ref }}
17+
RELEASE_SHA: ${{ github.sha }}
18+
run: |
19+
if [ "$RELEASE_REF" != 'refs/heads/master' ]; then
20+
echo '请在 master 分支手动运行 Publish 工作流。'
21+
exit 1
22+
fi
23+
echo "发布提交:$RELEASE_SHA" >> "$GITHUB_STEP_SUMMARY"
24+
25+
publish:
26+
needs: request
27+
permissions:
28+
contents: write
29+
uses: ./.github/workflows/release.yaml
30+
with:
31+
publish: true

‎.github/workflows/release.yaml‎

Lines changed: 38 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,76 @@
1-
name: Release
1+
name: Release Verify
22

33
on:
44
push:
5-
tags:
6-
- 'v*'
75
branches:
86
- '**'
97
paths:
108
- '.github/workflows/release.yaml'
119
- '.github/workflows/check.yaml'
10+
- '.github/workflows/publish.yaml'
11+
- '.github/workflows/prepare-release.yaml'
1212
- 'scripts/compile.ts'
1313
- 'scripts/checksum.ts'
1414
- 'scripts/platforms.ts'
1515
- 'scripts/release.ts'
16+
- 'scripts/publish-release.ts'
17+
- 'scripts/prepare-release.ts'
1618
- 'scripts/smoke.ts'
1719
- 'docs/installation.md'
1820
- 'LICENSE*'
1921
- 'tests/compile.test.ts'
2022
- 'tests/release.test.ts'
23+
- 'tests/publish-release.test.ts'
24+
- 'tests/prepare-release.test.ts'
2125
- 'package.json'
2226
- 'bun.lockb'
2327
- 'bump.config.ts'
2428
- '.bun-version'
2529
workflow_dispatch:
30+
workflow_call:
31+
inputs:
32+
publish:
33+
description: 验收通过后创建标签并发布
34+
type: boolean
35+
default: false
2636

2737
permissions:
2838
contents: read
2939

3040
concurrency:
31-
group: release-${{ github.ref }}
32-
cancel-in-progress: ${{ github.ref_type != 'tag' }}
41+
group: release-${{ inputs.publish && 'publish' || github.ref }}
42+
cancel-in-progress: ${{ !inputs.publish }}
3343

3444
jobs:
3545
metadata:
3646
name: 校验版本与发布目标
3747
runs-on: ubuntu-24.04
3848
outputs:
39-
tag: ${{ steps.metadata.outputs.tag }}
40-
prerelease: ${{ steps.metadata.outputs.prerelease }}
4149
matrix: ${{ steps.metadata.outputs.matrix }}
4250
steps:
4351
- uses: actions/checkout@v5
52+
with:
53+
ref: ${{ github.sha }}
54+
fetch-depth: 0
4455
- uses: oven-sh/setup-bun@v2
4556
with:
4657
bun-version-file: .bun-version
47-
- name: 校验标签并生成产物清单
58+
- name: 校验版本并生成产物清单
4859
id: metadata
49-
run: bun scripts/release.ts metadata
50-
- name: 检查发布状态
51-
if: github.event_name == 'push' && github.ref_type == 'tag'
60+
run: bun scripts/release.ts metadata ${{ inputs.publish && '--publish' || '' }}
61+
- name: 检查发布请求、主分支与已有版本
62+
if: inputs.publish
5263
env:
5364
GH_TOKEN: ${{ github.token }}
54-
RELEASE_TAG: ${{ steps.metadata.outputs.tag }}
55-
run: |
56-
if state=$(gh release view "$RELEASE_TAG" --json isDraft --jq .isDraft); then
57-
if [ "$state" != 'true' ]; then
58-
echo '该标签已经公开发布,请使用新版本标签。'
59-
exit 1
60-
fi
61-
fi
65+
run: bun scripts/publish-release.ts check
6266

6367
checks:
6468
needs: metadata
65-
if: github.ref_type == 'tag' || github.event_name == 'workflow_dispatch'
69+
if: inputs.publish || github.event_name == 'workflow_dispatch'
6670
uses: ./.github/workflows/check.yaml
71+
with:
72+
ref: ${{ github.sha }}
73+
publish: ${{ inputs.publish || false }}
6774

6875
build:
6976
name: 验收 ${{ matrix.name }}
@@ -81,6 +88,8 @@ jobs:
8188
steps:
8289
- name: 检出待验收提交
8390
uses: actions/checkout@v5
91+
with:
92+
ref: ${{ github.sha }}
8493
- name: 安装固定版本 Bun
8594
uses: oven-sh/setup-bun@v2
8695
with:
@@ -138,6 +147,8 @@ jobs:
138147
runs-on: ubuntu-24.04
139148
steps:
140149
- uses: actions/checkout@v5
150+
with:
151+
ref: ${{ github.sha }}
141152
- uses: oven-sh/setup-bun@v2
142153
with:
143154
bun-version-file: .bun-version
@@ -165,19 +176,20 @@ jobs:
165176
overwrite: true
166177

167178
release:
168-
name: 发布完整标签产物
179+
name: 创建标签并发布已验收产物
169180
needs: [metadata, checks, artifacts]
170-
if: github.event_name == 'push' && github.ref_type == 'tag'
181+
if: inputs.publish
171182
runs-on: ubuntu-24.04
172183
permissions:
173184
contents: write
174185
env:
175186
GH_TOKEN: ${{ github.token }}
176187
GH_REPO: ${{ github.repository }}
177-
RELEASE_TAG: ${{ needs.metadata.outputs.tag }}
178-
RELEASE_PRERELEASE: ${{ needs.metadata.outputs.prerelease }}
179188
steps:
180189
- uses: actions/checkout@v5
190+
with:
191+
ref: ${{ github.sha }}
192+
fetch-depth: 0
181193
- uses: oven-sh/setup-bun@v2
182194
with:
183195
bun-version-file: .bun-version
@@ -188,34 +200,5 @@ jobs:
188200
- name: 核对待上传文件
189201
working-directory: dist
190202
run: sha256sum --check SHA256SUMS
191-
- name: 生成下载与安装说明
192-
run: |
193-
bun scripts/release.ts notes > release-notes.md
194-
gh api --method POST "repos/$GH_REPO/releases/generate-notes" \
195-
-f tag_name="$RELEASE_TAG" --jq .body >> release-notes.md
196-
- name: 创建或恢复未公开草稿
197-
run: |
198-
if state=$(gh release view "$RELEASE_TAG" --json isDraft --jq .isDraft); then
199-
if [ "$state" != 'true' ]; then
200-
echo '该标签已经公开发布,请使用新版本标签。'
201-
exit 1
202-
fi
203-
gh release edit "$RELEASE_TAG" --title "java-run $RELEASE_TAG" \
204-
--notes-file release-notes.md --prerelease="$RELEASE_PRERELEASE"
205-
else
206-
gh release create "$RELEASE_TAG" --verify-tag --draft \
207-
--notes-file release-notes.md --title "java-run $RELEASE_TAG" \
208-
--prerelease="$RELEASE_PRERELEASE"
209-
fi
210-
- name: 上传完整资产并核对草稿
211-
run: |
212-
gh release upload "$RELEASE_TAG" dist/* --clobber
213-
gh release view "$RELEASE_TAG" --json assets --jq '[.assets[].name]' \
214-
| bun scripts/release.ts verify-assets
215-
- name: 公开已验收版本
216-
run: |
217-
if [ "$RELEASE_PRERELEASE" = 'true' ]; then
218-
gh release edit "$RELEASE_TAG" --draft=false --prerelease=true --latest=false
219-
else
220-
gh release edit "$RELEASE_TAG" --draft=false --prerelease=false
221-
fi
203+
- name: 创建标签、上传草稿资产并公开版本
204+
run: bun scripts/publish-release.ts publish

0 commit comments

Comments
 (0)