@rightkit/release 0.2.30 → 0.2.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build-release.mjs +384 -0
- package/cli/right-release.mjs +14 -9
- package/create-mac-updater.mjs +6 -1
- package/create-mac-updater.test.mjs +1 -1
- package/legal-contract.mjs +9 -2
- package/legal-contract.test.mjs +4 -0
- package/package.json +1 -1
- package/pub-upload.mjs +100 -0
- package/release-cli-contract.test.mjs +43 -0
- package/release-state.mjs +111 -0
- package/release-state.test.mjs +224 -0
- package/release.mjs +3 -3
- package/release.test.mjs +14 -17
- package/right-suite-contract.test.mjs +2 -3
- package/rightkit-versions.json +3 -4
- package/upload-release.mjs +221 -0
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import {
|
|
4
|
+
chmodSync,
|
|
5
|
+
closeSync,
|
|
6
|
+
copyFileSync,
|
|
7
|
+
existsSync,
|
|
8
|
+
mkdirSync,
|
|
9
|
+
openSync,
|
|
10
|
+
readFileSync,
|
|
11
|
+
realpathSync,
|
|
12
|
+
renameSync,
|
|
13
|
+
rmSync,
|
|
14
|
+
statfsSync,
|
|
15
|
+
statSync,
|
|
16
|
+
symlinkSync,
|
|
17
|
+
unlinkSync,
|
|
18
|
+
writeFileSync,
|
|
19
|
+
} from "node:fs";
|
|
20
|
+
import path from "node:path";
|
|
21
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
22
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
23
|
+
import { cacheFingerprint, releaseEnvironment, runBuildStateMachine } from "./release-state.mjs";
|
|
24
|
+
|
|
25
|
+
const TOOL_ROOT = path.dirname(fileURLToPath(import.meta.url));
|
|
26
|
+
const WORKER = path.join(TOOL_ROOT, "release.mjs");
|
|
27
|
+
const args = process.argv.slice(2);
|
|
28
|
+
let configName = "right-release.config.mjs";
|
|
29
|
+
let platform = process.platform === "win32" ? "win" : process.platform === "darwin" ? "mac" : process.platform;
|
|
30
|
+
let dryRun = false;
|
|
31
|
+
|
|
32
|
+
for (let i = 0; i < args.length; i += 1) {
|
|
33
|
+
const arg = args[i];
|
|
34
|
+
if (arg === "--config") configName = args[++i];
|
|
35
|
+
else if (arg === "--platform") platform = args[++i];
|
|
36
|
+
else if (arg === "--dry-run") dryRun = true;
|
|
37
|
+
else if (arg === "--tier" || arg.startsWith("--tier=")) fail("build is tier-neutral; select patch or update only during upload");
|
|
38
|
+
else if (arg === "-h" || arg === "--help") usage(0);
|
|
39
|
+
else fail(`unknown argument: ${arg}`);
|
|
40
|
+
}
|
|
41
|
+
if (platform !== "win" && platform !== "mac") fail("--platform must be win or mac");
|
|
42
|
+
|
|
43
|
+
const invocationRoot = path.dirname(path.resolve(configName));
|
|
44
|
+
const repoRoot = git(invocationRoot, ["rev-parse", "--show-toplevel"]);
|
|
45
|
+
const relativeConfig = path.relative(repoRoot, path.resolve(configName)).replaceAll("\\", "/");
|
|
46
|
+
if (relativeConfig.startsWith("../")) fail("release config must live inside the Git repository");
|
|
47
|
+
const vaultRoot = path.join(repoRoot, ".right-release");
|
|
48
|
+
mkdirSync(path.join(vaultRoot, "locks"), { recursive: true });
|
|
49
|
+
const lock = acquireLock(path.join(vaultRoot, "locks", `${platform}.lock.json`));
|
|
50
|
+
let child = null;
|
|
51
|
+
|
|
52
|
+
for (const signal of ["SIGINT", "SIGTERM", "SIGHUP"]) {
|
|
53
|
+
process.once(signal, () => {
|
|
54
|
+
if (child?.pid) killTree(child.pid);
|
|
55
|
+
lock.release();
|
|
56
|
+
process.exit(signal === "SIGINT" ? 130 : 143);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
try {
|
|
61
|
+
if (!dryRun) git(repoRoot, ["fetch", "origin", "main"]);
|
|
62
|
+
const commit = git(repoRoot, ["rev-parse", dryRun ? "HEAD" : "origin/main"]);
|
|
63
|
+
const shortCommit = commit.slice(0, 8);
|
|
64
|
+
const worktree = path.join(vaultRoot, "worktrees", `${platform}-${shortCommit}`);
|
|
65
|
+
if (!existsSync(worktree)) {
|
|
66
|
+
if (dryRun) fail(`dry-run needs an existing worktree: ${worktree}`);
|
|
67
|
+
mkdirSync(path.dirname(worktree), { recursive: true });
|
|
68
|
+
runChecked("git", ["worktree", "add", "--detach", worktree, commit], repoRoot);
|
|
69
|
+
} else if (git(worktree, ["rev-parse", "HEAD"]) !== commit) {
|
|
70
|
+
fail(`release worktree exists at the wrong commit: ${worktree}`);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const worktreeConfigPath = path.join(worktree, relativeConfig);
|
|
74
|
+
const config = (await import(`${pathToFileURL(worktreeConfigPath).href}?commit=${commit}`)).default;
|
|
75
|
+
if (!config?.app || !config?.version) fail("release config must expose app and version");
|
|
76
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(config.app) || !/^[A-Za-z0-9][A-Za-z0-9._+-]*$/.test(config.version)) {
|
|
77
|
+
fail("app and version must be safe release-id components");
|
|
78
|
+
}
|
|
79
|
+
const target = config.targets?.[platform];
|
|
80
|
+
if (!target?.package) fail(`${config.app} has no ${platform} package command`);
|
|
81
|
+
const requiredInputs = inputPaths(worktree, worktreeConfigPath, target);
|
|
82
|
+
const toolVersions = collectToolVersions(config.packageManager ?? "pnpm");
|
|
83
|
+
const inputHashes = hashInputs(requiredInputs);
|
|
84
|
+
const cargoLock = requiredInputs.find((file) => /Cargo\.lock$/i.test(file));
|
|
85
|
+
const cargoToml = requiredInputs.find((file) => /Cargo\.toml$/i.test(file));
|
|
86
|
+
const cacheKey = cacheFingerprint({
|
|
87
|
+
cargoLockSha256: cargoLock ? inputHashes[path.relative(worktree, cargoLock)] : "none",
|
|
88
|
+
rustc: toolVersions.rustc,
|
|
89
|
+
target: toolVersions.rustHost,
|
|
90
|
+
features: cargoToml ? sqlCipherFeatures(readFileSync(cargoToml, "utf8")) : [],
|
|
91
|
+
});
|
|
92
|
+
const env = {
|
|
93
|
+
...process.env,
|
|
94
|
+
...releaseEnvironment({ root: vaultRoot, platform, cacheKey, kind: "release" }),
|
|
95
|
+
};
|
|
96
|
+
if (!commandExists("sccache")) delete env.RUSTC_WRAPPER;
|
|
97
|
+
const releaseId = `${config.app}-${config.version}-${shortCommit}`;
|
|
98
|
+
const platformDir = platform === "win" ? "windows" : "mac";
|
|
99
|
+
const buildRoot = path.join(vaultRoot, "build", config.app, config.version, shortCommit, platformDir);
|
|
100
|
+
const stateRoot = path.join(vaultRoot, "state", releaseId, platformDir);
|
|
101
|
+
const lockPayload = {
|
|
102
|
+
schema: 1,
|
|
103
|
+
releaseId,
|
|
104
|
+
app: config.app,
|
|
105
|
+
version: config.version,
|
|
106
|
+
commit,
|
|
107
|
+
platform,
|
|
108
|
+
cacheKey,
|
|
109
|
+
inputs: inputHashes,
|
|
110
|
+
tools: toolVersions,
|
|
111
|
+
createdAt: new Date().toISOString(),
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const result = await runBuildStateMachine({
|
|
115
|
+
root: repoRoot,
|
|
116
|
+
app: config.app,
|
|
117
|
+
version: config.version,
|
|
118
|
+
commit,
|
|
119
|
+
platform,
|
|
120
|
+
requiredInputs,
|
|
121
|
+
ops: {
|
|
122
|
+
preflight: async () => {
|
|
123
|
+
assertDiskSpace(repoRoot, target.preflight?.minFreeGb ?? 20);
|
|
124
|
+
assertExecutables(["git", config.packageManager ?? "pnpm", "cargo", "rustc", ...(target.preflight?.executables ?? [])]);
|
|
125
|
+
for (const name of target.preflight?.env ?? []) if (!process.env[name]) fail(`missing required environment variable: ${name}`);
|
|
126
|
+
for (const command of target.preflight?.commands ?? []) runChecked(command.cmd, command.args ?? [], path.resolve(worktree, command.cwd ?? "."), env);
|
|
127
|
+
mkdirSync(buildRoot, { recursive: true });
|
|
128
|
+
mkdirSync(stateRoot, { recursive: true });
|
|
129
|
+
writeJson(path.join(buildRoot, "release-inputs.lock.json"), lockPayload);
|
|
130
|
+
writeJson(path.join(stateRoot, "release-inputs.lock.json"), lockPayload);
|
|
131
|
+
checkpoint(stateRoot, "preflight_complete");
|
|
132
|
+
},
|
|
133
|
+
prepare: async () => {
|
|
134
|
+
const cacheTarget = env.CARGO_TARGET_DIR;
|
|
135
|
+
const targetLink = path.join(worktree, "src-tauri", "target");
|
|
136
|
+
mkdirSync(cacheTarget, { recursive: true });
|
|
137
|
+
if (!existsSync(targetLink)) symlinkSync(cacheTarget, targetLink, process.platform === "win32" ? "junction" : "dir");
|
|
138
|
+
else if (realpathSync(targetLink) !== realpathSync(cacheTarget)) {
|
|
139
|
+
fail(`worktree target exists and is not the release cache link: ${targetLink}`);
|
|
140
|
+
}
|
|
141
|
+
await runProgress(config.packageManager ?? "pnpm", ["install", "--frozen-lockfile"], worktree, env, cacheTarget);
|
|
142
|
+
},
|
|
143
|
+
build: async () => {
|
|
144
|
+
await runProgress(process.execPath, [WORKER, "--config", worktreeConfigPath, "--platform", platform, "--no-upload"], worktree, env, env.CARGO_TARGET_DIR);
|
|
145
|
+
checkpoint(stateRoot, "build_complete");
|
|
146
|
+
checkpoint(stateRoot, "signed");
|
|
147
|
+
checkpoint(stateRoot, "hardened");
|
|
148
|
+
},
|
|
149
|
+
seal: async ({ sealedDir }) => {
|
|
150
|
+
sealRelease({ configRoot: path.dirname(worktreeConfigPath), sealedDir, releaseId, config, target, platform, commit, inputHashes, toolVersions, cacheKey });
|
|
151
|
+
checkpoint(stateRoot, "sealed");
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
});
|
|
155
|
+
console.log(`right-release build: ${result.resumed ? "resumed" : "sealed"} ${result.releaseId}`);
|
|
156
|
+
console.log(`sealed: ${result.sealedDir}`);
|
|
157
|
+
} finally {
|
|
158
|
+
lock.release();
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function inputPaths(worktree, configPath, target) {
|
|
162
|
+
const candidates = [
|
|
163
|
+
configPath,
|
|
164
|
+
path.join(worktree, "package.json"),
|
|
165
|
+
path.join(worktree, "pnpm-lock.yaml"),
|
|
166
|
+
path.join(worktree, "src-tauri", "Cargo.toml"),
|
|
167
|
+
path.join(worktree, "src-tauri", "Cargo.lock"),
|
|
168
|
+
...(target.preflight?.files ?? []).map((file) => path.resolve(worktree, expandEnv(file))),
|
|
169
|
+
];
|
|
170
|
+
const required = [...new Set(candidates)];
|
|
171
|
+
for (const file of required) if (!existsSync(file)) fail(`missing required release input: ${file}`);
|
|
172
|
+
return required;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function hashInputs(files) {
|
|
176
|
+
return Object.fromEntries(files.map((file) => [path.relative(path.dirname(path.dirname(file)), file), hashFile(file)]));
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function hashFile(file) {
|
|
180
|
+
return createHash("sha256").update(readFileSync(file)).digest("hex");
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function sqlCipherFeatures(text) {
|
|
184
|
+
return [...text.matchAll(/features\s*=\s*\[([^\]]+)\]/g)]
|
|
185
|
+
.flatMap((match) => match[1].match(/"([^"]+)"/g) ?? [])
|
|
186
|
+
.map((value) => value.slice(1, -1))
|
|
187
|
+
.filter((value) => /sqlcipher|openssl/i.test(value));
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function sealRelease({ configRoot, sealedDir, releaseId, config, target, platform, commit, inputHashes, toolVersions, cacheKey }) {
|
|
191
|
+
const sources = new Map();
|
|
192
|
+
const addSource = (source, role) => {
|
|
193
|
+
const current = sources.get(source) ?? new Set();
|
|
194
|
+
current.add(role);
|
|
195
|
+
sources.set(source, current);
|
|
196
|
+
};
|
|
197
|
+
for (const artifact of target.installer?.artifacts ?? []) addSource(path.resolve(configRoot, artifact.file), "installer");
|
|
198
|
+
for (const artifact of target.updater?.artifacts ?? []) {
|
|
199
|
+
addSource(path.resolve(configRoot, artifact.file), "updater");
|
|
200
|
+
addSource(path.resolve(configRoot, artifact.signature), "updater-signature");
|
|
201
|
+
}
|
|
202
|
+
for (const file of sources.keys()) if (!existsSync(file)) fail(`cannot seal missing artifact: ${file}`);
|
|
203
|
+
const temp = `${sealedDir}.tmp-${process.pid}`;
|
|
204
|
+
if (existsSync(temp)) rmSync(temp, { recursive: true, force: true });
|
|
205
|
+
mkdirSync(temp, { recursive: true });
|
|
206
|
+
const files = [];
|
|
207
|
+
const sourceNames = new Map();
|
|
208
|
+
for (const [source, roles] of sources) {
|
|
209
|
+
let name = path.basename(source);
|
|
210
|
+
if ([...sourceNames.values()].includes(name) && sourceNames.get(source) !== name) name = `${[...roles].join("-")}-${name}`;
|
|
211
|
+
sourceNames.set(source, name);
|
|
212
|
+
copyFileSync(source, path.join(temp, name));
|
|
213
|
+
files.push({ role: [...roles].sort().join("+"), name, sha256: hashFile(source), sizeBytes: statSync(source).size });
|
|
214
|
+
}
|
|
215
|
+
const routes = { patch: [], update: [] };
|
|
216
|
+
for (const artifact of target.installer?.artifacts ?? []) {
|
|
217
|
+
const source = path.resolve(configRoot, artifact.file);
|
|
218
|
+
routes.patch.push({ role: "installer", name: sourceNames.get(source), bucket: "public", key: artifact.key });
|
|
219
|
+
}
|
|
220
|
+
for (const artifact of target.updater?.artifacts ?? []) {
|
|
221
|
+
const source = path.resolve(configRoot, artifact.file);
|
|
222
|
+
const patchKey = artifact.patchKey ?? artifact.key.replace("/updates/", "/installers/");
|
|
223
|
+
routes.patch.push({ role: "updater", name: sourceNames.get(source), signature: sourceNames.get(path.resolve(configRoot, artifact.signature)), bucket: "public", key: patchKey, platform: artifact.platform });
|
|
224
|
+
routes.update.push({ role: "updater", name: sourceNames.get(source), signature: sourceNames.get(path.resolve(configRoot, artifact.signature)), bucket: "private", key: artifact.key, platform: artifact.platform });
|
|
225
|
+
}
|
|
226
|
+
writeJson(path.join(temp, "hardening.json"), { schema: 1, passed: true, checkedAt: new Date().toISOString(), files: files.map((file) => file.sha256) });
|
|
227
|
+
const manifest = {
|
|
228
|
+
schema: 1,
|
|
229
|
+
releaseId,
|
|
230
|
+
app: config.app,
|
|
231
|
+
version: config.version,
|
|
232
|
+
commit,
|
|
233
|
+
platform,
|
|
234
|
+
cacheKey,
|
|
235
|
+
files,
|
|
236
|
+
routes,
|
|
237
|
+
inputs: inputHashes,
|
|
238
|
+
tools: toolVersions,
|
|
239
|
+
checkpoints: ["preflight_complete", "build_complete", "signed", "hardened", "sealed"],
|
|
240
|
+
sealedAt: new Date().toISOString(),
|
|
241
|
+
};
|
|
242
|
+
writeJson(path.join(temp, "release-manifest.json"), manifest);
|
|
243
|
+
if (existsSync(sealedDir)) fail(`sealed directory already exists: ${sealedDir}`);
|
|
244
|
+
mkdirSync(path.dirname(sealedDir), { recursive: true });
|
|
245
|
+
renameSync(temp, sealedDir);
|
|
246
|
+
for (const item of files) {
|
|
247
|
+
const file = path.join(sealedDir, item.name);
|
|
248
|
+
try { chmodSync(file, 0o444); } catch { /* best effort; hashes are authoritative */ }
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function collectToolVersions(packageManager) {
|
|
253
|
+
const rustcVerbose = commandOutput("rustc", ["-vV"]);
|
|
254
|
+
return {
|
|
255
|
+
node: process.version,
|
|
256
|
+
packageManager: `${packageManager} ${commandOutput(packageManager, ["--version"])}`,
|
|
257
|
+
cargo: commandOutput("cargo", ["--version"]),
|
|
258
|
+
rustc: rustcVerbose,
|
|
259
|
+
rustHost: rustcVerbose.match(/^host:\s*(.+)$/m)?.[1] ?? "unknown",
|
|
260
|
+
sccache: commandExists("sccache") ? commandOutput("sccache", ["--version"]) : null,
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
async function runProgress(cmd, runArgs, cwd, env, watchDir) {
|
|
265
|
+
const inactivityMs = Number(process.env.RIGHT_RELEASE_STALL_MS ?? 10 * 60 * 1000);
|
|
266
|
+
const absoluteMs = Number(process.env.RIGHT_RELEASE_ABSOLUTE_MS ?? 90 * 60 * 1000);
|
|
267
|
+
let lastProgress = Date.now();
|
|
268
|
+
let lastMtime = newestMtime(watchDir);
|
|
269
|
+
const started = Date.now();
|
|
270
|
+
await new Promise((resolve, reject) => {
|
|
271
|
+
child = spawn(cmd, runArgs, { cwd, env, stdio: ["inherit", "pipe", "pipe"], windowsHide: true, shell: process.platform === "win32" });
|
|
272
|
+
for (const [stream, output] of [[child.stdout, process.stdout], [child.stderr, process.stderr]]) {
|
|
273
|
+
stream.on("data", (chunk) => { lastProgress = Date.now(); output.write(chunk); });
|
|
274
|
+
}
|
|
275
|
+
const monitor = setInterval(() => {
|
|
276
|
+
const mtime = newestMtime(watchDir);
|
|
277
|
+
if (mtime > lastMtime) { lastMtime = mtime; lastProgress = Date.now(); }
|
|
278
|
+
if (Date.now() - started > absoluteMs) stop(`absolute limit exceeded (${Math.round(absoluteMs / 60000)}m)`);
|
|
279
|
+
else if (Date.now() - lastProgress > inactivityMs) stop(`no output or file progress for ${Math.round(inactivityMs / 60000)}m`);
|
|
280
|
+
}, Math.min(30_000, Math.max(250, Math.floor(inactivityMs / 4))));
|
|
281
|
+
const stop = (reason) => { clearInterval(monitor); killTree(child.pid); reject(new Error(`release step stalled: ${reason}`)); };
|
|
282
|
+
child.once("error", (error) => { clearInterval(monitor); reject(error); });
|
|
283
|
+
child.once("exit", (code) => { clearInterval(monitor); child = null; code === 0 ? resolve() : reject(new Error(`${cmd} exited ${code}`)); });
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function newestMtime(dir) {
|
|
288
|
+
if (!existsSync(dir)) return 0;
|
|
289
|
+
try { return statSync(dir).mtimeMs; } catch { return 0; }
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
function checkpoint(stateRoot, name) {
|
|
293
|
+
const file = path.join(stateRoot, "checkpoints.json");
|
|
294
|
+
const state = existsSync(file) ? JSON.parse(readFileSync(file, "utf8")) : { schema: 1, completed: [] };
|
|
295
|
+
if (!state.completed.includes(name)) state.completed.push(name);
|
|
296
|
+
state.updatedAt = new Date().toISOString();
|
|
297
|
+
writeJson(file, state);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
function acquireLock(file) {
|
|
301
|
+
if (existsSync(file)) {
|
|
302
|
+
try {
|
|
303
|
+
const existing = JSON.parse(readFileSync(file, "utf8"));
|
|
304
|
+
if (!processAlive(existing.pid)) unlinkSync(file);
|
|
305
|
+
} catch {
|
|
306
|
+
unlinkSync(file);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
try {
|
|
310
|
+
const fd = openSync(file, "wx");
|
|
311
|
+
writeFileSync(fd, `${JSON.stringify({ pid: process.pid, startedAt: new Date().toISOString(), argv: process.argv })}\n`);
|
|
312
|
+
closeSync(fd);
|
|
313
|
+
return { release: () => { try { unlinkSync(file); } catch { /* already released */ } } };
|
|
314
|
+
} catch (error) {
|
|
315
|
+
if (error.code === "EEXIST") fail(`another ${platform} release is active: ${file}`);
|
|
316
|
+
throw error;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
function processAlive(pid) {
|
|
321
|
+
if (!Number.isInteger(Number(pid)) || Number(pid) <= 0) return false;
|
|
322
|
+
try { process.kill(Number(pid), 0); return true; } catch { return false; }
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
function assertDiskSpace(dir, minimumGb) {
|
|
326
|
+
const stats = statfsSync(dir);
|
|
327
|
+
const freeGb = Number(stats.bavail * stats.bsize) / 1024 ** 3;
|
|
328
|
+
if (freeGb < minimumGb) fail(`insufficient disk space: ${freeGb.toFixed(1)} GiB free, ${minimumGb} GiB required`);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
function assertExecutables(names) {
|
|
332
|
+
for (const name of names) if (!commandExists(name)) fail(`required executable not found: ${name}`);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
function commandExists(name) {
|
|
336
|
+
const probe = process.platform === "win32" ? spawnSync("where.exe", [name], { stdio: "ignore", windowsHide: true }) : spawnSync("sh", ["-lc", `command -v '${name.replaceAll("'", "")}'`], { stdio: "ignore" });
|
|
337
|
+
return probe.status === 0;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
function commandOutput(cmd, runArgs) {
|
|
341
|
+
const result = spawnSync(cmd, runArgs, { encoding: "utf8", windowsHide: true });
|
|
342
|
+
if (result.status !== 0) fail(`required command failed: ${cmd} ${runArgs.join(" ")}`);
|
|
343
|
+
return result.stdout.trim();
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
function git(cwd, runArgs) {
|
|
347
|
+
return commandOutputAt("git", runArgs, cwd);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
function commandOutputAt(cmd, runArgs, cwd) {
|
|
351
|
+
const result = spawnSync(cmd, runArgs, { cwd, encoding: "utf8", windowsHide: true });
|
|
352
|
+
if (result.status !== 0) fail(`${cmd} ${runArgs.join(" ")} failed: ${(result.stderr ?? "").trim()}`);
|
|
353
|
+
return result.stdout.trim();
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
function runChecked(cmd, runArgs, cwd, env = process.env) {
|
|
357
|
+
const result = spawnSync(cmd, runArgs, { cwd, env, stdio: "inherit", windowsHide: true, shell: false });
|
|
358
|
+
if (result.status !== 0) fail(`${cmd} exited ${result.status}`);
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
function killTree(pid) {
|
|
362
|
+
if (!pid) return;
|
|
363
|
+
if (process.platform === "win32") spawnSync("taskkill", ["/PID", String(pid), "/T", "/F"], { stdio: "ignore", windowsHide: true });
|
|
364
|
+
else { try { process.kill(-pid, "SIGTERM"); } catch { try { process.kill(pid, "SIGTERM"); } catch { /* gone */ } } }
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
function expandEnv(value) {
|
|
368
|
+
return String(value).replace(/%([^%]+)%/g, (_, name) => process.env[name] ?? "").replace(/\$\{([^}]+)\}/g, (_, name) => process.env[name] ?? "");
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
function writeJson(file, value) {
|
|
372
|
+
mkdirSync(path.dirname(file), { recursive: true });
|
|
373
|
+
writeFileSync(file, `${JSON.stringify(value, null, 2)}\n`);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
function usage(code) {
|
|
377
|
+
console.log("usage: right-release build --platform win|mac [--config right-release.config.mjs] [--dry-run]");
|
|
378
|
+
process.exit(code);
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
function fail(message) {
|
|
382
|
+
console.error(`right-release build: ${message}`);
|
|
383
|
+
process.exit(1);
|
|
384
|
+
}
|
package/cli/right-release.mjs
CHANGED
|
@@ -5,9 +5,11 @@ import { fileURLToPath } from "node:url";
|
|
|
5
5
|
|
|
6
6
|
const packageRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
|
7
7
|
const commands = new Map([
|
|
8
|
-
["release", "release.mjs"],
|
|
9
|
-
["build", "release.mjs"],
|
|
10
|
-
["package", "release.mjs"],
|
|
8
|
+
["release", "build-release.mjs"],
|
|
9
|
+
["build", "build-release.mjs"],
|
|
10
|
+
["package", "build-release.mjs"],
|
|
11
|
+
["publish", "upload-release.mjs"],
|
|
12
|
+
["upload", "upload-release.mjs"],
|
|
11
13
|
["deps", "deps.mjs"],
|
|
12
14
|
["publish-update", "publish-update.mjs"],
|
|
13
15
|
["hardening", "hardeningscan.mjs"],
|
|
@@ -47,7 +49,7 @@ if (first === "--version" || first === "-v") {
|
|
|
47
49
|
} else if (rest[0] === "swift") {
|
|
48
50
|
run("publish-swift.mjs", rest.slice(1));
|
|
49
51
|
} else {
|
|
50
|
-
run("release.mjs", rest
|
|
52
|
+
run("upload-release.mjs", rest);
|
|
51
53
|
}
|
|
52
54
|
} else if (first === "model") {
|
|
53
55
|
const rest = args.slice(1);
|
|
@@ -63,7 +65,7 @@ if (first === "--version" || first === "-v") {
|
|
|
63
65
|
} else if (commands.has(first)) {
|
|
64
66
|
run(commands.get(first), args.slice(1));
|
|
65
67
|
} else if (first.startsWith("-")) {
|
|
66
|
-
run("release.mjs", args);
|
|
68
|
+
run("build-release.mjs", args);
|
|
67
69
|
} else {
|
|
68
70
|
console.error(`right-release: unknown command: ${first}\n`);
|
|
69
71
|
printHelp();
|
|
@@ -119,8 +121,11 @@ function printHelp() {
|
|
|
119
121
|
console.log(`right-release <command> [options]
|
|
120
122
|
|
|
121
123
|
Commands:
|
|
122
|
-
|
|
123
|
-
|
|
124
|
+
build [--platform mac|win] Build, sign/notarize, harden, and seal; never uploads
|
|
125
|
+
upload --release <id> --platform mac|win --tier patch|update
|
|
126
|
+
Upload one sealed release; never builds
|
|
127
|
+
release Compatibility alias for build
|
|
128
|
+
publish Compatibility alias for upload
|
|
124
129
|
publish cargo --crate <name> [--dry-run] Test, inspect, scan, and publish one crates.io package
|
|
125
130
|
publish swift [--scope <s>] [--url <u>] [--dry-run] Test, archive, scan, and publish RightKitSwift to a Swift registry
|
|
126
131
|
model promote --authority heardright --config <file> [--dry-run]
|
|
@@ -135,6 +140,6 @@ Commands:
|
|
|
135
140
|
mirror-root-artifact --file <path> --package-root <dir>
|
|
136
141
|
Persist a worktree artifact in the primary repo root
|
|
137
142
|
|
|
138
|
-
Direct flags are treated as: right-release
|
|
139
|
-
|
|
143
|
+
Direct flags are treated as: right-release build <flags>.
|
|
144
|
+
Build is tier-neutral. Upload requires an explicit tier. Unsigned/local smoke builds stay app-local.`);
|
|
140
145
|
}
|
package/create-mac-updater.mjs
CHANGED
|
@@ -23,6 +23,10 @@ const outputPath = path.resolve(cwd, output);
|
|
|
23
23
|
if (!dryRun && !existsSync(appPath)) fail(`signed app not found: ${appPath}`);
|
|
24
24
|
|
|
25
25
|
const env = { ...process.env };
|
|
26
|
+
// bsdtar otherwise serializes macOS extended attributes as AppleDouble `._*`
|
|
27
|
+
// entries. Tauri's Rust extractor writes those entries as real bundle files,
|
|
28
|
+
// invalidating the Developer ID seal and causing syspolicyd to trash the app.
|
|
29
|
+
env.COPYFILE_DISABLE = "1";
|
|
26
30
|
if (!dryRun && !env.TAURI_SIGNING_PRIVATE_KEY) {
|
|
27
31
|
try {
|
|
28
32
|
env.TAURI_SIGNING_PRIVATE_KEY = execFileSync(
|
|
@@ -50,7 +54,8 @@ run("tar", [
|
|
|
50
54
|
run("pnpm", ["exec", "tauri", "signer", "sign", outputPath]);
|
|
51
55
|
|
|
52
56
|
function run(command, commandArgs) {
|
|
53
|
-
|
|
57
|
+
const envPrefix = command === "tar" ? "COPYFILE_DISABLE=1 " : "";
|
|
58
|
+
console.log(`${dryRun ? "[dry-run] " : ""}${envPrefix}${command} ${commandArgs.join(" ")}`);
|
|
54
59
|
if (dryRun) return;
|
|
55
60
|
const result = spawnSync(command, commandArgs, { cwd, env, stdio: "inherit" });
|
|
56
61
|
if (result.status !== 0) process.exit(result.status ?? 1);
|
|
@@ -8,7 +8,7 @@ const helper = fileURLToPath(new URL("./create-mac-updater.mjs", import.meta.url
|
|
|
8
8
|
test("documents the final signed-app to signed-updater sequence in dry-run mode", () => {
|
|
9
9
|
const result = spawnSync(process.execPath, [helper, "--app", "bundle/Test.app", "--output", "bundle/Test.app.tar.gz", "--dry-run"], { encoding: "utf8" });
|
|
10
10
|
assert.equal(result.status, 0, result.stderr);
|
|
11
|
-
assert.match(result.stdout, /tar .*Test\.app\.tar\.gz.*Test\.app\/Contents/);
|
|
11
|
+
assert.match(result.stdout, /COPYFILE_DISABLE=1 tar .*Test\.app\.tar\.gz.*Test\.app\/Contents/);
|
|
12
12
|
assert.doesNotMatch(result.stdout, / Test\.app$/m);
|
|
13
13
|
assert.match(result.stdout, /tauri signer sign .*Test\.app\.tar\.gz/);
|
|
14
14
|
});
|
package/legal-contract.mjs
CHANGED
|
@@ -135,8 +135,15 @@ export function assertLegalReleaseContract(root, legal, appName, platform) {
|
|
|
135
135
|
appendices.push({ ...appendix, absolutePath: realFile });
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
-
// The in-app gate is the
|
|
139
|
-
//
|
|
138
|
+
// The in-app gate is the SINGLE assent surface (Adrian, 2026-07-17). An
|
|
139
|
+
// installer/DMG can only PRESENT the text: it cannot record who agreed, cannot ask
|
|
140
|
+
// the individual-vs-enterprise basis, and passive updaters reach neither — so a
|
|
141
|
+
// license page is duplicate presentation that captures nothing. This gate
|
|
142
|
+
// previously REQUIRED bundle.licenseFile; it now requires its absence.
|
|
143
|
+
//
|
|
144
|
+
// Checked on EVERY platform, not just Windows: one bundle.licenseFile drives BOTH
|
|
145
|
+
// the NSIS license page and the macOS DMG SLA (branded-dmg.mjs derives its --eula
|
|
146
|
+
// from it), so a win-only check would let a mac build reintroduce the SLA.
|
|
140
147
|
if (typeof legal.tauriConfig !== "string") fail(appName, "the legal gate requires legal.tauriConfig");
|
|
141
148
|
const tauriPath = path.resolve(appRoot, legal.tauriConfig);
|
|
142
149
|
if (!within(appRoot, tauriPath) || !existsSync(tauriPath)) fail(appName, `missing Tauri config: ${legal.tauriConfig}`);
|
package/legal-contract.test.mjs
CHANGED
|
@@ -46,6 +46,8 @@ function fixture() {
|
|
|
46
46
|
})),
|
|
47
47
|
};
|
|
48
48
|
writeFileSync(path.join(legalDir, "legal-manifest.json"), `${JSON.stringify(manifest, null, 2)}\n`);
|
|
49
|
+
// No bundle.licenseFile: the in-app gate is the single assent surface, so a
|
|
50
|
+
// compliant app ships an installer with no license page (Adrian, 2026-07-17).
|
|
49
51
|
writeFileSync(
|
|
50
52
|
path.join(tauriDir, "tauri.conf.json"),
|
|
51
53
|
`${JSON.stringify({ bundle: { publisher: "Damned Ventures LLC" } }, null, 2)}\n`,
|
|
@@ -105,6 +107,8 @@ test("rejects a Windows installer license page: the in-app gate is the only asse
|
|
|
105
107
|
});
|
|
106
108
|
|
|
107
109
|
test("rejects a macOS DMG SLA too — one licenseFile drives both bundlers", () => {
|
|
110
|
+
// branded-dmg.mjs derives its --eula from bundle.licenseFile, so a Windows-only
|
|
111
|
+
// check would let a mac release quietly reintroduce the mount-time SLA.
|
|
108
112
|
const { root, legal } = fixture();
|
|
109
113
|
writeFileSync(path.join(root, "src-tauri", "tauri.conf.json"), JSON.stringify({ bundle: { licenseFile: "../legal/EULA.md" } }));
|
|
110
114
|
assert.throws(() => assertLegalReleaseContract(root, legal, "fixture", "mac"), /licenseFile must be absent/i);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rightkit/release",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.32",
|
|
4
4
|
"description": "Portable Right Suite release CLI/SDK: signed installers, updater artifacts, patch/update routing, hardening, R2 publish, and RightApps registration.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
package/pub-upload.mjs
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { accessSync, statSync } from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { spawnSync } from "node:child_process";
|
|
5
|
+
|
|
6
|
+
const ACCOUNT_ID = "03ae77ccd7a07bcbb2dcfde47fa7ba3a";
|
|
7
|
+
const BUCKETS = new Map([
|
|
8
|
+
["public", "rightapps-downloads"],
|
|
9
|
+
["private", "rightapps-updates"],
|
|
10
|
+
]);
|
|
11
|
+
// Wrangler always runs remotely through a package runner; which one exists is machine-specific
|
|
12
|
+
// (a node install without npm/npx is normal when pnpm is the pinned package manager).
|
|
13
|
+
const RUNNERS = [
|
|
14
|
+
{ cmd: "npx", prefix: [] },
|
|
15
|
+
{ cmd: "pnpm", prefix: ["dlx"] },
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
const [, , localFile, r2Key, bucketAlias = "public"] = process.argv;
|
|
19
|
+
if (!localFile || !r2Key) {
|
|
20
|
+
console.error("Usage: node upload-large.mjs <localFile> <r2Key> [public|private]");
|
|
21
|
+
process.exit(1);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const bucket = BUCKETS.get(bucketAlias);
|
|
25
|
+
if (!bucket) {
|
|
26
|
+
console.error(`upload-large: invalid bucket alias ${bucketAlias}; expected public|private`);
|
|
27
|
+
process.exit(1);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
try {
|
|
31
|
+
accessSync(localFile);
|
|
32
|
+
} catch {
|
|
33
|
+
console.error(`upload-large: missing local file: ${localFile}`);
|
|
34
|
+
process.exit(1);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const fileSize = statSync(localFile).size;
|
|
38
|
+
const object = `${bucket}/${r2Key}`;
|
|
39
|
+
const wranglerArgs = ["wrangler@4", "r2", "object", "put", object, "--file", path.resolve(localFile), "--remote"];
|
|
40
|
+
const env = cleanCloudflareEnv(process.env);
|
|
41
|
+
|
|
42
|
+
console.log(`Uploading ${path.basename(localFile)} (${(fileSize / 1024 / 1024).toFixed(1)} MB) -> ${object}`);
|
|
43
|
+
console.log(`wrangler r2 object put ${object} --file ${path.resolve(localFile)} --remote`);
|
|
44
|
+
|
|
45
|
+
// Resolve the package runner before the dry-run exit: a release box without one cannot upload,
|
|
46
|
+
// and that must fail here rather than after a signed build has already been produced.
|
|
47
|
+
const runner = resolveRunner(env);
|
|
48
|
+
if (!runner) {
|
|
49
|
+
console.error(
|
|
50
|
+
"upload-large: no package runner found. Tried: " +
|
|
51
|
+
`${RUNNERS.map((entry) => [entry.cmd, ...entry.prefix].join(" ")).join(", ")}. ` +
|
|
52
|
+
"Install one, or set RIGHT_RELEASE_WRANGLER_RUNNER (e.g. \"pnpm dlx\").",
|
|
53
|
+
);
|
|
54
|
+
process.exit(1);
|
|
55
|
+
}
|
|
56
|
+
console.log(`runner: ${[runner.cmd, ...runner.prefix].join(" ")}`);
|
|
57
|
+
|
|
58
|
+
if (process.env.RIGHT_RELEASE_UPLOAD_DRY_RUN === "1") {
|
|
59
|
+
process.exit(0);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const result = spawnSync(runner.cmd, [...runner.prefix, ...wranglerArgs], {
|
|
63
|
+
env,
|
|
64
|
+
stdio: "inherit",
|
|
65
|
+
shell: process.platform === "win32",
|
|
66
|
+
windowsHide: true,
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
if (result.error) {
|
|
70
|
+
console.error(`upload-large: failed to start wrangler: ${result.error.message}`);
|
|
71
|
+
process.exit(1);
|
|
72
|
+
}
|
|
73
|
+
process.exit(result.status ?? 1);
|
|
74
|
+
|
|
75
|
+
function resolveRunner(env) {
|
|
76
|
+
const override = process.env.RIGHT_RELEASE_WRANGLER_RUNNER?.trim();
|
|
77
|
+
if (override) {
|
|
78
|
+
const [cmd, ...prefix] = override.split(/\s+/);
|
|
79
|
+
return { cmd, prefix };
|
|
80
|
+
}
|
|
81
|
+
for (const candidate of RUNNERS) {
|
|
82
|
+
const probe = spawnSync(candidate.cmd, ["--version"], {
|
|
83
|
+
env,
|
|
84
|
+
stdio: "ignore",
|
|
85
|
+
shell: process.platform === "win32",
|
|
86
|
+
windowsHide: true,
|
|
87
|
+
});
|
|
88
|
+
if (!probe.error && probe.status === 0) return candidate;
|
|
89
|
+
}
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function cleanCloudflareEnv(source) {
|
|
94
|
+
const env = { ...source, CLOUDFLARE_ACCOUNT_ID: source.CLOUDFLARE_ACCOUNT_ID || ACCOUNT_ID };
|
|
95
|
+
delete env.CLOUDFLARE_API_KEY;
|
|
96
|
+
delete env.CLOUDFLARE_EMAIL;
|
|
97
|
+
delete env.CF_API_KEY;
|
|
98
|
+
delete env.CF_EMAIL;
|
|
99
|
+
return env;
|
|
100
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { mkdtempSync, readFileSync } from "node:fs";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { spawnSync } from "node:child_process";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
import test from "node:test";
|
|
8
|
+
|
|
9
|
+
const root = path.dirname(fileURLToPath(import.meta.url));
|
|
10
|
+
const cli = path.join(root, "cli", "right-release.mjs");
|
|
11
|
+
const build = path.join(root, "build-release.mjs");
|
|
12
|
+
const upload = path.join(root, "upload-release.mjs");
|
|
13
|
+
|
|
14
|
+
test("CLI routes build and release only to the build state machine", () => {
|
|
15
|
+
const source = readFileSync(cli, "utf8");
|
|
16
|
+
assert.match(source, /\["build",\s*"build-release\.mjs"\]/);
|
|
17
|
+
assert.match(source, /\["release",\s*"build-release\.mjs"\]/);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test("CLI routes upload and legacy publish only to the upload state machine", () => {
|
|
21
|
+
const source = readFileSync(cli, "utf8");
|
|
22
|
+
assert.match(source, /\["upload",\s*"upload-release\.mjs"\]/);
|
|
23
|
+
assert.match(source, /\["publish",\s*"upload-release\.mjs"\]/);
|
|
24
|
+
assert.doesNotMatch(source, /first === "publish"[\s\S]{0,500}run\("release\.mjs"/);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test("build is tier-neutral and rejects a tier before touching a repository", () => {
|
|
28
|
+
const result = spawnSync(process.execPath, [build, "--platform", "win", "--tier", "patch"], {
|
|
29
|
+
cwd: mkdtempSync(path.join(os.tmpdir(), "right-build-cli-")),
|
|
30
|
+
encoding: "utf8",
|
|
31
|
+
});
|
|
32
|
+
assert.notEqual(result.status, 0);
|
|
33
|
+
assert.match(result.stderr, /build is tier-neutral/i);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test("upload requires an explicit patch or update tier before reading a release", () => {
|
|
37
|
+
const result = spawnSync(process.execPath, [upload, "--platform", "win", "--release", "fixture-1.0.0-deadbeef"], {
|
|
38
|
+
cwd: mkdtempSync(path.join(os.tmpdir(), "right-upload-cli-")),
|
|
39
|
+
encoding: "utf8",
|
|
40
|
+
});
|
|
41
|
+
assert.notEqual(result.status, 0);
|
|
42
|
+
assert.match(result.stderr, /tier is required.*patch\|update/i);
|
|
43
|
+
});
|