11# Tauri 桌面端:多平台构建并发布到 GitHub Release
2- # 触发:推送到 release 分支,或推送 tag desktop-v*
2+ # 触发:推送到 release 分支、推送 tag desktop-v*、或手动触发
33name : Build and Release Desktop
44
55on :
@@ -32,19 +32,65 @@ jobs:
3232 - name : Checkout
3333 uses : actions/checkout@v4
3434
35- - name : Install dependencies (Ubuntu only)
36- if : matrix.platform == 'ubuntu-22.04'
37- run : |
38- sudo apt-get update
39- sudo apt-get install -y libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf
40-
4135 - name : Setup Node.js
4236 uses : actions/setup-node@v4
4337 with :
4438 node-version : ' lts/*'
4539 cache : ' npm'
4640 cache-dependency-path : desktop/package-lock.json
4741
42+ # 统一解析版本与发布 tag:tag 触发用 tag 版本,否则用 tauri 配置中的版本
43+ - name : Resolve version and release tag
44+ id : version
45+ run : |
46+ const ref = process.env.GITHUB_REF || '';
47+ const refName = process.env.GITHUB_REF_NAME || '';
48+ const fs = require('fs');
49+ const path = require('path');
50+ let version, releaseTag;
51+ if (ref.startsWith('refs/tags/') && refName.startsWith('desktop-v')) {
52+ version = refName.replace(/^desktop-v/, '');
53+ releaseTag = refName;
54+ } else {
55+ const confPath = path.join('desktop', 'src-tauri', 'tauri.conf.json');
56+ const conf = JSON.parse(fs.readFileSync(confPath, 'utf8'));
57+ version = conf.version;
58+ releaseTag = 'desktop-v' + version;
59+ }
60+ const out = process.env.GITHUB_OUTPUT;
61+ fs.appendFileSync(out, `version=${version}\nrelease_tag=${releaseTag}\n`);
62+ env :
63+ GITHUB_REF : ${{ github.ref }}
64+ GITHUB_REF_NAME : ${{ github.ref_name }}
65+
66+ # 从 tag 触发时,将版本写回项目配置,保证构建产物版本与 release 一致
67+ - name : Sync version to project (when triggered by tag)
68+ if : startsWith(github.ref, 'refs/tags/')
69+ run : |
70+ const fs = require('fs');
71+ const path = require('path');
72+ const v = process.env.VERSION;
73+ const confPath = path.join('desktop', 'src-tauri', 'tauri.conf.json');
74+ const conf = JSON.parse(fs.readFileSync(confPath, 'utf8'));
75+ conf.version = v;
76+ fs.writeFileSync(confPath, JSON.stringify(conf, null, 2));
77+ const cargoPath = path.join('desktop', 'src-tauri', 'Cargo.toml');
78+ let cargo = fs.readFileSync(cargoPath, 'utf8');
79+ cargo = cargo.replace(/^version = ".*"/m, `version = "${v}"`);
80+ fs.writeFileSync(cargoPath, cargo);
81+ const pkgPath = path.join('desktop', 'package.json');
82+ const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
83+ pkg.version = v;
84+ fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
85+ env :
86+ VERSION : ${{ steps.version.outputs.version }}
87+
88+ - name : Install dependencies (Ubuntu only)
89+ if : matrix.platform == 'ubuntu-22.04'
90+ run : |
91+ sudo apt-get update
92+ sudo apt-get install -y libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf
93+
4894 - name : Install Rust
4995 uses : dtolnay/rust-toolchain@stable
5096 with :
@@ -65,9 +111,10 @@ jobs:
65111 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
66112 with :
67113 projectPath : desktop
68- tagName : desktop-v__VERSION__
69- releaseName : ' COMSOL Agent Desktop v__VERSION__ '
70- releaseBody : ' See the assets to download this version and install.'
114+ tagName : ${{ steps.version.outputs.release_tag }}
115+ releaseName : COMSOL Agent Desktop v${{ steps.version.outputs.version }}
116+ releaseBody : ' See the assets below to download and install.'
71117 releaseDraft : true
72118 prerelease : false
119+ appVersion : ${{ steps.version.outputs.version }}
73120 args : ${{ matrix.args }}
0 commit comments