Skip to content

Commit 5ad7628

Browse files
committed
chore: stabilize desktop workflow version metadata
1 parent a07f278 commit 5ad7628

3 files changed

Lines changed: 44 additions & 4 deletions

File tree

.github/workflows/desktop-beta.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ jobs:
6262
id: meta
6363
shell: pwsh
6464
run: |
65-
$baseVersion = node -e "process.stdout.write(require('./apps/desktop/package.json').version)"
65+
$baseVersion = (node apps/desktop/scripts/desktop-package-version.mjs get).Trim()
6666
$buildDate = Get-Date -Format 'yyyyMMdd'
6767
$shortSha = "${env:GITHUB_SHA}".Substring(0, 7)
6868
$desktopVersion = "$baseVersion-$env:CHANNEL.$buildDate"
69-
node -e "const fs=require('node:fs'); const path='apps/desktop/package.json'; const pkg=JSON.parse(fs.readFileSync(path,'utf8')); pkg.version=process.argv[1]; fs.writeFileSync(path, JSON.stringify(pkg, null, 2)+'`n');" "$desktopVersion"
69+
node apps/desktop/scripts/desktop-package-version.mjs set "$desktopVersion" | Out-Null
7070
"desktop_version=$desktopVersion" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8
7171
"build_date=$buildDate" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8
7272
"short_sha=$shortSha" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8

.github/workflows/desktop-nightly.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ jobs:
6363
id: meta
6464
shell: pwsh
6565
run: |
66-
$baseVersion = node -e "process.stdout.write(require('./apps/desktop/package.json').version)"
66+
$baseVersion = (node apps/desktop/scripts/desktop-package-version.mjs get).Trim()
6767
$buildDate = Get-Date -Format 'yyyyMMdd'
6868
$shortSha = "${env:GITHUB_SHA}".Substring(0, 7)
6969
$desktopVersion = "$baseVersion-$env:CHANNEL.$buildDate"
70-
node -e "const fs=require('node:fs'); const path='apps/desktop/package.json'; const pkg=JSON.parse(fs.readFileSync(path,'utf8')); pkg.version=process.argv[1]; fs.writeFileSync(path, JSON.stringify(pkg, null, 2)+'`n');" "$desktopVersion"
70+
node apps/desktop/scripts/desktop-package-version.mjs set "$desktopVersion" | Out-Null
7171
"desktop_version=$desktopVersion" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8
7272
"build_date=$buildDate" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8
7373
"short_sha=$shortSha" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { readFile, writeFile } from "node:fs/promises";
2+
import { dirname, resolve } from "node:path";
3+
import { fileURLToPath } from "node:url";
4+
5+
const scriptDir = dirname(fileURLToPath(import.meta.url));
6+
const packageJsonPath = resolve(scriptDir, "..", "package.json");
7+
8+
async function readPackageJson() {
9+
return JSON.parse(await readFile(packageJsonPath, "utf8"));
10+
}
11+
12+
async function main() {
13+
const command = process.argv[2];
14+
15+
if (command === "get") {
16+
const pkg = await readPackageJson();
17+
process.stdout.write(`${pkg.version}\n`);
18+
return;
19+
}
20+
21+
if (command === "set") {
22+
const version = process.argv[3]?.trim();
23+
if (!version) {
24+
throw new Error("[desktop-package-version] missing version argument");
25+
}
26+
27+
const pkg = await readPackageJson();
28+
pkg.version = version;
29+
await writeFile(packageJsonPath, `${JSON.stringify(pkg, null, 2)}\n`, "utf8");
30+
process.stdout.write(`${version}\n`);
31+
return;
32+
}
33+
34+
throw new Error("[desktop-package-version] expected 'get' or 'set'");
35+
}
36+
37+
main().catch((error) => {
38+
console.error(error);
39+
process.exitCode = 1;
40+
});

0 commit comments

Comments
 (0)