5eeff7abaa
scripts/update-version.mjs now maintains a `deployCount` integer and
rewrites `version` as `${baseVersion}.${deployCount}` every time the
build hash actually changes. When build is unchanged (re-run without
new commit) it still no-ops, matching prior behaviour, so re-running
the build twice in CI doesn't inflate the counter.
version.json shape:
{
"baseVersion": "0.1.0-dev", <- stable, manually owned
"version": "0.1.0-dev.42", <- baseVersion + "." + deployCount
"build": "20260518.f942f101",
"deployCount": 42
}
Migration: on the very first run after this change, if `baseVersion`
is missing, the script derives it from the existing `version` field
by stripping any trailing `.<digits>`. If `deployCount` is missing it
seeds from that same trailing counter, so a repo that was already
hand-numbered (e.g. "0.1.0-dev.12") doesn't reset progress to 0.
Verified manually:
- Re-run with no new commit -> "build unchanged: ...", file untouched.
- New build -> bumps deployCount by exactly 1, rewrites version.
- Manually editing baseVersion to "0.2.0" -> next bump yields
"0.2.0.<count+1>", manual base preserved.
api-server reads version.json statically (import with type: "json"),
so no API change is needed — the new fields flow through to
/api/system/version automatically. admin.tsx just prints
data.current.version, no regex parsing, so the new suffixed string
shows up in the System Updates card with no UI edit.
version.json reset to baseVersion=0.1.0-dev, version=0.1.0-dev,
deployCount=0 so the next legitimate Mac docker build bumps cleanly
to dev.1 on first redeploy.
71 lines
2.6 KiB
JavaScript
71 lines
2.6 KiB
JavaScript
#!/usr/bin/env node
|
|
import { execSync } from "node:child_process";
|
|
import { readFileSync, writeFileSync } from "node:fs";
|
|
import { fileURLToPath } from "node:url";
|
|
import { dirname, resolve } from "node:path";
|
|
|
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
const versionPath = resolve(__dirname, "..", "version.json");
|
|
|
|
function git(args) {
|
|
return execSync(`git ${args}`, { encoding: "utf8" }).trim();
|
|
}
|
|
|
|
let commit = "unknown";
|
|
let date = new Date().toISOString().slice(0, 10).replace(/-/g, "");
|
|
try {
|
|
commit = git("log -1 --format=%h");
|
|
date = git("log -1 --format=%cd --date=format:%Y%m%d");
|
|
} catch (err) {
|
|
console.warn(`[update-version] git unavailable, using fallback: ${err.message}`);
|
|
}
|
|
|
|
const build = `${date}.${commit}`;
|
|
const current = JSON.parse(readFileSync(versionPath, "utf8"));
|
|
|
|
// #597: derive the stable base from the existing `version` field on
|
|
// first run so older repos migrate cleanly. e.g. "0.1.0-dev.5" -> base
|
|
// "0.1.0-dev", count 5. A bare "0.1.0-dev" (no trailing .N) just stays
|
|
// the base and starts counting from the current deployCount (or 0).
|
|
const TRAILING_COUNTER = /\.(\d+)$/;
|
|
function deriveBase(versionStr) {
|
|
if (typeof versionStr !== "string" || versionStr.length === 0) {
|
|
return "0.1.0-dev";
|
|
}
|
|
const m = versionStr.match(TRAILING_COUNTER);
|
|
return m ? versionStr.slice(0, -m[0].length) : versionStr;
|
|
}
|
|
|
|
const baseVersion =
|
|
typeof current.baseVersion === "string" && current.baseVersion.length > 0
|
|
? current.baseVersion
|
|
: deriveBase(current.version);
|
|
|
|
let deployCount = Number.isInteger(current.deployCount)
|
|
? current.deployCount
|
|
: (() => {
|
|
// Seed from the trailing counter on the existing version string
|
|
// so first migration doesn't reset progress to 0 if the user had
|
|
// already been numbering manually (e.g. "0.1.0-dev.12").
|
|
const m =
|
|
typeof current.version === "string"
|
|
? current.version.match(TRAILING_COUNTER)
|
|
: null;
|
|
return m ? parseInt(m[1], 10) : 0;
|
|
})();
|
|
|
|
if (current.build === build) {
|
|
// No new commit since last run -> nothing to do. Don't bump the
|
|
// counter and don't rewrite the file. This matches pre-#597 behaviour
|
|
// so re-running the build twice in CI doesn't inflate the counter.
|
|
console.log(`[update-version] build unchanged: ${build}`);
|
|
} else {
|
|
deployCount += 1;
|
|
const version = `${baseVersion}.${deployCount}`;
|
|
const next = { baseVersion, version, build, deployCount };
|
|
writeFileSync(versionPath, JSON.stringify(next, null, 2) + "\n");
|
|
console.log(
|
|
`[update-version] ${current.build} -> ${build} | ${current.version ?? "<none>"} -> ${version}`,
|
|
);
|
|
}
|