Skip to content

Commit 244073d

Browse files
committed
feat(release): auto-sync version from git tag before build
Add a "Sync version from tag" step to each platform build job that updates package.json, src-tauri/tauri.conf.json, and src-tauri/Cargo.toml with the version extracted from the git tag. This ensures build artifacts carry the correct version number without requiring manual version bumps in source files.
1 parent 399cf3a commit 244073d

1 file changed

Lines changed: 77 additions & 0 deletions

File tree

.github/workflows/release.yml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,25 @@ jobs:
107107
- uses: Swatinem/rust-cache@v2
108108
with: { workspaces: src-tauri, shared-key: 'release-linux' }
109109

110+
- name: Sync version from tag
111+
env:
112+
VERSION: ${{ needs.validate.outputs.version }}
113+
run: |
114+
node -e '
115+
const fs = require("fs");
116+
const v = process.env.VERSION;
117+
const pkg = JSON.parse(fs.readFileSync("package.json", "utf8"));
118+
pkg.version = v;
119+
fs.writeFileSync("package.json", JSON.stringify(pkg, null, 2) + "\n");
120+
const conf = JSON.parse(fs.readFileSync("src-tauri/tauri.conf.json", "utf8"));
121+
conf.version = v;
122+
fs.writeFileSync("src-tauri/tauri.conf.json", JSON.stringify(conf, null, 2) + "\n");
123+
let toml = fs.readFileSync("src-tauri/Cargo.toml", "utf8");
124+
toml = toml.replace(/^version = ".*"/m, `version = "${v}"`);
125+
fs.writeFileSync("src-tauri/Cargo.toml", toml);
126+
console.log("Synced version to " + v);
127+
'
128+
110129
- run: pnpm install --frozen-lockfile
111130
- run: pnpm tauri build --target x86_64-unknown-linux-gnu
112131

@@ -145,6 +164,26 @@ jobs:
145164
- uses: Swatinem/rust-cache@v2
146165
with: { workspaces: src-tauri, shared-key: 'release-windows' }
147166

167+
- name: Sync version from tag
168+
shell: bash
169+
env:
170+
VERSION: ${{ needs.validate.outputs.version }}
171+
run: |
172+
node -e '
173+
const fs = require("fs");
174+
const v = process.env.VERSION;
175+
const pkg = JSON.parse(fs.readFileSync("package.json", "utf8"));
176+
pkg.version = v;
177+
fs.writeFileSync("package.json", JSON.stringify(pkg, null, 2) + "\n");
178+
const conf = JSON.parse(fs.readFileSync("src-tauri/tauri.conf.json", "utf8"));
179+
conf.version = v;
180+
fs.writeFileSync("src-tauri/tauri.conf.json", JSON.stringify(conf, null, 2) + "\n");
181+
let toml = fs.readFileSync("src-tauri/Cargo.toml", "utf8");
182+
toml = toml.replace(/^version = ".*"/m, `version = "${v}"`);
183+
fs.writeFileSync("src-tauri/Cargo.toml", toml);
184+
console.log("Synced version to " + v);
185+
'
186+
148187
- run: pnpm install --frozen-lockfile
149188
- run: pnpm tauri build --target x86_64-pc-windows-msvc
150189

@@ -184,6 +223,25 @@ jobs:
184223
- uses: Swatinem/rust-cache@v2
185224
with: { workspaces: src-tauri, shared-key: 'release-macos-arm64' }
186225

226+
- name: Sync version from tag
227+
env:
228+
VERSION: ${{ needs.validate.outputs.version }}
229+
run: |
230+
node -e '
231+
const fs = require("fs");
232+
const v = process.env.VERSION;
233+
const pkg = JSON.parse(fs.readFileSync("package.json", "utf8"));
234+
pkg.version = v;
235+
fs.writeFileSync("package.json", JSON.stringify(pkg, null, 2) + "\n");
236+
const conf = JSON.parse(fs.readFileSync("src-tauri/tauri.conf.json", "utf8"));
237+
conf.version = v;
238+
fs.writeFileSync("src-tauri/tauri.conf.json", JSON.stringify(conf, null, 2) + "\n");
239+
let toml = fs.readFileSync("src-tauri/Cargo.toml", "utf8");
240+
toml = toml.replace(/^version = ".*"/m, `version = "${v}"`);
241+
fs.writeFileSync("src-tauri/Cargo.toml", toml);
242+
console.log("Synced version to " + v);
243+
'
244+
187245
- run: pnpm install --frozen-lockfile
188246
- run: pnpm tauri build --target aarch64-apple-darwin
189247

@@ -222,6 +280,25 @@ jobs:
222280
- uses: Swatinem/rust-cache@v2
223281
with: { workspaces: src-tauri, shared-key: 'release-macos-intel' }
224282

283+
- name: Sync version from tag
284+
env:
285+
VERSION: ${{ needs.validate.outputs.version }}
286+
run: |
287+
node -e '
288+
const fs = require("fs");
289+
const v = process.env.VERSION;
290+
const pkg = JSON.parse(fs.readFileSync("package.json", "utf8"));
291+
pkg.version = v;
292+
fs.writeFileSync("package.json", JSON.stringify(pkg, null, 2) + "\n");
293+
const conf = JSON.parse(fs.readFileSync("src-tauri/tauri.conf.json", "utf8"));
294+
conf.version = v;
295+
fs.writeFileSync("src-tauri/tauri.conf.json", JSON.stringify(conf, null, 2) + "\n");
296+
let toml = fs.readFileSync("src-tauri/Cargo.toml", "utf8");
297+
toml = toml.replace(/^version = ".*"/m, `version = "${v}"`);
298+
fs.writeFileSync("src-tauri/Cargo.toml", toml);
299+
console.log("Synced version to " + v);
300+
'
301+
225302
- run: pnpm install --frozen-lockfile
226303
- run: pnpm tauri build --target x86_64-apple-darwin
227304

0 commit comments

Comments
 (0)