Файли
openidea/scripts/nightly-prepare.ts
T
l0ng-ai e03c5507f7 ci: publish a nightly prerelease of main every day (#6962)
nightly.yml builds main at 18:00 UTC, when it has moved since the last
nightly, as v<next patch>-nightly.<date>: a tag on a commit over main that
only sets the version (scripts/nightly-prepare.ts), built and published by
release.yml, which can now be called with `nightly: true` (notes from the
previous nightly; no official plugins, CNB mirror or Homebrew cask).

Nightly apps update from the rolling `nightly` release, which holds the
newest nightly's latest.json, and skip the CNB mirror, which carries only
stable releases. Stable apps keep reading releases/latest, never a
prerelease. The MSI gets a numeric version (last release + run number),
and the newest 14 nightlies are kept.
2026-11-30 15:55:50 +08:00

108 рядки
4.8 KiB
TypeScript
Неформатований Анотація Історія

Цей файл містить неоднозначні символи Юнікоду
Цей файл містить символи Юнікоду, які можна сплутати з іншими символами. Якщо ви вважаєте, що це зроблено навмисно, можете сміливо ігнорувати це попередження. Щоб показати їх, скористайтеся кнопкою Escape.
/**
* Prepares a nightly build commit (nightly.yml): `node scripts/nightly-prepare.ts --date 20261130
* --build 42` sets the app version to the next patch's nightly, `0.1.56-nightly.20261130` (`.2`,
* `.3`… when that tag already exists), in Cargo.toml, package.json and tauri.conf.json, points the
* updater at the nightly channel's manifest, gives the MSI installer a numeric version, refreshes
* Cargo.lock and the plugin API snapshot, and prints the version (also `version=` in
* $GITHUB_OUTPUT). The next patch is the current version's when that is already released (its
* `v` tag exists), else the current version itself.
*/
import { spawnSync } from "node:child_process";
import { appendFileSync, readFileSync } from "node:fs";
import { join } from "node:path";
import { fileURLToPath } from "node:url";
import {
cargoVersion,
edit,
parseVersion,
setCargoVersion,
setJsonVersion,
syncApiSnapshot,
} from "./release-prepare.ts";
/** The nightly channel's updater manifest: the rolling `nightly` release (nightly.yml). */
export const NIGHTLY_ENDPOINT = "https://github.com/l0ng-ai/openidea/releases/download/nightly/latest.json";
function bump(version: string): string {
const [major, minor, patch] = version.split(".").map(Number);
return `${major}.${minor}.${patch! + 1}`;
}
/** The nightly's version: the first of `<next>-nightly.<date>`, `….2`, `….3` whose tag is not in `tags`. */
export function nightlyVersion(current: string, released: boolean, date: string, tags: Set<string>): string {
if (!/^\d{8}$/.test(date)) throw new Error(`expected a date like 20261130, got ${date}`);
const base = `${released ? bump(parseVersion(current)) : parseVersion(current)}-nightly.${date}`;
for (let n = 1; ; n++) {
const version = n === 1 ? base : `${base}.${n}`;
if (!tags.has(`v${version}`)) return version;
}
}
/**
* The MSI ProductVersion (`major.minor.patch.build`, numbers only): the last released version
* with the build number, so a nightly sorts after that release and before the next.
*/
export function msiVersion(current: string, released: boolean, build: number): string {
if (!Number.isInteger(build) || build < 0 || build > 65535) throw new Error(`build ${build} is not 0–65535`);
const [major, minor, patch] = parseVersion(current).split(".").map(Number);
const last = released || patch === 0 ? patch : patch! - 1;
return `${major}.${minor}.${last}.${build}`;
}
/** tauri.conf.json for a nightly: its version, the nightly updater manifest and the MSI version. */
export function setNightlyConfig(json: string, version: string, msi: string): string {
const config = JSON.parse(setJsonVersion(json, version)) as {
plugins?: { updater?: { endpoints?: string[] } };
bundle?: { windows?: { wix?: { version?: string } } };
};
if (!config.plugins?.updater) throw new Error("tauri.conf.json: no plugins.updater");
config.plugins.updater.endpoints = [NIGHTLY_ENDPOINT];
config.bundle ??= {};
config.bundle.windows ??= {};
config.bundle.windows.wix = { ...config.bundle.windows.wix, version: msi };
return `${JSON.stringify(config, null, 2)}\n`;
}
function arg(name: string): string {
const index = process.argv.indexOf(`--${name}`);
const value = index >= 0 ? process.argv[index + 1] : undefined;
if (!value) throw new Error(`missing --${name}`);
return value;
}
function git(root: string, ...args: string[]): string {
const result = spawnSync("git", args, { cwd: root, encoding: "utf8" });
if (result.status !== 0) throw new Error(`git ${args.join(" ")}: ${result.stderr}`);
return result.stdout;
}
function main() {
const root = fileURLToPath(new URL("..", import.meta.url));
const date = arg("date");
const build = Number(arg("build"));
const current = cargoVersion(readFileSync(join(root, "Cargo.toml"), "utf8"));
const tags = new Set(git(root, "tag", "--list", "v*").split("\n").filter(Boolean));
const released = tags.has(`v${current}`);
const version = nightlyVersion(current, released, date, tags);
const msi = msiVersion(current, released, build);
edit(join(root, "Cargo.toml"), (text) => setCargoVersion(text, version));
edit(join(root, "package.json"), (text) => setJsonVersion(text, version));
edit(join(root, "src-tauri/tauri.conf.json"), (text) => setNightlyConfig(text, version, msi));
const cargo = spawnSync("cargo", ["update", "--workspace"], { cwd: root, stdio: "inherit" });
if (cargo.status !== 0) throw new Error("cargo update --workspace failed");
syncApiSnapshot(root);
if (process.env.GITHUB_OUTPUT) appendFileSync(process.env.GITHUB_OUTPUT, `version=${version}\n`);
console.log(version);
}
if (process.argv[1] && fileURLToPath(import.meta.url) === process.argv[1]) {
try {
main();
} catch (error) {
console.error(`nightly-prepare: ${error instanceof Error ? error.message : String(error)}`);
process.exit(1);
}
}