Skip to content

A personal assistant that lives on your desktop, remembers what matters, and can use your Mac for you.

TypeScript

fix(package): CI never stages a Windows runtime without its commit

Marcelito80af8accb78c
diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml
index c5d5a9b..09db519 100644
--- a/.github/workflows/windows.yml
+++ b/.github/workflows/windows.yml
@@ -96,5 +96,5 @@ jobs:
# The daemon test files that run on Windows (the runtime build uses the addon built above).
- name: Daemon tests
- run: pnpm exec vitest run packages/daemon/test/windows-stop.test.ts packages/daemon/test/windows-app-channel.test.ts packages/daemon/test/app-channel-platform.test.ts packages/daemon/test/app-channel.test.ts packages/daemon/test/app-channel-fd.test.ts packages/daemon/test/windows-app-channel-addon.test.ts packages/daemon/test/process-tree.test.ts packages/daemon/test/supervisor.test.ts packages/daemon/test/runtime.test.ts packages/daemon/test/config.test.ts packages/daemon/test/isolation.test.ts packages/daemon/test/private-memory.test.ts packages/daemon/test/lifecycle.test.ts packages/daemon/test/cli.test.ts packages/daemon/test/runtime-build.test.ts
+ run: pnpm exec vitest run packages/daemon/test/windows-stop.test.ts packages/daemon/test/windows-app-channel.test.ts packages/daemon/test/app-channel-platform.test.ts packages/daemon/test/app-channel.test.ts packages/daemon/test/app-channel-fd.test.ts packages/daemon/test/windows-app-channel-addon.test.ts packages/daemon/test/process-tree.test.ts packages/daemon/test/supervisor.test.ts packages/daemon/test/runtime.test.ts packages/daemon/test/config.test.ts packages/daemon/test/isolation.test.ts packages/daemon/test/private-memory.test.ts packages/daemon/test/lifecycle.test.ts packages/daemon/test/cli.test.ts packages/daemon/test/runtime-build.test.ts scripts/package/test/lib.test.ts
diff --git a/scripts/package/lib.mjs b/scripts/package/lib.mjs
index 14e7950..696bf9e 100644
--- a/scripts/package/lib.mjs
+++ b/scripts/package/lib.mjs
@@ -150,8 +150,10 @@ export function windowsBuildGo(source, isFile) {
win32.basename(exe).toLowerCase() !== "go.exe" ||
/[;\r\n"]/.test(exe)
)
- throw new Error("GENTLE_DOT_BUILD_GO must name an absolute, already provisioned go.exe.");
- if (!isFile(exe)) throw new Error("GENTLE_DOT_BUILD_GO must name an existing regular file.");
+ throw new Error(
+ "GENTLE_DOT_BUILD_GO must be the full path of the real go.exe in GOROOT\\bin (not a Scoop or Chocolatey shim), such as C:\\Program Files\\Go\\bin\\go.exe.",
+ );
+ if (!isFile(exe)) throw new Error(`GENTLE_DOT_BUILD_GO names ${exe}, which is not an existing file.`);
return exe;
}
@@ -280,14 +282,24 @@ export function formatSize(bytes) {
return `${(bytes / 1024 / 1024).toFixed(1)} MB`;
}
-/** A copied Windows source tree has no Git revision; never manufacture one. */
+/**
+ * A copied Windows source tree has no Git revision; never manufacture one. That label is for a
+ * local copy only: CI stages release candidates, which must name their daemon commit.
+ */
export function daemonSourceRevision(
repo,
platform = process.platform,
present = existsSync,
git = execFileSync,
+ ci = process.env.CI,
) {
- if (platform === "win32" && !present(join(repo, ".git"))) return "snapshot-unversioned";
+ if (platform === "win32" && !present(join(repo, ".git"))) {
+ if (ci)
+ throw new Error(
+ `CI must stage from a Git checkout: ${repo} has no .git, so the runtime would have no daemon commit.`,
+ );
+ return "snapshot-unversioned";
+ }
const commit = git("git", ["rev-parse", "HEAD"], { cwd: repo, encoding: "utf8" }).trim();
const dirty = git("git", ["status", "--porcelain", "--", "packages"], { cwd: repo, encoding: "utf8" });
return dirty.trim() ? `${commit}-dirty` : commit;
diff --git a/scripts/package/test/lib.test.ts b/scripts/package/test/lib.test.ts
index fc5633d..3a924ae 100644
--- a/scripts/package/test/lib.test.ts
+++ b/scripts/package/test/lib.test.ts
@@ -214,10 +214,14 @@ describe("Windows staging install", () => {
SECRET: "omit",
};
expect(windowsBuildGo(source, () => true)).toBe(source.GENTLE_DOT_BUILD_GO);
- expect(() => windowsBuildGo({}, () => true)).toThrow(/GENTLE_DOT_BUILD_GO/);
- expect(() => windowsBuildGo(source, () => false)).toThrow(/existing/);
+ const usage =
+ "GENTLE_DOT_BUILD_GO must be the full path of the real go.exe in GOROOT\\bin (not a Scoop or Chocolatey shim), such as C:\\Program Files\\Go\\bin\\go.exe.";
+ expect(() => windowsBuildGo({}, () => true)).toThrow(usage);
+ expect(() => windowsBuildGo(source, () => false)).toThrow(
+ "GENTLE_DOT_BUILD_GO names C:\\Program Files\\Go\\bin\\go.exe, which is not an existing file.",
+ );
for (const value of ["go.exe", "C:\\tools;other\\go.exe", "C:\\tools\\other.exe"]) {
- expect(() => windowsBuildGo({ GENTLE_DOT_BUILD_GO: value }, () => true)).toThrow(/GENTLE_DOT_BUILD_GO/);
+ expect(() => windowsBuildGo({ GENTLE_DOT_BUILD_GO: value }, () => true)).toThrow(usage);
}
const env = installerEnv("C:\\stage", "C:\\cache", "windows-x64", source, source.GENTLE_DOT_BUILD_GO);
expect(env.PATH).toBe(
@@ -290,14 +294,21 @@ describe("Windows staging install", () => {
const noGit = () => {
throw new Error("must not invoke git for a snapshot");
};
- expect(daemonSourceRevision("C:\\snapshot", "win32", () => false, noGit)).toBe("snapshot-unversioned");
+ // A local copy without .git is labeled; CI (any value of CI) refuses to lose the commit.
+ expect(daemonSourceRevision("C:\\snapshot", "win32", () => false, noGit, "")).toBe(
+ "snapshot-unversioned",
+ );
+ for (const ci of ["true", "1"])
+ expect(() => daemonSourceRevision("C:\\snapshot", "win32", () => false, noGit, ci)).toThrow(
+ "CI must stage from a Git checkout: C:\\snapshot has no .git, so the runtime would have no daemon commit.",
+ );
for (const platform of ["linux", "darwin", "win32"]) {
const calls: unknown[] = [];
const git = (command, args, options) => {
calls.push([command, args, options]);
return args[0] === "rev-parse" ? "abc123\n" : " M packages/daemon/src/cli.ts\n";
};
- expect(daemonSourceRevision("/repo", platform, () => true, git)).toBe("abc123-dirty");
+ expect(daemonSourceRevision("/repo", platform, () => true, git, "true")).toBe("abc123-dirty");
expect(calls).toEqual([
["git", ["rev-parse", "HEAD"], { cwd: "/repo", encoding: "utf8" }],
["git", ["status", "--porcelain", "--", "packages"], { cwd: "/repo", encoding: "utf8" }],