effect-ci 0.1.2 → 0.1.4
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.
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import {
|
|
2
|
+
untracedHits
|
|
3
|
+
} from "./chunk-Q5USMIJ3.js";
|
|
4
|
+
|
|
5
|
+
// ../ci/src/input-evidence.ts
|
|
6
|
+
import { execFileSync } from "node:child_process";
|
|
7
|
+
import { createHash, sign, verify } from "node:crypto";
|
|
8
|
+
import { existsSync, readdirSync, readFileSync, realpathSync, statSync } from "node:fs";
|
|
9
|
+
import { relative, resolve } from "node:path";
|
|
10
|
+
import * as Effect from "effect/Effect";
|
|
11
|
+
var inputEvidenceKey = (request) => JSON.stringify({
|
|
12
|
+
command: request.command,
|
|
13
|
+
repository: request.event.source?.kind === "git" ? request.event.source.repository : void 0,
|
|
14
|
+
scope: request.policy.scope,
|
|
15
|
+
stepId: request.stepId,
|
|
16
|
+
task: request.trace?.task,
|
|
17
|
+
workflowId: request.workflowId
|
|
18
|
+
});
|
|
19
|
+
var maximumRecords = 20;
|
|
20
|
+
var sha256 = (value) => createHash("sha256").update(value).digest("hex");
|
|
21
|
+
var git = (cwd, args, input) => execFileSync("git", args, {
|
|
22
|
+
cwd,
|
|
23
|
+
encoding: "utf8",
|
|
24
|
+
input,
|
|
25
|
+
// Notes hold every traced file's digest: often several MB, past the 1 MB default.
|
|
26
|
+
maxBuffer: 256 * 1024 * 1024,
|
|
27
|
+
stdio: ["pipe", "pipe", "ignore"]
|
|
28
|
+
}).trim();
|
|
29
|
+
var keyObject = (cwd, key) => git(cwd, ["hash-object", "--stdin"], key);
|
|
30
|
+
var canonical = (evidence) => JSON.stringify(evidence, (_key, value) => value && typeof value === "object" && !Array.isArray(value) ? Object.fromEntries(Object.entries(value).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0)) : value);
|
|
31
|
+
var leafSteps = (plan) => Object.values(plan).flatMap((task) => task.steps.flatMap((step) => step.plan ? leafSteps(step.plan) : [step]));
|
|
32
|
+
var digestFile = (path) => sha256(readFileSync(path));
|
|
33
|
+
var traceRun = (cwd, task) => {
|
|
34
|
+
const body = execFileSync("sh", ["-c", 'PATH="$PATH:$PWD/node_modules/.bin" exec vp run --dry-run --json --cache -vv "$1"', "sh", task], {
|
|
35
|
+
cwd,
|
|
36
|
+
encoding: "utf8",
|
|
37
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
38
|
+
maxBuffer: 16 * 1024 * 1024
|
|
39
|
+
});
|
|
40
|
+
const plan = JSON.parse(body);
|
|
41
|
+
if (plan.version !== 1 || untracedHits(body).length > 0) return void 0;
|
|
42
|
+
const steps = leafSteps(plan.plan);
|
|
43
|
+
if (steps.length === 0) return void 0;
|
|
44
|
+
const written = [];
|
|
45
|
+
let writtenKnown = true;
|
|
46
|
+
for (const step of steps) {
|
|
47
|
+
const baseline = step.cache?.baseline;
|
|
48
|
+
if (step.cache?.status === "unknown") {
|
|
49
|
+
const reads = Object.entries(baseline?.fingerprint?.inputs ?? {});
|
|
50
|
+
if (!writtenKnown || reads.length === 0) return void 0;
|
|
51
|
+
const readsWritten = ([path, input]) => written.some((output) => {
|
|
52
|
+
if (output === path) return true;
|
|
53
|
+
const below = path === "." ? output : output.startsWith(`${path}/`) ? output.slice(path.length + 1) : void 0;
|
|
54
|
+
if (below === void 0) return false;
|
|
55
|
+
if (input.type !== "dir") return true;
|
|
56
|
+
const [child] = below.split("/");
|
|
57
|
+
return input.entries !== void 0 && !input.entries.includes(child);
|
|
58
|
+
});
|
|
59
|
+
if (reads.some(readsWritten)) return void 0;
|
|
60
|
+
} else if (step.cache?.status !== "hit") return void 0;
|
|
61
|
+
if (Array.isArray(baseline?.outputs)) written.push(...baseline.outputs);
|
|
62
|
+
else writtenKnown = false;
|
|
63
|
+
}
|
|
64
|
+
const inputs = {};
|
|
65
|
+
const env = {};
|
|
66
|
+
for (const step of steps) {
|
|
67
|
+
const fingerprint = step.cache?.baseline?.fingerprint;
|
|
68
|
+
for (const [path, input] of Object.entries(fingerprint?.inputs ?? {})) {
|
|
69
|
+
const absolute = resolve(plan.workspaceRoot, path);
|
|
70
|
+
if (input.type === "file") {
|
|
71
|
+
if (!existsSync(absolute)) {
|
|
72
|
+
if (!input.mayBeMissing) return void 0;
|
|
73
|
+
inputs[path] = { type: "missing" };
|
|
74
|
+
} else inputs[path] = { type: "file", sha256: digestFile(absolute), ...input.mayBeMissing ? { mayBeMissing: true } : {} };
|
|
75
|
+
} else inputs[path] = input;
|
|
76
|
+
}
|
|
77
|
+
for (const name of fingerprint?.env ?? []) {
|
|
78
|
+
const value = process.env[name];
|
|
79
|
+
env[name] = value === void 0 ? null : sha256(value);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return { root: relative(realpathSync(cwd), realpathSync(plan.workspaceRoot)) || ".", inputs, env };
|
|
83
|
+
};
|
|
84
|
+
var matchesInputEvidence = (cwd, evidence) => {
|
|
85
|
+
const root = resolve(cwd, evidence.root);
|
|
86
|
+
for (const [path, input] of Object.entries(evidence.inputs)) {
|
|
87
|
+
const absolute = resolve(root, path);
|
|
88
|
+
const relativePath = relative(root, absolute);
|
|
89
|
+
if (relativePath.startsWith("..")) return false;
|
|
90
|
+
const exists = existsSync(absolute);
|
|
91
|
+
switch (input.type) {
|
|
92
|
+
case "missing":
|
|
93
|
+
if (exists) return false;
|
|
94
|
+
break;
|
|
95
|
+
case "file":
|
|
96
|
+
if (!exists) {
|
|
97
|
+
if (!input.mayBeMissing) return false;
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
if (!statSync(absolute).isFile() || digestFile(absolute) !== input.sha256) return false;
|
|
101
|
+
break;
|
|
102
|
+
case "dir": {
|
|
103
|
+
if (!exists) {
|
|
104
|
+
if (!input.mayBeMissing) return false;
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
if (!statSync(absolute).isDirectory()) return false;
|
|
108
|
+
if (input.entries) {
|
|
109
|
+
const entries = readdirSync(absolute).filter((entry) => entry !== ".git").sort();
|
|
110
|
+
if (entries.join("\0") !== [...input.entries].sort().join("\0")) return false;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
for (const [name, digest] of Object.entries(evidence.env)) {
|
|
116
|
+
const value = process.env[name];
|
|
117
|
+
if ((value === void 0 ? null : sha256(value)) !== digest) return false;
|
|
118
|
+
}
|
|
119
|
+
return true;
|
|
120
|
+
};
|
|
121
|
+
var notesRef = (options) => `--ref=${options.ref ?? "effect-ci-inputs"}`;
|
|
122
|
+
var readInputEvidenceRecords = (options, key) => {
|
|
123
|
+
try {
|
|
124
|
+
return JSON.parse(git(options.cwd, ["notes", notesRef(options), "show", keyObject(options.cwd, key)]));
|
|
125
|
+
} catch {
|
|
126
|
+
return [];
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
var writeInputEvidenceRecords = (options, key, records) => {
|
|
130
|
+
const identity = (() => {
|
|
131
|
+
try {
|
|
132
|
+
git(options.cwd, ["var", "GIT_COMMITTER_IDENT"]);
|
|
133
|
+
return [];
|
|
134
|
+
} catch {
|
|
135
|
+
return ["-c", "user.name=Effect CI", "-c", "user.email=effect-ci@localhost"];
|
|
136
|
+
}
|
|
137
|
+
})();
|
|
138
|
+
git(
|
|
139
|
+
options.cwd,
|
|
140
|
+
[...identity, "notes", notesRef(options), "add", "--force", "--file", "-", keyObject(options.cwd, key)],
|
|
141
|
+
JSON.stringify(records)
|
|
142
|
+
);
|
|
143
|
+
};
|
|
144
|
+
var inputEvidenceCheckCache = (options) => ({
|
|
145
|
+
lookup: (request) => Effect.sync(() => {
|
|
146
|
+
if (request.policy.scope !== "inputs" || !request.trace || request.workspace.kind !== "local") return false;
|
|
147
|
+
return readInputEvidenceRecords(options, inputEvidenceKey(request)).some(({ evidence, signature }) => verify(null, Buffer.from(canonical(evidence)), options.publicKey, Buffer.from(signature, "base64url")) && matchesInputEvidence(request.workspace.cwd, evidence));
|
|
148
|
+
}),
|
|
149
|
+
record: (request) => Effect.sync(() => {
|
|
150
|
+
if (request.policy.scope !== "inputs" || !request.trace || !options.privateKey || request.workspace.kind !== "local") return;
|
|
151
|
+
const evidence = traceRun(request.workspace.cwd, request.trace.task);
|
|
152
|
+
if (!evidence) return;
|
|
153
|
+
const signature = Buffer.from(sign(null, Buffer.from(canonical(evidence)), options.privateKey)).toString("base64url");
|
|
154
|
+
const key = inputEvidenceKey(request);
|
|
155
|
+
writeInputEvidenceRecords(options, key, [
|
|
156
|
+
{ evidence, signature },
|
|
157
|
+
...readInputEvidenceRecords(options, key).filter((record) => canonical(record.evidence) !== canonical(evidence))
|
|
158
|
+
].slice(0, maximumRecords));
|
|
159
|
+
})
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
export {
|
|
163
|
+
inputEvidenceKey,
|
|
164
|
+
canonical,
|
|
165
|
+
matchesInputEvidence,
|
|
166
|
+
readInputEvidenceRecords,
|
|
167
|
+
writeInputEvidenceRecords,
|
|
168
|
+
inputEvidenceCheckCache
|
|
169
|
+
};
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import {
|
|
2
|
+
inputEvidenceCheckCache
|
|
3
|
+
} from "./chunk-QRAH3KJT.js";
|
|
1
4
|
import {
|
|
2
5
|
ApprovalError,
|
|
3
6
|
CommandCheckpointError,
|
|
@@ -237,10 +240,10 @@ effect-ci oidc -- <deploy command> Deploy using temporary creden
|
|
|
237
240
|
try {
|
|
238
241
|
const env = { ...process.env, CLOUDFLARE_API_TOKEN: credential.token, CLOUDFLARE_ACCOUNT_ID: credential.accountId };
|
|
239
242
|
delete env.EFFECT_CI_OIDC_TOKEN;
|
|
240
|
-
process.exitCode = await new Promise((
|
|
243
|
+
process.exitCode = await new Promise((resolve4, reject) => {
|
|
241
244
|
const child = spawn(command[0], command.slice(1), { cwd, env, stdio: "inherit" });
|
|
242
245
|
child.on("error", reject);
|
|
243
|
-
child.on("exit", (code) =>
|
|
246
|
+
child.on("exit", (code) => resolve4(code ?? 1));
|
|
244
247
|
});
|
|
245
248
|
} finally {
|
|
246
249
|
const revoked = await fetch(`${issuer}/revoke`, { method: "POST", headers: { authorization: `Bearer ${credential.receipt}` }, redirect: "error", signal: AbortSignal.timeout(15e3) });
|
|
@@ -298,6 +301,15 @@ var setupArtifactsRemote = (root, name, repo, host, branch, log) => {
|
|
|
298
301
|
remote = cf("artifacts", "namespaces", "repos", "create", host.namespace, "--name", repo, "--default-branch", branch).remote;
|
|
299
302
|
log(`Created Artifacts repository ${host.namespace}/${repo}`);
|
|
300
303
|
}
|
|
304
|
+
if (host.queue) subscribeToQueue(host.namespace, host.queue, repo, log);
|
|
305
|
+
execFileSync3("git", ["remote", "add", name, remote], { cwd: root });
|
|
306
|
+
log(`Added Git remote ${name} \u2192 ${remote}`);
|
|
307
|
+
const match = artifactsRemote.exec(remote);
|
|
308
|
+
if (!match) throw new Error("Artifacts returned an unexpected remote URL");
|
|
309
|
+
return { remote, namespace: match[1], repo: match[2] };
|
|
310
|
+
};
|
|
311
|
+
var subscribeToQueue = (namespace, queueName, repo, log) => {
|
|
312
|
+
const host = { namespace, queue: queueName };
|
|
301
313
|
const queue = cf("queues", "list").find((entry) => entry.queue_name === host.queue);
|
|
302
314
|
if (!queue) throw new Error(`Queue ${host.queue} not found; deploy the host first`);
|
|
303
315
|
const subscription = `${host.queue}-${repo}`.slice(0, 64);
|
|
@@ -313,11 +325,6 @@ var setupArtifactsRemote = (root, name, repo, host, branch, log) => {
|
|
|
313
325
|
}));
|
|
314
326
|
log(`Subscribed ${host.namespace}/${repo} pushes to ${host.queue}`);
|
|
315
327
|
}
|
|
316
|
-
execFileSync3("git", ["remote", "add", name, remote], { cwd: root });
|
|
317
|
-
log(`Added Git remote ${name} \u2192 ${remote}`);
|
|
318
|
-
const match = artifactsRemote.exec(remote);
|
|
319
|
-
if (!match) throw new Error("Artifacts returned an unexpected remote URL");
|
|
320
|
-
return { remote, namespace: match[1], repo: match[2] };
|
|
321
328
|
};
|
|
322
329
|
var pushToArtifacts = (root, target, refspecs, token, quiet = false) => spawnSync("git", ["push", ...quiet ? ["--quiet"] : [], target.remote, ...[refspecs].flat()], {
|
|
323
330
|
cwd: root,
|
|
@@ -373,20 +380,31 @@ var vitePlusAvailable = (cwd) => {
|
|
|
373
380
|
}
|
|
374
381
|
};
|
|
375
382
|
|
|
383
|
+
// ../cli/src/check-evidence.ts
|
|
384
|
+
import { readFileSync as readFileSync3 } from "node:fs";
|
|
385
|
+
import { resolve } from "node:path";
|
|
386
|
+
var pem = (root, value) => !value ? void 0 : value.includes("-----BEGIN ") ? value : readFileSync3(resolve(root, value), "utf8");
|
|
387
|
+
var environmentCheckCache = (root, env = process.env) => {
|
|
388
|
+
const publicKey = pem(root, env.EFFECT_CI_CHECK_PUBLIC_KEY);
|
|
389
|
+
if (!publicKey) return void 0;
|
|
390
|
+
const privateKey = pem(root, env.EFFECT_CI_CHECK_PRIVATE_KEY);
|
|
391
|
+
return inputEvidenceCheckCache({ cwd: root, publicKey, ...privateKey ? { privateKey } : {} });
|
|
392
|
+
};
|
|
393
|
+
|
|
376
394
|
// ../cli/src/index.ts
|
|
377
|
-
import { existsSync as existsSync6, lstatSync as lstatSync4, mkdirSync as mkdirSync3, readFileSync as
|
|
395
|
+
import { existsSync as existsSync6, lstatSync as lstatSync4, mkdirSync as mkdirSync3, readFileSync as readFileSync7, realpathSync, writeFileSync as writeFileSync3 } from "node:fs";
|
|
378
396
|
import { execFileSync as execFileSync5 } from "node:child_process";
|
|
379
|
-
import { basename, dirname as dirname4, join as join6, relative, resolve as
|
|
397
|
+
import { basename, dirname as dirname4, join as join6, relative, resolve as resolve3 } from "node:path";
|
|
380
398
|
import { pathToFileURL } from "node:url";
|
|
381
399
|
import { parseArgs as parseArgs2, parseEnv as parseEnv3 } from "node:util";
|
|
382
400
|
|
|
383
401
|
// ../cli/src/project-env.ts
|
|
384
|
-
import { existsSync as existsSync3, readFileSync as
|
|
385
|
-
import { dirname as dirname2, join as join3, resolve } from "node:path";
|
|
402
|
+
import { existsSync as existsSync3, readFileSync as readFileSync4 } from "node:fs";
|
|
403
|
+
import { dirname as dirname2, join as join3, resolve as resolve2 } from "node:path";
|
|
386
404
|
import { parseEnv } from "node:util";
|
|
387
405
|
function projectEnvironment(cwd) {
|
|
388
406
|
const directories = [];
|
|
389
|
-
for (let directory =
|
|
407
|
+
for (let directory = resolve2(cwd); ; directory = dirname2(directory)) {
|
|
390
408
|
directories.unshift(directory);
|
|
391
409
|
if (existsSync3(join3(directory, ".git")) || dirname2(directory) === directory) break;
|
|
392
410
|
}
|
|
@@ -394,7 +412,7 @@ function projectEnvironment(cwd) {
|
|
|
394
412
|
for (const directory of directories) {
|
|
395
413
|
for (const name of [".env", ".env.local"]) {
|
|
396
414
|
const path = join3(directory, name);
|
|
397
|
-
if (existsSync3(path)) Object.assign(settings, parseEnv(
|
|
415
|
+
if (existsSync3(path)) Object.assign(settings, parseEnv(readFileSync4(path, "utf8")));
|
|
398
416
|
}
|
|
399
417
|
}
|
|
400
418
|
if (settings.EFFECT_CI_PUBLIC_URL) settings.EFFECT_CI_REMOTE_URL ??= settings.EFFECT_CI_PUBLIC_URL;
|
|
@@ -552,7 +570,7 @@ function makeLocalProjectChecks(options = {}) {
|
|
|
552
570
|
|
|
553
571
|
// ../cli/src/login.ts
|
|
554
572
|
import { spawnSync as spawnSync2 } from "node:child_process";
|
|
555
|
-
import { chmodSync, existsSync as existsSync4, lstatSync as lstatSync2, mkdirSync as mkdirSync2, readFileSync as
|
|
573
|
+
import { chmodSync, existsSync as existsSync4, lstatSync as lstatSync2, mkdirSync as mkdirSync2, readFileSync as readFileSync5, writeFileSync as writeFileSync2 } from "node:fs";
|
|
556
574
|
import { homedir as homedir2 } from "node:os";
|
|
557
575
|
import { dirname as dirname3, join as join4 } from "node:path";
|
|
558
576
|
var userConfigPath = () => process.env.EFFECT_CI_CONFIG || join4(homedir2(), ".config", "effect-ci", "config.json");
|
|
@@ -560,7 +578,7 @@ var readUserConfig = (path = userConfigPath()) => {
|
|
|
560
578
|
if (!existsSync4(path)) return {};
|
|
561
579
|
const file = lstatSync2(path);
|
|
562
580
|
if (!file.isFile() || file.isSymbolicLink() || file.size > 8192) throw new Error(`Invalid Effect CI config: ${path}`);
|
|
563
|
-
const value = JSON.parse(
|
|
581
|
+
const value = JSON.parse(readFileSync5(path, "utf8"));
|
|
564
582
|
if (value.version !== 1) throw new Error(`Invalid Effect CI config: ${path}`);
|
|
565
583
|
return typeof value.remoteUrl === "string" ? { remoteUrl: remoteOrigin(value.remoteUrl) } : {};
|
|
566
584
|
};
|
|
@@ -625,7 +643,7 @@ setting CF_ACCESS_CLIENT_ID and CF_ACCESS_CLIENT_SECRET (an Access service token
|
|
|
625
643
|
};
|
|
626
644
|
|
|
627
645
|
// ../cli/src/remote-config.ts
|
|
628
|
-
import { existsSync as existsSync5, lstatSync as lstatSync3, readFileSync as
|
|
646
|
+
import { existsSync as existsSync5, lstatSync as lstatSync3, readFileSync as readFileSync6 } from "node:fs";
|
|
629
647
|
import { join as join5 } from "node:path";
|
|
630
648
|
import { parseEnv as parseEnv2 } from "node:util";
|
|
631
649
|
var readProjectRemote = (root) => {
|
|
@@ -635,7 +653,7 @@ var readProjectRemote = (root) => {
|
|
|
635
653
|
const stat = lstatSync3(path);
|
|
636
654
|
if (!stat.isFile() || stat.isSymbolicLink() || stat.size > 65536)
|
|
637
655
|
throw new Error("Invalid remote configuration file");
|
|
638
|
-
const values2 = parseEnv2(
|
|
656
|
+
const values2 = parseEnv2(readFileSync6(path, "utf8"));
|
|
639
657
|
return values2;
|
|
640
658
|
};
|
|
641
659
|
const shared = read(".env"), local = read(".env.local");
|
|
@@ -654,7 +672,7 @@ var readProjectOidc = (root) => {
|
|
|
654
672
|
if (!existsSync5(path)) return void 0;
|
|
655
673
|
const file = lstatSync3(path);
|
|
656
674
|
if (!file.isFile() || file.isSymbolicLink() || file.size > 8192) throw new Error("Invalid OIDC configuration file");
|
|
657
|
-
return JSON.parse(
|
|
675
|
+
return JSON.parse(readFileSync6(path, "utf8"));
|
|
658
676
|
};
|
|
659
677
|
|
|
660
678
|
// ../cli/src/remote-diagnostics.ts
|
|
@@ -1110,7 +1128,7 @@ var followRemoteRun = async (connection, format, run) => {
|
|
|
1110
1128
|
);
|
|
1111
1129
|
}
|
|
1112
1130
|
if (format === "text") console.log("Remote logs disconnected; reconnecting to the same Workflow\u2026");
|
|
1113
|
-
await new Promise((
|
|
1131
|
+
await new Promise((resolve4) => setTimeout(resolve4, Math.min(1e3 * interruptions, 5e3)));
|
|
1114
1132
|
}
|
|
1115
1133
|
const terminal = events.at(-1);
|
|
1116
1134
|
if (terminal?.type === "workflow_errored" || terminal?.type === "workflow_terminated") {
|
|
@@ -1179,11 +1197,11 @@ var runPush = async (input, cwd, detected) => {
|
|
|
1179
1197
|
signal: AbortSignal.timeout(15e3)
|
|
1180
1198
|
}).catch(() => void 0);
|
|
1181
1199
|
const host = response?.ok ? (await response.json()).artifacts : void 0;
|
|
1182
|
-
if (typeof host?.namespace !== "string" || typeof host.queue !== "string")
|
|
1200
|
+
if (typeof host?.namespace !== "string" || host.queue !== void 0 && typeof host.queue !== "string")
|
|
1183
1201
|
throw new CliFailure("CI_REMOTE_UNAVAILABLE", ExitCode.providerUnavailable, "This host does not accept Artifacts pushes. Update the host, or add an Artifacts remote yourself.");
|
|
1184
1202
|
const repo = basename(root).toLowerCase().replace(/[^a-z0-9_.-]+/g, "-").replace(/^[^a-z0-9]+/, "").slice(0, 100) || "project";
|
|
1185
1203
|
try {
|
|
1186
|
-
target = setupArtifactsRemote(root, name, repo, { namespace: host.namespace, queue: host.queue }, branch, log);
|
|
1204
|
+
target = setupArtifactsRemote(root, name, repo, { namespace: host.namespace, ...typeof host.queue === "string" ? { queue: host.queue } : {} }, branch, log);
|
|
1187
1205
|
} catch (error) {
|
|
1188
1206
|
throw new CliFailure(
|
|
1189
1207
|
"CI_REMOTE_AUTH_REQUIRED",
|
|
@@ -1224,7 +1242,7 @@ var runPush = async (input, cwd, detected) => {
|
|
|
1224
1242
|
if (response?.status === 400)
|
|
1225
1243
|
throw new CliFailure("CI_REMOTE_FAILED", ExitCode.providerUnavailable, `The push succeeded, but the host could not start its run: ${detail}`, { instanceId });
|
|
1226
1244
|
if (response?.ok || response?.status === 404 || attempt === 4) break;
|
|
1227
|
-
await new Promise((
|
|
1245
|
+
await new Promise((resolve4) => setTimeout(resolve4, 1e3 * (attempt + 1)));
|
|
1228
1246
|
}
|
|
1229
1247
|
const deadline = Date.now() + 6e4;
|
|
1230
1248
|
while (true) {
|
|
@@ -1245,7 +1263,7 @@ var runPush = async (input, cwd, detected) => {
|
|
|
1245
1263
|
`The push succeeded, but no run started for ${revision} within 60 seconds. Check the Artifacts event subscription for ${target.namespace}/${target.repo}.`,
|
|
1246
1264
|
{ instanceId }
|
|
1247
1265
|
);
|
|
1248
|
-
await new Promise((
|
|
1266
|
+
await new Promise((resolve4) => setTimeout(resolve4, 1e3));
|
|
1249
1267
|
}
|
|
1250
1268
|
if (format === "text") console.log(`Remote Workflow ${instanceId}`);
|
|
1251
1269
|
const result = await followRemoteRun(connection, format, run);
|
|
@@ -1406,7 +1424,7 @@ var workflowNames = [
|
|
|
1406
1424
|
"ci.mjs"
|
|
1407
1425
|
];
|
|
1408
1426
|
var findWorkflow = (cwd) => {
|
|
1409
|
-
let directory =
|
|
1427
|
+
let directory = resolve3(cwd);
|
|
1410
1428
|
while (true) {
|
|
1411
1429
|
for (const name of workflowNames) {
|
|
1412
1430
|
const candidate = join6(directory, ".cloudflare", "ci", name);
|
|
@@ -1450,12 +1468,12 @@ var extractWorkflow = (args, cwd) => {
|
|
|
1450
1468
|
remaining.splice(positional, 1);
|
|
1451
1469
|
}
|
|
1452
1470
|
}
|
|
1453
|
-
const path = explicit ?
|
|
1471
|
+
const path = explicit ? resolve3(cwd, explicit) : findWorkflow(cwd);
|
|
1454
1472
|
if (!path || !existsSync6(path)) {
|
|
1455
1473
|
throw new CliFailure(
|
|
1456
1474
|
"CI_WORKFLOW_NOT_FOUND",
|
|
1457
1475
|
ExitCode.usage,
|
|
1458
|
-
explicit ? `Workflow not found: ${
|
|
1476
|
+
explicit ? `Workflow not found: ${resolve3(cwd, explicit)}` : `No .cloudflare/ci/workflow.ts found from ${resolve3(cwd)}`
|
|
1459
1477
|
);
|
|
1460
1478
|
}
|
|
1461
1479
|
return { args: remaining, path };
|
|
@@ -1469,7 +1487,7 @@ var loadProgram = async (args = process.argv.slice(2), cwd = process.cwd()) => {
|
|
|
1469
1487
|
program: inferJavaScriptProgram(selected.path)
|
|
1470
1488
|
};
|
|
1471
1489
|
}
|
|
1472
|
-
if (basename(selected.path).startsWith("ci.") &&
|
|
1490
|
+
if (basename(selected.path).startsWith("ci.") && readFileSync7(selected.path, "utf8").trim() === "") {
|
|
1473
1491
|
return {
|
|
1474
1492
|
args: selected.args,
|
|
1475
1493
|
path: selected.path,
|
|
@@ -1511,7 +1529,7 @@ var inferJavaScriptProgram = (root) => {
|
|
|
1511
1529
|
`Zero-config CI requires a package.json at ${manifestPath}`
|
|
1512
1530
|
);
|
|
1513
1531
|
}
|
|
1514
|
-
const manifest = JSON.parse(
|
|
1532
|
+
const manifest = JSON.parse(readFileSync7(manifestPath, "utf8"));
|
|
1515
1533
|
let tasks = { names: [], dependencies: {} };
|
|
1516
1534
|
if (manifest.dependencies?.["vite-plus"] || manifest.devDependencies?.["vite-plus"]) {
|
|
1517
1535
|
try {
|
|
@@ -1544,7 +1562,7 @@ var initializeJavaScriptProject = (args, cwd) => {
|
|
|
1544
1562
|
const invocation = parseInvocation(args, void 0, cwd);
|
|
1545
1563
|
if (invocation.help || invocation.command !== "run" || invocation.location !== "local") return void 0;
|
|
1546
1564
|
requireAction(invocation.targets);
|
|
1547
|
-
const program = inferJavaScriptProgram(
|
|
1565
|
+
const program = inferJavaScriptProgram(resolve3(cwd));
|
|
1548
1566
|
selectedWorkflow(program, invocation.targets);
|
|
1549
1567
|
for (const directory of [join6(cwd, ".cloudflare"), join6(cwd, ".cloudflare", "ci")]) {
|
|
1550
1568
|
if (existsSync6(directory)) {
|
|
@@ -1568,7 +1586,7 @@ var printJson = (value) => {
|
|
|
1568
1586
|
process.stdout.write(`${JSON.stringify(value, null, 2)}
|
|
1569
1587
|
`);
|
|
1570
1588
|
};
|
|
1571
|
-
var projectRoot = (workflowPath) => basename(dirname4(workflowPath)) === "ci" && basename(dirname4(dirname4(workflowPath))) === ".cloudflare" ?
|
|
1589
|
+
var projectRoot = (workflowPath) => basename(dirname4(workflowPath)) === "ci" && basename(dirname4(dirname4(workflowPath))) === ".cloudflare" ? resolve3(dirname4(workflowPath), "../..") : dirname4(workflowPath);
|
|
1572
1590
|
var defaultLocalOptions = (workflowPath) => {
|
|
1573
1591
|
const event = process.env.EFFECT_CI_EVENT ?? process.env.GITHUB_EVENT_NAME;
|
|
1574
1592
|
const revision = process.env.EFFECT_CI_REVISION ?? process.env.GITHUB_SHA;
|
|
@@ -1578,13 +1596,15 @@ var defaultLocalOptions = (workflowPath) => {
|
|
|
1578
1596
|
try {
|
|
1579
1597
|
const path = process.env.GITHUB_EVENT_PATH;
|
|
1580
1598
|
if (path && lstatSync4(path).isFile() && lstatSync4(path).size <= 4194304)
|
|
1581
|
-
payload = JSON.parse(
|
|
1599
|
+
payload = JSON.parse(readFileSync7(path, "utf8"));
|
|
1582
1600
|
} catch {
|
|
1583
1601
|
}
|
|
1584
1602
|
const comparison = process.env.EFFECT_CI_BASE_REVISION ? { base: process.env.EFFECT_CI_BASE_REVISION, ...revision ? { head: revision } : {} } : githubSourceComparison(event ?? "workflow_dispatch", payload, revision);
|
|
1585
1603
|
const approval = decision === "approved" || decision === "rejected" ? { request: () => Effect2.succeed({ decision }) } : void 0;
|
|
1604
|
+
const checkCache = environmentCheckCache(projectRoot(workflowPath));
|
|
1586
1605
|
return {
|
|
1587
1606
|
...approval ? { approval } : {},
|
|
1607
|
+
...checkCache ? { checkCache } : {},
|
|
1588
1608
|
env: process.env.NODE_ENV ?? (process.env.CI ? "test" : "development"),
|
|
1589
1609
|
event: {
|
|
1590
1610
|
type: event ?? "workflow_dispatch",
|
|
@@ -1706,7 +1726,7 @@ var list = (program, format) => {
|
|
|
1706
1726
|
if (!program.requiresTarget) console.log(` effect-ci run (whole workflow)`);
|
|
1707
1727
|
for (const target of targets) console.log(` effect-ci run ${target}`);
|
|
1708
1728
|
};
|
|
1709
|
-
var main = async (program, args = process.argv.slice(2), workflowPath =
|
|
1729
|
+
var main = async (program, args = process.argv.slice(2), workflowPath = resolve3(process.cwd(), ".cloudflare/ci/workflow.ts")) => {
|
|
1710
1730
|
let format = detectedFormat();
|
|
1711
1731
|
const logs = [];
|
|
1712
1732
|
try {
|
|
@@ -1866,7 +1886,7 @@ var runCli = async (args = process.argv.slice(2), cwd = process.cwd()) => {
|
|
|
1866
1886
|
}
|
|
1867
1887
|
let settings;
|
|
1868
1888
|
try {
|
|
1869
|
-
settings = parseEnv3(
|
|
1889
|
+
settings = parseEnv3(readFileSync7(resolve3(cwd, path), "utf8"));
|
|
1870
1890
|
} catch {
|
|
1871
1891
|
throw new CliFailure("CI_USAGE_ERROR", ExitCode.usage, `Cannot read environment file: ${path}`);
|
|
1872
1892
|
}
|
|
@@ -1907,7 +1927,7 @@ var runCli = async (args = process.argv.slice(2), cwd = process.cwd()) => {
|
|
|
1907
1927
|
{ workflow: workflow("hosted", function* () {
|
|
1908
1928
|
}) },
|
|
1909
1929
|
args,
|
|
1910
|
-
|
|
1930
|
+
resolve3(cwd, ".cloudflare/ci/workflow.ts")
|
|
1911
1931
|
);
|
|
1912
1932
|
return;
|
|
1913
1933
|
}
|
|
@@ -1920,7 +1940,7 @@ var runCli = async (args = process.argv.slice(2), cwd = process.cwd()) => {
|
|
|
1920
1940
|
}, cwd);
|
|
1921
1941
|
if (!invocation.help && invocation.command === "run" && !invocation.targets.length) {
|
|
1922
1942
|
const path = findWorkflow(cwd);
|
|
1923
|
-
if (!path || basename(path).startsWith("ci.") &&
|
|
1943
|
+
if (!path || basename(path).startsWith("ci.") && readFileSync7(path, "utf8").trim() === "") {
|
|
1924
1944
|
requireAction(invocation.targets);
|
|
1925
1945
|
}
|
|
1926
1946
|
}
|
|
@@ -1929,7 +1949,7 @@ var runCli = async (args = process.argv.slice(2), cwd = process.cwd()) => {
|
|
|
1929
1949
|
{ workflow: workflow("hosted", function* () {
|
|
1930
1950
|
}) },
|
|
1931
1951
|
args,
|
|
1932
|
-
|
|
1952
|
+
resolve3(cwd, ".cloudflare/ci/workflow.ts")
|
|
1933
1953
|
);
|
|
1934
1954
|
return;
|
|
1935
1955
|
}
|
|
@@ -1941,7 +1961,7 @@ var runCli = async (args = process.argv.slice(2), cwd = process.cwd()) => {
|
|
|
1941
1961
|
if (invocation.location === "local" && (invocation.help || invocation.command !== "run")) {
|
|
1942
1962
|
let program;
|
|
1943
1963
|
try {
|
|
1944
|
-
program = inferJavaScriptProgram(
|
|
1964
|
+
program = inferJavaScriptProgram(resolve3(cwd));
|
|
1945
1965
|
} catch (error) {
|
|
1946
1966
|
if (invocation.help && error instanceof CliFailure && ["CI_ZERO_CONFIG_UNSUPPORTED", "CI_ZERO_CONFIG_NO_TASKS"].includes(error.code)) {
|
|
1947
1967
|
console.log(help("no workflow selected"));
|
|
@@ -1950,7 +1970,7 @@ var runCli = async (args = process.argv.slice(2), cwd = process.cwd()) => {
|
|
|
1950
1970
|
}
|
|
1951
1971
|
throw error;
|
|
1952
1972
|
}
|
|
1953
|
-
process.exitCode = await main(program, args,
|
|
1973
|
+
process.exitCode = await main(program, args, resolve3(cwd, ".cloudflare/ci/ci.ts"));
|
|
1954
1974
|
return;
|
|
1955
1975
|
}
|
|
1956
1976
|
}
|
package/dist/effect-ci.js
CHANGED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import {
|
|
2
|
+
canonical,
|
|
3
|
+
inputEvidenceCheckCache,
|
|
4
|
+
inputEvidenceKey,
|
|
5
|
+
matchesInputEvidence,
|
|
6
|
+
readInputEvidenceRecords,
|
|
7
|
+
writeInputEvidenceRecords
|
|
8
|
+
} from "./chunks/chunk-QRAH3KJT.js";
|
|
9
|
+
import "./chunks/chunk-Q5USMIJ3.js";
|
|
10
|
+
export {
|
|
11
|
+
canonical,
|
|
12
|
+
inputEvidenceCheckCache,
|
|
13
|
+
inputEvidenceKey,
|
|
14
|
+
matchesInputEvidence,
|
|
15
|
+
readInputEvidenceRecords,
|
|
16
|
+
writeInputEvidenceRecords
|
|
17
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { CheckCache, CheckCacheRequest } from "./index.js";
|
|
2
|
+
/** What a passing run read, as Vite+ traced it, with content digests Effect CI computes. */
|
|
3
|
+
export type PathEvidence = {
|
|
4
|
+
readonly type: "file";
|
|
5
|
+
readonly sha256: string;
|
|
6
|
+
readonly mayBeMissing?: true;
|
|
7
|
+
} | {
|
|
8
|
+
readonly type: "dir";
|
|
9
|
+
readonly entries?: ReadonlyArray<string>;
|
|
10
|
+
readonly mayBeMissing?: true;
|
|
11
|
+
} | {
|
|
12
|
+
readonly type: "missing";
|
|
13
|
+
};
|
|
14
|
+
export interface InputEvidence {
|
|
15
|
+
/** The Vite+ workspace root, relative to the check's working directory. */
|
|
16
|
+
readonly root: string;
|
|
17
|
+
readonly inputs: Readonly<Record<string, PathEvidence>>;
|
|
18
|
+
/** SHA-256 of each env var value the run's cache key includes. */
|
|
19
|
+
readonly env: Readonly<Record<string, string | null>>;
|
|
20
|
+
}
|
|
21
|
+
export interface SignedInputEvidence {
|
|
22
|
+
readonly evidence: InputEvidence;
|
|
23
|
+
readonly signature: string;
|
|
24
|
+
}
|
|
25
|
+
export interface InputEvidenceCheckCacheOptions {
|
|
26
|
+
/** A Git checkout whose notes ref stores the evidence. Push the ref to share it. */
|
|
27
|
+
readonly cwd: string;
|
|
28
|
+
readonly privateKey?: string;
|
|
29
|
+
readonly publicKey: string;
|
|
30
|
+
readonly ref?: string;
|
|
31
|
+
}
|
|
32
|
+
/** Evidence is keyed by what ran, never by commit, so it survives rebases and squashes. */
|
|
33
|
+
export declare const inputEvidenceKey: (request: CheckCacheRequest) => string;
|
|
34
|
+
export declare const canonical: (evidence: InputEvidence) => string;
|
|
35
|
+
/** Whether the workspace still has every input exactly as the passing run read it. */
|
|
36
|
+
export declare const matchesInputEvidence: (cwd: string, evidence: InputEvidence) => boolean;
|
|
37
|
+
/** The signed records stored for one evidence key, newest first. */
|
|
38
|
+
export declare const readInputEvidenceRecords: (options: Pick<InputEvidenceCheckCacheOptions, "cwd" | "ref">, key: string) => ReadonlyArray<SignedInputEvidence>;
|
|
39
|
+
/** Replace the records for one evidence key. Records go on stdin, never argv: a traced
|
|
40
|
+
* `node_modules` makes each one hundreds of KB, past Linux's 128 KB per-argument limit
|
|
41
|
+
* and, after a few records, macOS's 1 MB ARG_MAX. */
|
|
42
|
+
export declare const writeInputEvidenceRecords: (options: Pick<InputEvidenceCheckCacheOptions, "cwd" | "ref">, key: string, records: ReadonlyArray<SignedInputEvidence>) => void;
|
|
43
|
+
/**
|
|
44
|
+
* Reuses a passing Vite+ check when every file and env var it read is unchanged, on any
|
|
45
|
+
* commit. A trusted writer signs what Vite+ traced; a reader recomputes each digest.
|
|
46
|
+
* Commands without a Vite+ trace and checks reused by commit always run.
|
|
47
|
+
*/
|
|
48
|
+
export declare const inputEvidenceCheckCache: (options: InputEvidenceCheckCacheOptions) => CheckCache;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "effect-ci",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Effect CI: typed CI workflows you run locally, in agents, or on your own Cloudflare host",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -41,6 +41,10 @@
|
|
|
41
41
|
"types": "./dist/types/vite-plus.d.ts",
|
|
42
42
|
"default": "./dist/vite-plus.js"
|
|
43
43
|
},
|
|
44
|
+
"./input-evidence": {
|
|
45
|
+
"types": "./dist/types/input-evidence.d.ts",
|
|
46
|
+
"default": "./dist/input-evidence.js"
|
|
47
|
+
},
|
|
44
48
|
"./package.json": "./package.json"
|
|
45
49
|
},
|
|
46
50
|
"files": [
|