1+ name : Release Build
2+
3+ on :
4+ push :
5+ # 仅匹配 1.2.3 或 1.2.3-beta1 这样的 tag,例如 1.0.0、2.3.4-beta2
6+ tags :
7+ - " [0-9]+.[0-9]+.[0-9]+"
8+ - " [0-9]+.[0-9]+.[0-9]+-beta[0-9]+"
9+
10+ permissions : write-all
11+
12+ concurrency :
13+ group : " ${{ github.workflow }} - ${{ github.head_ref || github.ref }}"
14+ cancel-in-progress : ${{ github.ref != 'refs/heads/master' }}
15+
16+ jobs :
17+ check-version :
18+ name : 校验版本号
19+ runs-on : ubuntu-latest
20+ steps :
21+ - name : 拉取代码
22+ uses : actions/checkout@v3
23+
24+ - name : 校验 package.json version 与 tag 一致
25+ run : |
26+ TAG_NAME="${GITHUB_REF##refs/tags/}"
27+ PKG_VERSION=$(node -p "require('./package.json').version")
28+ if [[ "$PKG_VERSION" != "$TAG_NAME" ]]; then
29+ echo "❌ package.json 里的 version ($PKG_VERSION) 和 tag ($TAG_NAME) 不一致,终止执行。"
30+ exit 1
31+ else
32+ echo "✅ package.json 里的 version 和 tag ($TAG_NAME) 一致,继续执行。"
33+ fi
34+
35+
36+ build-win :
37+ name : Windows 打包
38+ runs-on : windows-latest
39+ needs : check-version
40+ outputs :
41+ artifacts-path : ${{ steps.set-artifacts-path.outputs.result }}
42+ steps :
43+ - name : 拉取代码
44+ uses : actions/checkout@v3
45+
46+ - name : 设置 Node.js
47+ uses : actions/setup-node@v4
48+ with :
49+ node-version : 18
50+
51+ - name : 安装依赖
52+ run : npm install
53+
54+ - name : 打包 Windows 32位
55+ run : npm run build-w
56+ env :
57+ GH_TOKEN : ${{ secrets.GH_TOKEN }}
58+
59+ - name : 打包 Windows 64位
60+ run : npm run build-w-64
61+ env :
62+ GH_TOKEN : ${{ secrets.GH_TOKEN }}
63+
64+ - name : 设置产物路径
65+ id : set-artifacts-path
66+ run : echo "result=out" >> $GITHUB_OUTPUT
67+
68+ - name : 上传构建产物
69+ uses : actions/upload-artifact@v4
70+ with :
71+ name : win-builds
72+ path : out/*.exe
73+
74+ build-mac :
75+ name : macOS 打包
76+ runs-on : macos-latest
77+ needs : check-version
78+ steps :
79+ - name : 拉取代码
80+ uses : actions/checkout@v3
81+
82+ - name : 设置 Node.js
83+ uses : actions/setup-node@v4
84+ with :
85+ node-version : 18
86+
87+ - name : 安装依赖
88+ run : npm install
89+
90+ - name : 打包 macOS x64
91+ run : npm run build-m
92+ env :
93+ GH_TOKEN : ${{ secrets.GH_TOKEN }}
94+
95+ - name : 打包 macOS arm64
96+ run : npm run build-m-arm64
97+ env :
98+ GH_TOKEN : ${{ secrets.GH_TOKEN }}
99+
100+ - name : 打包 macOS Universal
101+ run : npm run build-m-universal
102+ env :
103+ GH_TOKEN : ${{ secrets.GH_TOKEN }}
104+
105+ - name : 上传构建产物
106+ uses : actions/upload-artifact@v4
107+ with :
108+ name : mac-builds
109+ path : out/*.dmg
110+
111+ build-linux :
112+ name : Linux 打包
113+ runs-on : ubuntu-latest
114+ needs : check-version
115+ steps :
116+ - name : 拉取代码
117+ uses : actions/checkout@v3
118+
119+ - name : 设置 Node.js
120+ uses : actions/setup-node@v4
121+ with :
122+ node-version : 18
123+
124+ - name : 安装依赖
125+ run : npm install
126+
127+ - name : 打包 Linux x64
128+ run : npm run build-l
129+ env :
130+ GH_TOKEN : ${{ secrets.GH_TOKEN }}
131+
132+ - name : 打包 Linux arm64
133+ run : npm run build-l-arm64
134+ env :
135+ GH_TOKEN : ${{ secrets.GH_TOKEN }}
136+
137+ - name : 上传构建产物
138+ uses : actions/upload-artifact@v4
139+ with :
140+ name : linux-builds
141+ path : |
142+ out/*.tar.xz
143+ out/*.deb
144+
145+
146+ release :
147+ name : 自动发布 Release
148+ needs : [build-win, build-mac, build-linux]
149+ runs-on : ubuntu-latest
150+ steps :
151+ - name : 拉取代码
152+ uses : actions/checkout@v3
153+
154+ # 下载各平台构建产物
155+ - name : 下载 Windows 产物
156+ uses : actions/download-artifact@v4
157+ with :
158+ name : win-builds
159+ path : artifacts/win
160+
161+ - name : 下载 macOS 产物
162+ uses : actions/download-artifact@v4
163+ with :
164+ name : mac-builds
165+ path : artifacts/mac
166+
167+ - name : 下载 Linux 产物
168+ uses : actions/download-artifact@v4
169+ with :
170+ name : linux-builds
171+ path : artifacts/linux
172+
173+ # 自动生成 Release Notes(使用 tag 相关 commit 信息)
174+ - name : 生成 Release Notes
175+ id : changelog
176+ run : |
177+ TAG_NAME="${GITHUB_REF##refs/tags/}"
178+ PREV_TAG=$(git tag --sort=-creatordate | grep -B1 "^${TAG_NAME}$" | head -n1)
179+ if [ -z "$PREV_TAG" ]; then
180+ git log -1 --pretty=format:"%h %s" "$TAG_NAME" > release_notes.txt
181+ else
182+ git log "$PREV_TAG..$TAG_NAME" --pretty=format:"- %h %s" > release_notes.txt
183+ fi
184+ echo "release_notes<<EOF" >> $GITHUB_OUTPUT
185+ cat release_notes.txt >> $GITHUB_OUTPUT
186+ echo "EOF" >> $GITHUB_OUTPUT
187+
188+ - name : 发布 Release
189+ uses : softprops/action-gh-release@v2
190+ with :
191+ tag_name : ${{ github.ref_name }}
192+ name : ${{ github.ref_name }}
193+ body : ${{ steps.changelog.outputs.release_notes }}
194+ files : |
195+ artifacts/win/**
196+ artifacts/mac/**
197+ artifacts/linux/**
198+ prerelease : ${{ contains(github.ref_name, 'beta') }}
199+ env :
200+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments