Skip to content

Commit f30eeef

Browse files
committed
feat: 版本号单源管理(VERSION),版本变更触发打包并自动发布 Release
- 根目录 VERSION 为唯一版本源,sync-version.mjs 同步到 tauri.conf/package.json/Cargo.toml - workflow 触发条件改为仅 VERSION 变更的 push(或手动),普通推送不再打包 - 打包后自动发布/更新 v<版本> GitHub Release 并附全平台安装包 - 本版本 1.0.0 -> 1.1.0
1 parent a17f02e commit f30eeef

8 files changed

Lines changed: 97 additions & 13 deletions

File tree

‎.github/workflows/desktop-build.yml‎

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
name: Desktop Build
22

3+
# 仅当版本号变更(VERSION 文件修改的 push)或手动触发时打包;
4+
# 打包完成后自动发布/更新同名 GitHub Release 并附上安装包。
35
on:
46
workflow_dispatch:
57
push:
68
branches: [master]
7-
paths:
8-
- "desktop/**"
9-
- "templates/**"
10-
- "static/**"
11-
- ".github/workflows/desktop-build.yml"
9+
paths: ["VERSION"]
10+
11+
permissions:
12+
contents: write
1213

1314
jobs:
1415
build:
@@ -27,6 +28,11 @@ jobs:
2728
steps:
2829
- uses: actions/checkout@v4
2930

31+
- name: 读取版本号
32+
id: version
33+
shell: bash
34+
run: echo "ver=$(tr -d ' \r\n' < ../VERSION)" >> "$GITHUB_OUTPUT"
35+
3036
- name: 安装 Node
3137
uses: actions/setup-node@v4
3238
with:
@@ -42,6 +48,9 @@ jobs:
4248
with:
4349
workspaces: desktop/src-tauri
4450

51+
- name: 同步版本号(VERSION → tauri.conf/package.json/Cargo.toml)
52+
run: node scripts/sync-version.mjs
53+
4554
- name: 同步 UI(从 templates/ + static/ 生成)
4655
run: node scripts/sync-ui.mjs
4756

@@ -57,14 +66,25 @@ jobs:
5766
npm run tauri build
5867
fi
5968
60-
- name: 上传安装包
69+
- name: 上传 Artifacts(90 天)
6170
uses: actions/upload-artifact@v4
6271
with:
63-
name: ScriptDeck-${{ matrix.label }}
72+
name: ScriptDeck-${{ matrix.label }}-${{ steps.version.outputs.ver }}
6473
path: |
6574
desktop/src-tauri/target/release/bundle/**/*.exe
6675
desktop/src-tauri/target/release/bundle/**/*.msi
6776
desktop/src-tauri/target/release/bundle/**/*.dmg
6877
desktop/src-tauri/target/universal-apple-darwin/release/bundle/**/*.dmg
6978
desktop/src-tauri/target/universal-apple-darwin/release/bundle/**/*.app.tar.gz
7079
if-no-files-found: error
80+
81+
- name: 发布/更新 GitHub Release
82+
shell: bash
83+
env:
84+
GH_TOKEN: ${{ github.token }}
85+
run: |
86+
TAG="v${{ steps.version.outputs.ver }}"
87+
FILES=$(find src-tauri/target -path "*bundle*" \( -name "*.exe" -o -name "*.msi" -o -name "*.dmg" -o -name "*.app.tar.gz" \) | sort -u | tr '\n' ' ')
88+
echo " attaching: $FILES"
89+
gh release create "$TAG" --title "ScriptDeck $TAG" --generate-notes $FILES \
90+
|| gh release upload "$TAG" $FILES --clobber

‎README.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
浏览器界面原样复用,后端用 Rust 重写,打包为独立安装包(Windows NSIS/MSI、macOS .dmg),
1515
macOS 上额外支持 `.sh` 脚本(在 Terminal 中运行)。详见 [desktop/README.md](desktop/README.md)。
1616

