Image Pipeline Playground
chore(desktop): sync installer version from git tag
Mohammad Rajaei5b289a5692bc
diff --git a/.github/workflows/desktop.yml b/.github/workflows/desktop.ymlindex 9e70e1c..f8aa2c3 100644--- a/.github/workflows/desktop.yml+++ b/.github/workflows/desktop.yml@@ -31,6 +31,9 @@ jobs:steps:- name: Checkoutuses: actions/checkout@v4+ with:+ # Needed so untagged builds can resolve the nearest `v*` tag for versioning.+ fetch-depth: 0- name: Setup Node.jsuses: actions/setup-node@v4diff --git a/desktop/README.md b/desktop/README.mdindex c0b5a4c..4028e95 100644--- a/desktop/README.md+++ b/desktop/README.md@@ -18,6 +18,8 @@ Installers land in `desktop/release/`. End users do **not** need Python or Node.GitHub Actions builds Windows / Linux / macOS installers on `main` and publishes them when you push a `v*` tag (see `.github/workflows/desktop.yml`).+Installer version comes from the git tag (`v0.2.0` → `0.2.0`) via `scripts/build-desktop.mjs`. Override with `IMAGE_PIPES_VERSION` if needed.+## Developer day-to-dayTerminal A — not required if you use the desktop shell:diff --git a/scripts/build-desktop.mjs b/scripts/build-desktop.mjsindex 6947a69..242a9ac 100644--- a/scripts/build-desktop.mjs+++ b/scripts/build-desktop.mjs@@ -4,9 +4,10 @@* 1) frontend production build* 2) PyInstaller backend sidecar* 3) stage into desktop/resources/server- * 4) electron-builder installer+ * 4) sync desktop version from git tag (when available)+ * 5) electron-builder installer*/-import { spawn } from 'node:child_process'+import { execSync, spawn } from 'node:child_process'import fs from 'node:fs'import path from 'node:path'import { fileURLToPath } from 'node:url'@@ -40,6 +41,70 @@ function copyDir(src, dest) {fs.cpSync(src, dest, { recursive: true })}+/** Strip leading `v` from a git tag (v0.2.0 → 0.2.0). */+function stripVersionPrefix(tag) {+ return tag.trim().replace(/^v/i, '')+}++/**+ * Resolve the desktop app version from (in order):+ * 1) IMAGE_PIPES_VERSION env+ * 2) GITHUB_REF tag (CI tag builds)+ * 3) nearest git tag (`git describe --tags --abbrev=0`)+ * Returns null when nothing usable is found.+ */+function resolveDesktopVersion() {+ const override = process.env.IMAGE_PIPES_VERSION?.trim()+ if (override) return stripVersionPrefix(override)++ const ref = process.env.GITHUB_REF ?? ''+ if (ref.startsWith('refs/tags/')) {+ return stripVersionPrefix(ref.slice('refs/tags/'.length))+ }++ try {+ const tag = execSync('git describe --tags --abbrev=0', {+ cwd: root,+ encoding: 'utf8',+ stdio: ['ignore', 'pipe', 'ignore'],+ }).trim()+ if (tag) return stripVersionPrefix(tag)+ } catch {+ // Untagged clone / shallow checkout without tags.+ }+ return null+}++/** Write resolved version into desktop/package.json for electron-builder. */+function syncDesktopPackageVersion(desktopDir) {+ const version = resolveDesktopVersion()+ const pkgPath = path.join(desktopDir, 'package.json')+ const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'))++ if (!version) {+ console.log(+ `==> No git tag version found; keeping desktop/package.json at ${pkg.version}`,+ )+ return pkg.version+ }++ if (!/^\d+\.\d+\.\d+/.test(version)) {+ throw new Error(+ `Invalid desktop version "${version}" (expected semver like 0.2.0)`,+ )+ }++ if (pkg.version === version) {+ console.log(`==> Desktop version already ${version}`)+ return version+ }++ console.log(`==> Setting desktop version to ${version} (from git tag)`)+ pkg.version = version+ fs.writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`)+ return version+}+async function main() {const skipInstaller = process.argv.includes('--sidecar-only')const frontendDir = path.join(root, 'frontend')@@ -96,7 +161,9 @@ async function main() {console.log('==> Installing desktop dependencies')await run('npm', npmInstall, desktopDir)- console.log('==> Building Electron installer')+ const version = syncDesktopPackageVersion(desktopDir)++ console.log(`==> Building Electron installer (v${version})`)await run('npm', ['run', 'dist'], desktopDir)console.log('\nDesktop build complete. Installers are under desktop/release/')