Repository navigation
158 lines (147 loc) · 5.75 KB
/
Copy pathrelease.yml
File metadata and controls
158 lines (147 loc) · 5.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
name: Release
# tag 推上来就按 CHANGELOG 正文建 GitHub Release。
# 起因:v4.13.0 起的 6 个版本只打了 tag 没建 Release,而应用内检查读的是
# /releases/latest —— 结果"发现新版本"静默失效了好几天,且没有任何地方报错。
# 人工建 Release 是病根本身,所以这里补上自动化。
#
# 注意取舍:本 workflow 不等 CI,tag 一推就发。若希望"只有 CI 绿了才发",
# 改成 workflow_run 触发(在 CI 完成后再跑本文件)即可。
on:
push:
tags:
- 'v*'
# 允许手工补建历史版本(幂等:已存在就跳过)
workflow_dispatch:
inputs:
tag:
description: '要补建 Release 的 tag,例如 v4.12.1'
required: true
type: string
permissions:
contents: write
jobs:
github-release:
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.meta.outputs.tag }}
env:
GH_TOKEN: ${{ github.token }}
steps:
- uses: actions/checkout@v7
with:
# 读 annotated tag 的 subject 作为 Release 标题,需要 tag 对象在本地
fetch-depth: 0
fetch-tags: true
# 所有来自上下文/输入的字符串一律经 env 传入,不内插进 shell —— 防脚本注入。
- name: 解析目标 tag 与标题
id: meta
env:
INPUT_TAG: ${{ inputs.tag }}
REF_NAME: ${{ github.ref_name }}
run: |
set -euo pipefail
TAG="${INPUT_TAG:-$REF_NAME}"
case "$TAG" in
refs/*) TAG="${TAG#refs/tags/}" ;;
esac
# annotated tag 有 subject 就用它;轻量 tag 回落到 tag 名。
TITLE="$(git tag -l --format='%(contents:subject)' "$TAG" 2>/dev/null || true)"
if [ -z "$TITLE" ]; then TITLE="$TAG"; fi
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
{
echo 'title<<EOF_TITLE'
echo "$TITLE"
echo 'EOF_TITLE'
} >> "$GITHUB_OUTPUT"
echo "目标 tag: $TAG"
echo "标题 : $TITLE"
- name: 从 CHANGELOG 抽取正文
env:
TAG: ${{ steps.meta.outputs.tag }}
run: |
set -euo pipefail
# 取不到正文就非零退出 → 本步失败 → 不会发出空正文的 Release。
node scripts/extract-release-notes.mjs "$TAG" CHANGELOG.md > "$RUNNER_TEMP/notes.md"
wc -c "$RUNNER_TEMP/notes.md"
- name: 创建 Release(已存在则跳过)
env:
TAG: ${{ steps.meta.outputs.tag }}
TITLE: ${{ steps.meta.outputs.title }}
NOTES: ${{ runner.temp }}/notes.md
run: |
set -euo pipefail
if gh release view "$TAG" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then
echo "Release $TAG 已存在,跳过创建(幂等,便于手工重跑)。"
exit 0
fi
gh release create "$TAG" --repo "$GITHUB_REPOSITORY" --title "$TITLE" --notes-file "$NOTES"
# ------------------------------------------------------------------
# 产物化:tag push 时随 Release 附带三平台单文件可执行(免 Node 环境即可运行)。
# @yao-pkg/pkg 打包,与本地 build:win 同一条链路(tsc → esbuild bundle → pkg)。
# 只在 tag push 事件执行:workflow_dispatch 补建历史版本时跳过,避免把当前
# main 的代码错附到旧 Release 上。
# ------------------------------------------------------------------
build-binaries:
needs: github-release
if: github.event_name == 'push'
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
targets: node22-linux-x64
- os: macos-latest
targets: node22-macos-arm64 node22-macos-x64
- os: windows-latest
targets: node22-win-x64
runs-on: ${{ matrix.os }}
env:
GH_TOKEN: ${{ github.token }}
steps:
- uses: actions/checkout@v7
with:
ref: ${{ needs.github-release.outputs.tag }}
- uses: actions/setup-node@v7
with:
node-version: 22
cache: npm
- run: npm ci || npm install
- name: 打包单文件可执行并上传到 Release
shell: bash
env:
TAG: ${{ needs.github-release.outputs.tag }}
TARGETS: ${{ matrix.targets }}
run: |
set -euo pipefail
npm run build:exe
VER="${TAG#v}"
FILES=""
for target in $TARGETS; do
plat="${target#node22-}" # linux-x64 / macos-arm64 / win-x64
ext=""; case "$plat" in win-*) ext=".exe" ;; esac
out="$RUNNER_TEMP/commandcode-proxy-$VER-$plat$ext"
npx pkg dist/bundle.cjs --target "$target" --output "$out" --compress GZip
FILES="$FILES $out"
done
gh release upload "$TAG" $FILES --repo "$GITHUB_REPOSITORY" --clobber
echo "已上传:$FILES"
# ------------------------------------------------------------------
# 汇总全部平台产物生成 SHA256SUMS.txt(供下载方校验完整性)
# ------------------------------------------------------------------
checksums:
needs: [github-release, build-binaries]
if: github.event_name == 'push'
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ github.token }}
steps:
- name: 生成并上传 SHA256SUMS
env:
TAG: ${{ needs.github-release.outputs.tag }}
run: |
set -euo pipefail
mkdir -p "$RUNNER_TEMP/assets" && cd "$RUNNER_TEMP/assets"
gh release download "$TAG" --repo "$GITHUB_REPOSITORY" --clobber
sha256sum $(ls | grep -v '^SHA256SUMS') > SHA256SUMS.txt
gh release upload "$TAG" SHA256SUMS.txt --repo "$GITHUB_REPOSITORY" --clobber
cat SHA256SUMS.txt