Skip to content

Commit f132f96

Browse files
authored
Merge pull request #53 from Xavier9896/master
添加 release 流水线,实现自动打包发版
2 parents cc082be + 3ff9034 commit f132f96

File tree

3 files changed

+207
-5
lines changed

3 files changed

+207
-5
lines changed

.github/workflows/release.yml

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
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 }}

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "electron-hiprint",
3-
"version": "1.0.12-beta10",
3+
"version": "1.0.13",
44
"description": "vue-plugin-hiprint client",
55
"main": "main.js",
66
"author": "CcSimple<[email protected]>",
@@ -77,7 +77,8 @@
7777
"icon": "./build/icons/256x256.png",
7878
"artifactName": "${productName}-${version}.${ext}",
7979
"target": [
80-
"tar.xz"
80+
"tar.xz",
81+
"deb"
8182
]
8283
},
8384
"protocols": [
@@ -87,7 +88,8 @@
8788
"hiprint"
8889
]
8990
}
90-
]
91+
],
92+
"publish": null
9193
},
9294
"dependencies": {
9395
"address": "^1.2.0",

tools/rename.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ class ReName {
3131
let version = pkg.version;
3232
let productName = pkg.build.productName;
3333
let fileName = `${productName}-${version}`;
34-
let extList = [".exe", ".dmg", ".tar.xz"];
34+
let extList = [".exe", ".dmg", ".tar.xz", ".deb"];
3535
extList.forEach((e) => {
3636
let file = path.join(that.dirs, `${fileName}${e}`);
3737
let nFile = path.join(
3838
that.dirs,
39-
`${productName}_${args["tag"]}-${version}${e}`
39+
`${productName}_${args["tag"]}-${version}${e}`,
4040
);
4141
if (fs.existsSync(file)) {
4242
console.log("exist ", file);

0 commit comments

Comments
 (0)