17+
发版:修改根目录 [VERSION](VERSION) 并推送,CI 自动打包并发布带安装包的 GitHub Release;
18+
仅版本号变更(或手动触发)才打包。
19+
1720
```bash
1821
cd desktop
1922
npm install && npm run dev # 开发调试

‎VERSION‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.1.0

‎desktop/README.md‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,23 @@ npm run dev # 开发调试窗口
3434
> `ui/` 由 `scripts/sync-ui.mjs` 生成(去 Jinja、fetch→invoke、追加 .sh 徽章),
3535
> 不要手改——修改根目录源文件后重新执行 `sync-ui` 即可。
3636
37+
## 版本与发版
38+
39+
版本号**单一来源**是仓库根目录的 `VERSION` 文件,`npm run sync-version` 将其同步到
40+
`tauri.conf.json` / `package.json` / `Cargo.toml`。
41+
42+
发版流程:修改 `VERSION`(如 `1.1.0`)→ 提交并推送到 master → CI 自动打包并发布
43+
同名 GitHub Release(附全平台安装包)。**只有 VERSION 变更(或 Actions 页手动触发)才会打包**,
44+
普通代码推送不触发。
45+
3746
## 打包
3847

3948
```bash
4049
npm run build # Windows 出 NSIS/MSI;macOS 出 .app/.dmg
4150
```
4251

43-
macOS 构建必须在 mac 上执行(Tauri 不支持交叉编译),或直接跑
44-
`.github/workflows/desktop-build.yml`(push 到 master 或手动触发,
45-
产物在 Actions Artifacts 中,覆盖 Windows x64 / macOS arm64 / macOS x64)。
52+
CI(`.github/workflows/desktop-build.yml`)覆盖 Windows x64 与 macOS universal(Intel + Apple Silicon
53+
双架构单包,无需 Intel runner);macOS 构建无法在 Windows 上本地执行。
4654

4755
## 目录结构
4856

‎desktop/package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
{
22
"name": "scriptdeck-desktop",
33
"private": true,
4-
"version": "1.0.0",
4+
"version": "1.1.0",
55
"description": "ScriptDeck 桌面版(Tauri 2 + Rust)",
66
"scripts": {
77
"sync-ui": "node scripts/sync-ui.mjs",
8+
"sync-version": "node scripts/sync-version.mjs",
89
"tauri": "tauri",
910
"dev": "tauri dev",
1011
"build": "tauri build"

‎desktop/scripts/sync-version.mjs‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
* sync-version.mjs — 将仓库根目录的 VERSION 同步到各配置文件(单一版本源)。
3+
* CI 打包前与本地发版前执行,保证安装包版本号一致。
4+
* 幂等:值一致时不改写文件。
5+
*/
6+
import { readFileSync, writeFileSync } from "node:fs";
7+
import { dirname, join } from "node:path";
8+
import { fileURLToPath } from "node:url";
9+
10+
const desktopDir = join(dirname(fileURLToPath(import.meta.url)), "..");
11+
const version = readFileSync(join(desktopDir, "..", "VERSION"), "utf-8").trim();
12+
13+
if (!/^\d+\.\d+\.\d+(-[\w.]+)?$/.test(version)) {
14+
console.error(`[sync-version] VERSION 内容非法:${version}`);
15+
process.exit(1);
16+
}
17+
18+
const targets = [
19+
{
20+
file: join(desktopDir, "src-tauri", "tauri.conf.json"),
21+
pattern: /("version"\s*:\s*")[^"]+(")/,
22+
replace: (v) => `$1${v}$2`,
23+
},
24+
{
25+
file: join(desktopDir, "package.json"),
26+
pattern: /("version"\s*:\s*")[^"]+(")/,
27+
replace: (v) => `$1${v}$2`,
28+
},
29+
{
30+
file: join(desktopDir, "src-tauri", "Cargo.toml"),
31+
pattern: /^(version\s*=\s*")[^"]+(")/m,
32+
replace: (v) => `$1${v}$2`,
33+
},
34+
];
35+
36+
for (const { file, pattern, replace } of targets) {
37+
const name = file.split(/[\\/]/).slice(-2).join("/");
38+
const text = readFileSync(file, "utf-8").replace(/\r\n/g, "\n");
39+
if (!pattern.test(text)) {
40+
console.error(`[sync-version] ${name} 未找到 version 字段`);
41+
process.exit(1);
42+
}
43+
const updated = text.replace(pattern, replace(version));
44+
if (updated !== text) {
45+
writeFileSync(file, updated, "utf-8");
46+
console.log(`[sync-version] ${name}: -> ${version}`);
47+
} else {
48+
console.log(`[sync-version] ${name}: 已是 ${version}`);
49+
}
50+
}
51+
console.log(`[sync-version] 完成,当前版本 ${version}`);

‎desktop/src-tauri/Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "scriptdeck"
3-
version = "1.0.0"
3+
version = "1.1.0"
44
description = "ScriptDeck 脚本中台桌面版"
55
edition = "2021"
66

‎desktop/src-tauri/tauri.conf.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"$schema": "https://schema.tauri.app/config/2",
33
"productName": "ScriptDeck",
4-
"version": "1.0.0",
4+
"version": "1.1.0",
55
"identifier": "com.scriptdeck.app",
66
"build": {
77
"frontendDist": "../ui"

0 commit comments

Comments
 (0)