@cnc-tools/storm 0.8.0 → 0.9.0
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/dist/build-info.js +1 -1
- package/dist/commands/exec/command.d.ts +32 -0
- package/dist/commands/exec/metadata.js +1 -1
- package/dist/commands/exec/outcomes.d.ts +67 -0
- package/dist/commands/exec/outcomes.js +50 -0
- package/dist/commands/exec/run-command.d.ts +17 -11
- package/dist/commands/exec/run-command.js +33 -16
- package/dist/commands/runs/facts.d.ts +2 -2
- package/dist/commands/runs/facts.js +1 -1
- package/dist/commands/runs/list/outcomes.js +1 -1
- package/dist/commands/runs/logs/outcomes.js +1 -1
- package/dist/commands/runs/show/outcomes.js +3 -3
- package/dist/commands/vitest/command.d.ts +32 -0
- package/dist/commands/vitest/outcomes.d.ts +16 -0
- package/dist/core/run.d.ts +6 -1
- package/dist/core/run.js +1 -1
- package/dist/resources/testserver/commands/create/command.d.ts +6 -4
- package/dist/resources/testserver/commands/create/command.js +15 -6
- package/dist/resources/testserver/events.d.ts +4 -2
- package/dist/resources/testserver/pool/create.d.ts +4 -1
- package/dist/resources/testserver/pool/create.js +3 -1
- package/dist/resources/testserver/pool/gateways.d.ts +6 -0
- package/dist/resources/testserver/pool/live/pool-records.js +6 -2
- package/dist/resources/testserver/pool/pull-request.d.ts +18 -11
- package/dist/resources/testserver/pool/pull-request.js +43 -10
- package/dist/resources/testserver/presentation.js +2 -1
- package/dist/resources/testserver/provider.js +15 -7
- package/dist/runner/index.d.ts +2 -1
- package/dist/runner/index.js +1 -0
- package/dist/runner/prepare.d.ts +7 -6
- package/dist/runner/prepare.js +1 -1
- package/dist/runner/ready.d.ts +6 -0
- package/dist/runner/ready.js +33 -5
- package/dist/runner/recipe.d.ts +33 -6
- package/dist/runner/recipe.js +150 -22
- package/dist/runner/secrets.d.ts +42 -0
- package/dist/runner/secrets.js +44 -0
- package/dist/runner/snapshot-build.d.ts +5 -2
- package/dist/runner/snapshot-build.js +12 -5
- package/dist/runner/snapshot-cache.d.ts +3 -3
- package/dist/runner/snapshot-cache.js +2 -2
- package/dist/runner/snapshot-key.d.ts +19 -12
- package/dist/runner/snapshot-key.js +25 -16
- package/dist/runner/snapshot-save.d.ts +5 -3
- package/dist/runner/snapshot-save.js +7 -5
- package/dist/runner/steps.d.ts +6 -1
- package/dist/runner/steps.js +5 -2
- package/package.json +2 -3
- package/skills/overview.md +1 -0
- package/skills/testserver-builds.md +4 -2
package/dist/runner/recipe.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// evaluate the parts a recipe may give as functions, and check what they return.
|
|
4
4
|
import { parseKeepTime, parseTtl } from "../time/index.js";
|
|
5
5
|
import { RUN_PAYLOAD_VARIABLE } from "../sdk/index.js";
|
|
6
|
+
import { STEP_ENV } from "./steps.js";
|
|
6
7
|
/** The defaults of a recipe's optional keys. */
|
|
7
8
|
export const RECIPE_DEFAULTS = {
|
|
8
9
|
cwd: ".",
|
|
@@ -18,16 +19,37 @@ const RECIPE_KEYS = new Set([
|
|
|
18
19
|
"cwd",
|
|
19
20
|
"vcpus",
|
|
20
21
|
"env",
|
|
22
|
+
"secrets",
|
|
21
23
|
"timeout",
|
|
22
24
|
"keepSandbox",
|
|
23
25
|
"baseRefs",
|
|
24
26
|
"region",
|
|
25
27
|
"runtime",
|
|
26
28
|
]);
|
|
27
|
-
const SNAPSHOT_KEYS = new Set(["vcpus", "summary", "toolchains", "
|
|
29
|
+
const SNAPSHOT_KEYS = new Set(["vcpus", "summary", "toolchains", "prebuild"]);
|
|
28
30
|
const RUN_KEYS = new Set(["install", "build"]);
|
|
29
|
-
const STEP_KEYS = new Set(["label", "script"]);
|
|
31
|
+
const STEP_KEYS = new Set(["label", "script", "secrets"]);
|
|
30
32
|
const NAME_PATTERN = /^[a-z0-9][a-z0-9-]*$/;
|
|
33
|
+
const VARIABLE_PATTERN = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
34
|
+
/**
|
|
35
|
+
* Names a runner secret can't take because they change how a step's shell or programs run. A guard against a
|
|
36
|
+
* mistake, such as naming `PATH`, not a security boundary: a step's script can set any variable itself.
|
|
37
|
+
*/
|
|
38
|
+
const RESERVED_SECRET_NAMES = new Set([
|
|
39
|
+
"PATH",
|
|
40
|
+
"HOME",
|
|
41
|
+
"USER",
|
|
42
|
+
"LOGNAME",
|
|
43
|
+
"SHELL",
|
|
44
|
+
"PWD",
|
|
45
|
+
"TMPDIR",
|
|
46
|
+
"BASH_ENV",
|
|
47
|
+
"ENV",
|
|
48
|
+
"IFS",
|
|
49
|
+
"NODE_OPTIONS",
|
|
50
|
+
]);
|
|
51
|
+
/** Prefixes of the dynamic loader's variables, which a runner secret's name can't start with. */
|
|
52
|
+
const RESERVED_SECRET_PREFIXES = ["LD_", "DYLD_"];
|
|
31
53
|
/**
|
|
32
54
|
* Checks a recipe against its static rules: the keys it may hold and each value's shape. Functions are checked only
|
|
33
55
|
* for being functions; `resolveSteps` and `resolveVcpus` check what they return. Every problem is reported.
|
|
@@ -43,8 +65,9 @@ export function checkRecipe(value) {
|
|
|
43
65
|
const name = value["name"];
|
|
44
66
|
if (typeof name !== "string" || !NAME_PATTERN.test(name))
|
|
45
67
|
report(["name"], `must be lowercase letters, digits and dashes, starting with a letter or digit, not ${describeRecipeValue(name)}`);
|
|
46
|
-
const
|
|
47
|
-
const
|
|
68
|
+
const declared = declaredSecrets(value["secrets"]);
|
|
69
|
+
const snapshot = checkSnapshot(value["snapshot"], declared, report);
|
|
70
|
+
const run = checkRun(value["run"], declared, report);
|
|
48
71
|
const cwd = orDefault(value["cwd"], RECIPE_DEFAULTS.cwd);
|
|
49
72
|
if (!isRelativePath(cwd))
|
|
50
73
|
report(["cwd"], `must be a path relative to the repository's root, without "..", not ${describeRecipeValue(cwd)}`);
|
|
@@ -52,6 +75,7 @@ export function checkRecipe(value) {
|
|
|
52
75
|
if (typeof vcpus !== "function" && !isPositiveInteger(vcpus))
|
|
53
76
|
report(["vcpus"], `must be a positive whole number, or a function of the run's resources, not ${describeRecipeValue(vcpus)}`);
|
|
54
77
|
const env = checkEnv(value["env"], report);
|
|
78
|
+
const secrets = checkSecrets(value["secrets"], report);
|
|
55
79
|
const timeout = orDefault(value["timeout"], RECIPE_DEFAULTS.timeout);
|
|
56
80
|
const timeoutMinutes = typeof timeout === "string" ? parseTtl(timeout) : undefined;
|
|
57
81
|
if (timeoutMinutes === undefined)
|
|
@@ -71,6 +95,7 @@ export function checkRecipe(value) {
|
|
|
71
95
|
snapshot === undefined ||
|
|
72
96
|
run === undefined ||
|
|
73
97
|
env === undefined ||
|
|
98
|
+
secrets === undefined ||
|
|
74
99
|
baseRefs === undefined ||
|
|
75
100
|
timeoutMinutes === undefined)
|
|
76
101
|
return { ok: false, problems };
|
|
@@ -83,6 +108,7 @@ export function checkRecipe(value) {
|
|
|
83
108
|
cwd: cwd,
|
|
84
109
|
vcpus: vcpus,
|
|
85
110
|
env,
|
|
111
|
+
secrets,
|
|
86
112
|
timeout: timeout,
|
|
87
113
|
timeoutMinutes,
|
|
88
114
|
keepSandboxMinutes,
|
|
@@ -92,9 +118,20 @@ export function checkRecipe(value) {
|
|
|
92
118
|
},
|
|
93
119
|
};
|
|
94
120
|
}
|
|
95
|
-
|
|
121
|
+
/**
|
|
122
|
+
* The names a recipe's `secrets` key declares, for checking the names its static steps give; undefined when the key
|
|
123
|
+
* isn't a list, which `checkSecrets` reports, so no step's name is reported against it.
|
|
124
|
+
*/
|
|
125
|
+
function declaredSecrets(value) {
|
|
126
|
+
if (value === undefined)
|
|
127
|
+
return new Set();
|
|
128
|
+
if (!Array.isArray(value))
|
|
129
|
+
return undefined;
|
|
130
|
+
return new Set(value.filter((name) => typeof name === "string"));
|
|
131
|
+
}
|
|
132
|
+
function checkSnapshot(value, declared, report) {
|
|
96
133
|
if (!isRecord(value)) {
|
|
97
|
-
report(["snapshot"], `must be an object of vcpus, toolchains,
|
|
134
|
+
report(["snapshot"], `must be an object of vcpus, toolchains, prebuild and an optional summary, not ${describeRecipeValue(value)}`);
|
|
98
135
|
return undefined;
|
|
99
136
|
}
|
|
100
137
|
let ok = reportUnknownKeys(value, SNAPSHOT_KEYS, ["snapshot"], "a runner recipe snapshot key", report);
|
|
@@ -108,38 +145,42 @@ function checkSnapshot(value, report) {
|
|
|
108
145
|
report(["snapshot", "summary"], `must be a non-empty string, not ${describeRecipeValue(summary)}`);
|
|
109
146
|
ok = false;
|
|
110
147
|
}
|
|
111
|
-
const toolchains = checkSteps(value["toolchains"], ["snapshot", "toolchains"], report);
|
|
112
|
-
const
|
|
113
|
-
if (!ok || toolchains === undefined ||
|
|
148
|
+
const toolchains = checkSteps(value["toolchains"], ["snapshot", "toolchains"], declared, report);
|
|
149
|
+
const prebuild = checkSteps(value["prebuild"], ["snapshot", "prebuild"], declared, report);
|
|
150
|
+
if (!ok || toolchains === undefined || prebuild === undefined)
|
|
114
151
|
return undefined;
|
|
115
152
|
return {
|
|
116
153
|
vcpus: vcpus,
|
|
117
154
|
...(summary === undefined ? {} : { summary: summary }),
|
|
118
155
|
toolchains,
|
|
119
|
-
|
|
156
|
+
prebuild,
|
|
120
157
|
};
|
|
121
158
|
}
|
|
122
|
-
function checkRun(value, report) {
|
|
159
|
+
function checkRun(value, declared, report) {
|
|
123
160
|
if (!isRecord(value)) {
|
|
124
161
|
report(["run"], `must be an object of install and build steps, not ${describeRecipeValue(value)}`);
|
|
125
162
|
return undefined;
|
|
126
163
|
}
|
|
127
164
|
const ok = reportUnknownKeys(value, RUN_KEYS, ["run"], "a runner recipe run key", report);
|
|
128
|
-
const install = checkStep(value["install"], ["run", "install"], report);
|
|
129
|
-
const build = checkStep(value["build"], ["run", "build"], report);
|
|
165
|
+
const install = checkStep(value["install"], ["run", "install"], declared, report);
|
|
166
|
+
const build = checkStep(value["build"], ["run", "build"], declared, report);
|
|
130
167
|
return ok && install !== undefined && build !== undefined ? { install, build } : undefined;
|
|
131
168
|
}
|
|
132
|
-
function checkSteps(value, path, report) {
|
|
169
|
+
function checkSteps(value, path, declared, report) {
|
|
133
170
|
if (typeof value === "function")
|
|
134
171
|
return value;
|
|
135
172
|
if (!Array.isArray(value)) {
|
|
136
173
|
report(path, `must be a list of steps, or a function that returns one, not ${describeRecipeValue(value)}`);
|
|
137
174
|
return undefined;
|
|
138
175
|
}
|
|
139
|
-
const steps = value.map((step, index) => checkStep(step, [...path, String(index)], report));
|
|
176
|
+
const steps = value.map((step, index) => checkStep(step, [...path, String(index)], declared, report));
|
|
140
177
|
return steps.every((step) => step !== undefined) ? steps : undefined;
|
|
141
178
|
}
|
|
142
|
-
|
|
179
|
+
/**
|
|
180
|
+
* One step: a label, a script, and the runner secrets it gets, each named once and declared (`declared`; unchecked
|
|
181
|
+
* when undefined).
|
|
182
|
+
*/
|
|
183
|
+
function checkStep(value, path, declared, report) {
|
|
143
184
|
if (!isRecord(value)) {
|
|
144
185
|
report(path, `must be a step, { label, script }, not ${describeRecipeValue(value)}`);
|
|
145
186
|
return undefined;
|
|
@@ -155,7 +196,39 @@ function checkStep(value, path, report) {
|
|
|
155
196
|
report([...path, "script"], `must be a non-empty string, not ${describeRecipeValue(script)}`);
|
|
156
197
|
ok = false;
|
|
157
198
|
}
|
|
158
|
-
|
|
199
|
+
const secrets = checkStepSecrets(value["secrets"], [...path, "secrets"], declared, report);
|
|
200
|
+
if (secrets === undefined)
|
|
201
|
+
ok = false;
|
|
202
|
+
return ok && secrets !== undefined ? { label: label, script: script, secrets } : undefined;
|
|
203
|
+
}
|
|
204
|
+
/** A step's `secrets`: a list of names, each declared and none given twice; an empty list when absent. */
|
|
205
|
+
function checkStepSecrets(value, path, declared, report) {
|
|
206
|
+
if (value === undefined)
|
|
207
|
+
return [];
|
|
208
|
+
if (!Array.isArray(value)) {
|
|
209
|
+
report(path, `must be a list of names runner.secrets declares, not ${describeRecipeValue(value)}`);
|
|
210
|
+
return undefined;
|
|
211
|
+
}
|
|
212
|
+
let ok = true;
|
|
213
|
+
const seen = new Set();
|
|
214
|
+
value.forEach((name, index) => {
|
|
215
|
+
const at = [...path, String(index)];
|
|
216
|
+
if (typeof name !== "string") {
|
|
217
|
+
report(at, `must be a name runner.secrets declares, not ${describeRecipeValue(name)}`);
|
|
218
|
+
ok = false;
|
|
219
|
+
}
|
|
220
|
+
else if (declared !== undefined && !declared.has(name)) {
|
|
221
|
+
report(at, `names ${name}, which runner.secrets doesn't declare`);
|
|
222
|
+
ok = false;
|
|
223
|
+
}
|
|
224
|
+
else if (seen.has(name)) {
|
|
225
|
+
report(at, `names ${name} again`);
|
|
226
|
+
ok = false;
|
|
227
|
+
}
|
|
228
|
+
if (typeof name === "string")
|
|
229
|
+
seen.add(name);
|
|
230
|
+
});
|
|
231
|
+
return ok ? [...value] : undefined;
|
|
159
232
|
}
|
|
160
233
|
function checkEnv(value, report) {
|
|
161
234
|
if (value === undefined)
|
|
@@ -180,6 +253,55 @@ function checkEnv(value, report) {
|
|
|
180
253
|
}
|
|
181
254
|
return ok ? env : undefined;
|
|
182
255
|
}
|
|
256
|
+
/**
|
|
257
|
+
* The runner secrets' names: each a distinct environment variable name that neither a step's environment
|
|
258
|
+
* (`STEP_ENV`) nor the command's (`STORM_RUN`) already sets, and that isn't reserved (`RESERVED_SECRET_NAMES`, or
|
|
259
|
+
* starting with `LD_` or `DYLD_`). Names match case-sensitively, so `path` is allowed.
|
|
260
|
+
*/
|
|
261
|
+
function checkSecrets(value, report) {
|
|
262
|
+
if (value === undefined)
|
|
263
|
+
return [];
|
|
264
|
+
if (!Array.isArray(value)) {
|
|
265
|
+
report(["secrets"], `must be a list of environment variable names, not ${describeRecipeValue(value)}`);
|
|
266
|
+
return undefined;
|
|
267
|
+
}
|
|
268
|
+
let ok = true;
|
|
269
|
+
const seen = new Set();
|
|
270
|
+
value.forEach((name, index) => {
|
|
271
|
+
const path = ["secrets", String(index)];
|
|
272
|
+
if (typeof name !== "string" || !VARIABLE_PATTERN.test(name)) {
|
|
273
|
+
report(path, `must be an environment variable name, letters, digits and underscores, not starting with a digit, not ${describeRecipeValue(name)}`);
|
|
274
|
+
ok = false;
|
|
275
|
+
}
|
|
276
|
+
else if (name === RUN_PAYLOAD_VARIABLE) {
|
|
277
|
+
report(path, `can't be ${name}: storm sets it for the command`);
|
|
278
|
+
ok = false;
|
|
279
|
+
}
|
|
280
|
+
else if (Object.hasOwn(STEP_ENV, name)) {
|
|
281
|
+
report(path, `can't be ${name}: storm sets it for every step`);
|
|
282
|
+
ok = false;
|
|
283
|
+
}
|
|
284
|
+
else if (RESERVED_SECRET_NAMES.has(name)) {
|
|
285
|
+
report(path, `can't be ${name}: it changes how a step's shell or programs run`);
|
|
286
|
+
ok = false;
|
|
287
|
+
}
|
|
288
|
+
else if (reservedPrefix(name) !== undefined) {
|
|
289
|
+
report(path, `can't be ${name}: a name starting with ${reservedPrefix(name)} changes how a step's programs load`);
|
|
290
|
+
ok = false;
|
|
291
|
+
}
|
|
292
|
+
else if (seen.has(name)) {
|
|
293
|
+
report(path, `names ${name} again`);
|
|
294
|
+
ok = false;
|
|
295
|
+
}
|
|
296
|
+
if (typeof name === "string")
|
|
297
|
+
seen.add(name);
|
|
298
|
+
});
|
|
299
|
+
return ok ? [...value] : undefined;
|
|
300
|
+
}
|
|
301
|
+
/** The reserved prefix `name` starts with, if any. */
|
|
302
|
+
function reservedPrefix(name) {
|
|
303
|
+
return RESERVED_SECRET_PREFIXES.find((prefix) => name.startsWith(prefix));
|
|
304
|
+
}
|
|
183
305
|
function checkBaseRefs(value, report) {
|
|
184
306
|
if (value === undefined)
|
|
185
307
|
return [...RECIPE_DEFAULTS.baseRefs];
|
|
@@ -207,12 +329,17 @@ function reportUnknownKeys(value, known, path, what, report) {
|
|
|
207
329
|
return ok;
|
|
208
330
|
}
|
|
209
331
|
/**
|
|
210
|
-
* What a recipe's steps are at one base: the list as given, or what the function returns for `context`, checked
|
|
211
|
-
*
|
|
332
|
+
* What a recipe's steps are at one base: the list as given, or what the function returns for `context`, checked,
|
|
333
|
+
* each with the runner secrets it names, which must be among `declared`, the recipe's `secrets`. A function that
|
|
334
|
+
* throws or rejects, or returns anything but a list of steps, is a problem worded to follow the key.
|
|
212
335
|
*/
|
|
213
|
-
export async function resolveSteps(steps, context) {
|
|
336
|
+
export async function resolveSteps(steps, context, declared) {
|
|
337
|
+
// A list passed `checkRecipe` against the same declared names.
|
|
214
338
|
if (typeof steps !== "function")
|
|
215
|
-
return {
|
|
339
|
+
return {
|
|
340
|
+
ok: true,
|
|
341
|
+
steps: steps.map(({ label, script, secrets }) => ({ label, script, secrets: [...(secrets ?? [])] })),
|
|
342
|
+
};
|
|
216
343
|
let returned;
|
|
217
344
|
try {
|
|
218
345
|
returned = await steps(context);
|
|
@@ -223,7 +350,8 @@ export async function resolveSteps(steps, context) {
|
|
|
223
350
|
if (!Array.isArray(returned))
|
|
224
351
|
return { ok: false, problem: `must return a list of steps, not ${describeRecipeValue(returned)}` };
|
|
225
352
|
const problems = [];
|
|
226
|
-
const
|
|
353
|
+
const names = new Set(declared);
|
|
354
|
+
const checked = returned.map((step, index) => checkStep(step, [String(index)], names, (path, problem) => problems.push({ path, problem })));
|
|
227
355
|
const first = problems[0];
|
|
228
356
|
if (first !== undefined)
|
|
229
357
|
return {
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { CheckedRecipe } from "./recipe.ts";
|
|
2
|
+
/**
|
|
3
|
+
* The fewest characters a runner secret's value may have. The run replaces each value wherever it appears in what it
|
|
4
|
+
* prints and writes, so a short one would replace ordinary output.
|
|
5
|
+
*/
|
|
6
|
+
export declare const RUNNER_SECRET_MIN_LENGTH = 8;
|
|
7
|
+
/**
|
|
8
|
+
* A runner secret's value by its name, each an own property. A name can be any environment variable name, such as
|
|
9
|
+
* `constructor` or `__proto__`, so a map is built with `Object.fromEntries` and read with `Object.hasOwn`, never by
|
|
10
|
+
* assignment into `{}` or a plain lookup, which reach `Object.prototype`.
|
|
11
|
+
*/
|
|
12
|
+
export type RunnerSecrets = Readonly<Record<string, string>>;
|
|
13
|
+
/**
|
|
14
|
+
* What keeps one runner secret from being used: its variable is unset or empty (`missing`), its value holds a carriage
|
|
15
|
+
* return or a line feed (`multiline`), which line-by-line output would split past redaction, or it is shorter than
|
|
16
|
+
* `RUNNER_SECRET_MIN_LENGTH` (`short`).
|
|
17
|
+
*/
|
|
18
|
+
export type RunnerSecretProblem = "missing" | "multiline" | "short";
|
|
19
|
+
/**
|
|
20
|
+
* The runner secrets' values, or what keeps the run from starting: each variable with a problem, one problem each, in
|
|
21
|
+
* the recipe's order.
|
|
22
|
+
*/
|
|
23
|
+
export type RunnerSecretsRead = {
|
|
24
|
+
readonly ok: true;
|
|
25
|
+
readonly values: RunnerSecrets;
|
|
26
|
+
} | {
|
|
27
|
+
readonly ok: false;
|
|
28
|
+
readonly variables: readonly {
|
|
29
|
+
readonly name: string;
|
|
30
|
+
readonly problem: RunnerSecretProblem;
|
|
31
|
+
}[];
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* The values of the runner secrets one step names, `names`, from `values`, every runner secret the run read. A step
|
|
35
|
+
* that names none gets none. `names` is checked against the recipe's `secrets`, so each has a value.
|
|
36
|
+
*/
|
|
37
|
+
export declare function stepSecrets(values: RunnerSecrets, names: readonly string[]): RunnerSecrets;
|
|
38
|
+
/**
|
|
39
|
+
* Reads each of `recipe`'s runner secrets from `env`, the environment of the machine the run starts on. A variable's
|
|
40
|
+
* problem is the first that holds of `missing`, `multiline` and `short`. A value is used as it is, never trimmed.
|
|
41
|
+
*/
|
|
42
|
+
export declare function readRunnerSecrets(recipe: Pick<CheckedRecipe, "secrets">, env: Readonly<Record<string, string | undefined>>): RunnerSecretsRead;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// The runner secrets' values: read from this machine's environment as a runner run starts, handed only to the recipe
|
|
2
|
+
// steps that name them, and hidden as `<token>` in what the run prints and writes. storm writes no value itself; what
|
|
3
|
+
// a step leaves in the sandbox is the recipe's to keep out (`README.md`).
|
|
4
|
+
/**
|
|
5
|
+
* The fewest characters a runner secret's value may have. The run replaces each value wherever it appears in what it
|
|
6
|
+
* prints and writes, so a short one would replace ordinary output.
|
|
7
|
+
*/
|
|
8
|
+
export const RUNNER_SECRET_MIN_LENGTH = 8;
|
|
9
|
+
/**
|
|
10
|
+
* The values of the runner secrets one step names, `names`, from `values`, every runner secret the run read. A step
|
|
11
|
+
* that names none gets none. `names` is checked against the recipe's `secrets`, so each has a value.
|
|
12
|
+
*/
|
|
13
|
+
export function stepSecrets(values, names) {
|
|
14
|
+
return Object.fromEntries(names.map((name) => {
|
|
15
|
+
const value = ownValue(values, name);
|
|
16
|
+
if (value === undefined)
|
|
17
|
+
throw new Error(`stepSecrets: no value for runner secret ${name}`);
|
|
18
|
+
return [name, value];
|
|
19
|
+
}));
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Reads each of `recipe`'s runner secrets from `env`, the environment of the machine the run starts on. A variable's
|
|
23
|
+
* problem is the first that holds of `missing`, `multiline` and `short`. A value is used as it is, never trimmed.
|
|
24
|
+
*/
|
|
25
|
+
export function readRunnerSecrets(recipe, env) {
|
|
26
|
+
const values = [];
|
|
27
|
+
const variables = [];
|
|
28
|
+
for (const name of recipe.secrets) {
|
|
29
|
+
const value = ownValue(env, name);
|
|
30
|
+
if (value === undefined || value === "")
|
|
31
|
+
variables.push({ name, problem: "missing" });
|
|
32
|
+
else if (/[\r\n]/.test(value))
|
|
33
|
+
variables.push({ name, problem: "multiline" });
|
|
34
|
+
else if (value.length < RUNNER_SECRET_MIN_LENGTH)
|
|
35
|
+
variables.push({ name, problem: "short" });
|
|
36
|
+
else
|
|
37
|
+
values.push([name, value]);
|
|
38
|
+
}
|
|
39
|
+
return variables.length === 0 ? { ok: true, values: Object.fromEntries(values) } : { ok: false, variables };
|
|
40
|
+
}
|
|
41
|
+
/** `map`'s own value for `name`, so a name `Object.prototype` has, such as `toString`, isn't read as set. */
|
|
42
|
+
function ownValue(map, name) {
|
|
43
|
+
return Object.hasOwn(map, name) ? map[name] : undefined;
|
|
44
|
+
}
|
|
@@ -3,9 +3,10 @@ import type { RunnerProgress, RunnerStage } from "./events.ts";
|
|
|
3
3
|
import type { RunnerSnapshotEntry, SandboxAccess } from "./gateways.ts";
|
|
4
4
|
import type { PreparedRunner } from "./prepare.ts";
|
|
5
5
|
import type { RunnerSandboxScope } from "./scope.ts";
|
|
6
|
+
import { type RunnerSecrets } from "./secrets.ts";
|
|
6
7
|
/** How long a build sandbox may live: 30 minutes. */
|
|
7
8
|
export declare const BUILD_SANDBOX_TIMEOUT_MS: number;
|
|
8
|
-
/** The label of the step between the toolchain and
|
|
9
|
+
/** The label of the step between the toolchain and prebuild steps that commits the base's files. */
|
|
9
10
|
export declare const BASE_INDEX_LABEL = "Committing the base's files";
|
|
10
11
|
/** A runner snapshot a run built and the cache entry recorded for it. */
|
|
11
12
|
export interface BuiltSnapshot {
|
|
@@ -14,12 +15,14 @@ export interface BuiltSnapshot {
|
|
|
14
15
|
readonly ms: number;
|
|
15
16
|
readonly sizeBytes: number;
|
|
16
17
|
}
|
|
17
|
-
/** What a snapshot build needs to know: the prepared run, who it runs as, and why it builds. */
|
|
18
|
+
/** What a snapshot build needs to know: the prepared run, who it runs as, the runner secrets, and why it builds. */
|
|
18
19
|
export interface BuildSnapshotRequest {
|
|
19
20
|
readonly prepared: PreparedRunner;
|
|
20
21
|
readonly access: SandboxAccess;
|
|
21
22
|
/** The local user, for the sandbox's `user` tag. */
|
|
22
23
|
readonly user: string;
|
|
24
|
+
/** Every runner secret's value, of which each toolchain and prebuild step gets the ones it names. */
|
|
25
|
+
readonly secrets: RunnerSecrets;
|
|
23
26
|
readonly reason: "no-snapshot" | "rebuild";
|
|
24
27
|
}
|
|
25
28
|
/**
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
// Building a runner snapshot of a run's base: a build sandbox runs the toolchain steps, commits exactly the base's
|
|
2
|
-
// tracked files, runs the
|
|
2
|
+
// tracked files, runs the prebuild steps, and is saved as a snapshot, which the cache then records.
|
|
3
3
|
import { runnerTags } from "./context.js";
|
|
4
|
+
import { stepSecrets } from "./secrets.js";
|
|
4
5
|
import { dropBranchSnapshots, SNAPSHOT_EXPIRATION_MS } from "./snapshot-cache.js";
|
|
5
6
|
import { baseIndexScript, STAGED_FILES } from "./snapshot-key.js";
|
|
6
7
|
import { runStep, sandboxStop } from "./steps.js";
|
|
7
8
|
/** How long a build sandbox may live: 30 minutes. */
|
|
8
9
|
export const BUILD_SANDBOX_TIMEOUT_MS = 30 * 60_000;
|
|
9
|
-
/** The label of the step between the toolchain and
|
|
10
|
+
/** The label of the step between the toolchain and prebuild steps that commits the base's files. */
|
|
10
11
|
export const BASE_INDEX_LABEL = "Committing the base's files";
|
|
11
12
|
/**
|
|
12
13
|
* Builds a runner snapshot of `prepared.base`. The build sandbox starts while the base's files are packed, and is
|
|
@@ -25,7 +26,7 @@ export async function buildSnapshot(context, request, control, progress) {
|
|
|
25
26
|
kind: "snapshot-build-started",
|
|
26
27
|
base,
|
|
27
28
|
reason: request.reason,
|
|
28
|
-
summary: recipe.snapshot.summary ?? [...prepared.toolchains, ...prepared.
|
|
29
|
+
summary: recipe.snapshot.summary ?? [...prepared.toolchains, ...prepared.prebuild].map(({ label }) => label).join(", "),
|
|
29
30
|
});
|
|
30
31
|
const [started, archive] = await Promise.all([
|
|
31
32
|
scope.startBuildSandbox(access, {
|
|
@@ -56,10 +57,16 @@ export async function buildSnapshot(context, request, control, progress) {
|
|
|
56
57
|
], signal);
|
|
57
58
|
if (!staged.ok)
|
|
58
59
|
return sandboxStop("upload", staged.failure);
|
|
60
|
+
// Each recipe step gets the runner secrets it names; storm's own base-index step gets none.
|
|
61
|
+
const recipeStep = ({ label, script, secrets }) => ({
|
|
62
|
+
label,
|
|
63
|
+
script,
|
|
64
|
+
secrets: stepSecrets(request.secrets, secrets),
|
|
65
|
+
});
|
|
59
66
|
const steps = [
|
|
60
|
-
...prepared.toolchains,
|
|
67
|
+
...prepared.toolchains.map(recipeStep),
|
|
61
68
|
{ label: BASE_INDEX_LABEL, script: baseIndexScript(base, staged.value.directory) },
|
|
62
|
-
...prepared.
|
|
69
|
+
...prepared.prebuild.map(recipeStep),
|
|
63
70
|
];
|
|
64
71
|
await progress.emit({ kind: "output-started", section: "snapshot", sandbox: sandbox.name, region: recipe.region });
|
|
65
72
|
for (const step of steps) {
|
|
@@ -72,14 +72,14 @@ export interface SnapshotCacheContext {
|
|
|
72
72
|
/**
|
|
73
73
|
* Reads the cache for the runner snapshots a run of `recipe` on `branch` may start from. It removes expired entries'
|
|
74
74
|
* files, and keeps the entries for the recipe's region, runtime and name with more than an hour left, whose base HEAD
|
|
75
|
-
* contains (a base missing from the clone doesn't), and whose snapshot key, recomputed at that entry's base
|
|
76
|
-
* one recorded. Of branch snapshots it keeps only `branch`'s saved from this checkout, `repoRoot`, whatever HEAD
|
|
75
|
+
* contains (a base missing from the clone doesn't), and whose snapshot key, recomputed at that entry's base with the
|
|
76
|
+
* recipe's runner secret names, is the one recorded. Of branch snapshots it keeps only `branch`'s saved from this checkout, `repoRoot`, whatever HEAD
|
|
77
77
|
* commit saved them; with `branch` null, a detached HEAD, it keeps none. A branch of the same name in another checkout
|
|
78
78
|
* may hold other code, so its snapshot never carries over. A failure along the way is a note, never a refusal.
|
|
79
79
|
*/
|
|
80
80
|
export declare function findSnapshotCandidates(context: SnapshotCacheContext, request: {
|
|
81
81
|
readonly repoRoot: string;
|
|
82
|
-
readonly recipe: Pick<CheckedRecipe, "name" | "region" | "runtime" | "snapshot">;
|
|
82
|
+
readonly recipe: Pick<CheckedRecipe, "name" | "region" | "runtime" | "snapshot" | "secrets">;
|
|
83
83
|
/** HEAD's branch; null when detached. */
|
|
84
84
|
readonly branch: string | null;
|
|
85
85
|
}): Promise<{
|
|
@@ -49,8 +49,8 @@ export function hasTimeLeft(entry, now) {
|
|
|
49
49
|
/**
|
|
50
50
|
* Reads the cache for the runner snapshots a run of `recipe` on `branch` may start from. It removes expired entries'
|
|
51
51
|
* files, and keeps the entries for the recipe's region, runtime and name with more than an hour left, whose base HEAD
|
|
52
|
-
* contains (a base missing from the clone doesn't), and whose snapshot key, recomputed at that entry's base
|
|
53
|
-
* one recorded. Of branch snapshots it keeps only `branch`'s saved from this checkout, `repoRoot`, whatever HEAD
|
|
52
|
+
* contains (a base missing from the clone doesn't), and whose snapshot key, recomputed at that entry's base with the
|
|
53
|
+
* recipe's runner secret names, is the one recorded. Of branch snapshots it keeps only `branch`'s saved from this checkout, `repoRoot`, whatever HEAD
|
|
54
54
|
* commit saved them; with `branch` null, a detached HEAD, it keeps none. A branch of the same name in another checkout
|
|
55
55
|
* may hold other code, so its snapshot never carries over. A failure along the way is a note, never a refusal.
|
|
56
56
|
*/
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { CheckoutGateway } from "./gateways.ts";
|
|
2
|
-
import { type
|
|
2
|
+
import { type CheckedRecipe, type ResolvedRunnerStep, type RunnerStep } from "./recipe.ts";
|
|
3
3
|
/**
|
|
4
4
|
* Bump when a runner snapshot changes in a way its steps' text doesn't show (the scripts between the steps, what is
|
|
5
|
-
* uploaded, the build sandbox), so earlier snapshots stop matching.
|
|
5
|
+
* uploaded, the build sandbox), or the key's encoding changes, so earlier snapshots stop matching. 2 added each step's
|
|
6
|
+
* runner secret names.
|
|
6
7
|
*/
|
|
7
|
-
export declare const SNAPSHOT_FORMAT =
|
|
8
|
+
export declare const SNAPSHOT_FORMAT = 2;
|
|
8
9
|
/** Where the repository lives in every runner and build sandbox. */
|
|
9
10
|
export declare const REMOTE_ROOT = "/vercel/sandbox";
|
|
10
11
|
/** The names of the files uploaded to a sandbox's staging directory. */
|
|
@@ -25,7 +26,7 @@ export declare const RESET_TO_BASE: readonly string[];
|
|
|
25
26
|
export declare function bashScript(lines: readonly string[]): string;
|
|
26
27
|
/**
|
|
27
28
|
* Extracts the base's files from `<staging>/base.tgz` and commits exactly its tracked files
|
|
28
|
-
* (`<staging>/base-files`), before the
|
|
29
|
+
* (`<staging>/base-files`), before the prebuild steps. `git add -A` would drop tracked files `.gitignore` matches.
|
|
29
30
|
*/
|
|
30
31
|
export declare function baseIndexScript(base: string, staging: string): string;
|
|
31
32
|
/**
|
|
@@ -36,28 +37,34 @@ export declare function baseIndexScript(base: string, staging: string): string;
|
|
|
36
37
|
*/
|
|
37
38
|
export declare function applyScript(staging: string): string;
|
|
38
39
|
/**
|
|
39
|
-
* The snapshot key: sha256 hex over `format=<SNAPSHOT_FORMAT>`, each toolchain step's label
|
|
40
|
-
* base-index script with the placeholders `<base>`
|
|
41
|
-
*
|
|
40
|
+
* The snapshot key: sha256 hex over `format=<SNAPSHOT_FORMAT>`, each toolchain step's label, script and
|
|
41
|
+
* `secrets=<its runner secret names, sorted, joined with ",">`, the base-index script with the placeholders `<base>`
|
|
42
|
+
* and `<staging>`, and each prebuild step's three fields the same way, joined with NUL. Every step gives all three, so a
|
|
43
|
+
* step without runner secrets gives `secrets=`. The names are in the key, never the values: a step that gets another
|
|
44
|
+
* secret may build another snapshot, and every machine with the same recipe shares one. The base isn't in the key: a
|
|
45
|
+
* cache entry records it beside the key.
|
|
42
46
|
*/
|
|
43
47
|
export declare function snapshotKey(steps: {
|
|
44
48
|
readonly toolchains: readonly RunnerStep[];
|
|
45
|
-
readonly
|
|
49
|
+
readonly prebuild: readonly RunnerStep[];
|
|
46
50
|
}): string;
|
|
47
51
|
/** A recipe's snapshot steps at one base and their key, or the step key whose function failed there and why. */
|
|
48
52
|
export type SnapshotStepsAt = {
|
|
49
53
|
readonly ok: true;
|
|
50
|
-
readonly toolchains: readonly
|
|
51
|
-
readonly
|
|
54
|
+
readonly toolchains: readonly ResolvedRunnerStep[];
|
|
55
|
+
readonly prebuild: readonly ResolvedRunnerStep[];
|
|
52
56
|
readonly key: string;
|
|
53
57
|
} | {
|
|
54
58
|
readonly ok: false;
|
|
55
59
|
readonly path: readonly string[];
|
|
56
60
|
readonly problem: string;
|
|
57
61
|
};
|
|
58
|
-
/**
|
|
62
|
+
/**
|
|
63
|
+
* Evaluates `recipe`'s toolchain and prebuild steps at `base`, each step's runner secrets checked against the recipe's
|
|
64
|
+
* `secrets`, and computes their snapshot key.
|
|
65
|
+
*/
|
|
59
66
|
export declare function snapshotStepsAt(checkout: CheckoutGateway, request: {
|
|
60
67
|
readonly repoRoot: string;
|
|
61
68
|
readonly base: string;
|
|
62
|
-
readonly recipe: Pick<
|
|
69
|
+
readonly recipe: Pick<CheckedRecipe, "snapshot" | "secrets">;
|
|
63
70
|
}): Promise<SnapshotStepsAt>;
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
// What a runner snapshot is built from, and the scripts that commit a base in a build sandbox and a run's changes in
|
|
2
|
-
// a runner sandbox. The snapshot key hashes the steps' text
|
|
2
|
+
// a runner sandbox. The snapshot key hashes the steps' text and the names of the runner secrets each gets, so editing
|
|
3
|
+
// a step means a new snapshot.
|
|
3
4
|
import { createHash } from "node:crypto";
|
|
4
5
|
import { baseStepContext } from "./base.js";
|
|
5
6
|
import { resolveSteps } from "./recipe.js";
|
|
6
7
|
/**
|
|
7
8
|
* Bump when a runner snapshot changes in a way its steps' text doesn't show (the scripts between the steps, what is
|
|
8
|
-
* uploaded, the build sandbox), so earlier snapshots stop matching.
|
|
9
|
+
* uploaded, the build sandbox), or the key's encoding changes, so earlier snapshots stop matching. 2 added each step's
|
|
10
|
+
* runner secret names.
|
|
9
11
|
*/
|
|
10
|
-
export const SNAPSHOT_FORMAT =
|
|
12
|
+
export const SNAPSHOT_FORMAT = 2;
|
|
11
13
|
/** Where the repository lives in every runner and build sandbox. */
|
|
12
14
|
export const REMOTE_ROOT = "/vercel/sandbox";
|
|
13
15
|
/** The names of the files uploaded to a sandbox's staging directory. */
|
|
@@ -36,7 +38,7 @@ export function bashScript(lines) {
|
|
|
36
38
|
}
|
|
37
39
|
/**
|
|
38
40
|
* Extracts the base's files from `<staging>/base.tgz` and commits exactly its tracked files
|
|
39
|
-
* (`<staging>/base-files`), before the
|
|
41
|
+
* (`<staging>/base-files`), before the prebuild steps. `git add -A` would drop tracked files `.gitignore` matches.
|
|
40
42
|
*/
|
|
41
43
|
export function baseIndexScript(base, staging) {
|
|
42
44
|
const tarball = `${staging}/${STAGED_FILES.baseTarball}`;
|
|
@@ -74,34 +76,41 @@ export function applyScript(staging) {
|
|
|
74
76
|
]);
|
|
75
77
|
}
|
|
76
78
|
/**
|
|
77
|
-
* The snapshot key: sha256 hex over `format=<SNAPSHOT_FORMAT>`, each toolchain step's label
|
|
78
|
-
* base-index script with the placeholders `<base>`
|
|
79
|
-
*
|
|
79
|
+
* The snapshot key: sha256 hex over `format=<SNAPSHOT_FORMAT>`, each toolchain step's label, script and
|
|
80
|
+
* `secrets=<its runner secret names, sorted, joined with ",">`, the base-index script with the placeholders `<base>`
|
|
81
|
+
* and `<staging>`, and each prebuild step's three fields the same way, joined with NUL. Every step gives all three, so a
|
|
82
|
+
* step without runner secrets gives `secrets=`. The names are in the key, never the values: a step that gets another
|
|
83
|
+
* secret may build another snapshot, and every machine with the same recipe shares one. The base isn't in the key: a
|
|
84
|
+
* cache entry records it beside the key.
|
|
80
85
|
*/
|
|
81
86
|
export function snapshotKey(steps) {
|
|
82
|
-
const text = (list) => list.flatMap(({ label, script }) => [label, script]);
|
|
87
|
+
const text = (list) => list.flatMap(({ label, script, secrets }) => [label, script, `secrets=${(secrets ?? []).toSorted().join(",")}`]);
|
|
83
88
|
return createHash("sha256")
|
|
84
89
|
.update([
|
|
85
90
|
`format=${SNAPSHOT_FORMAT}`,
|
|
86
91
|
...text(steps.toolchains),
|
|
87
92
|
baseIndexScript("<base>", "<staging>"),
|
|
88
|
-
...text(steps.
|
|
93
|
+
...text(steps.prebuild),
|
|
89
94
|
].join("\0"))
|
|
90
95
|
.digest("hex");
|
|
91
96
|
}
|
|
92
|
-
/**
|
|
97
|
+
/**
|
|
98
|
+
* Evaluates `recipe`'s toolchain and prebuild steps at `base`, each step's runner secrets checked against the recipe's
|
|
99
|
+
* `secrets`, and computes their snapshot key.
|
|
100
|
+
*/
|
|
93
101
|
export async function snapshotStepsAt(checkout, request) {
|
|
94
102
|
const context = baseStepContext(checkout, request);
|
|
95
|
-
const
|
|
103
|
+
const { snapshot, secrets } = request.recipe;
|
|
104
|
+
const toolchains = await resolveSteps(snapshot.toolchains, context, secrets);
|
|
96
105
|
if (!toolchains.ok)
|
|
97
106
|
return { ok: false, path: ["snapshot", "toolchains"], problem: toolchains.problem };
|
|
98
|
-
const
|
|
99
|
-
if (!
|
|
100
|
-
return { ok: false, path: ["snapshot", "
|
|
107
|
+
const prebuild = await resolveSteps(snapshot.prebuild, context, secrets);
|
|
108
|
+
if (!prebuild.ok)
|
|
109
|
+
return { ok: false, path: ["snapshot", "prebuild"], problem: prebuild.problem };
|
|
101
110
|
return {
|
|
102
111
|
ok: true,
|
|
103
112
|
toolchains: toolchains.steps,
|
|
104
|
-
|
|
105
|
-
key: snapshotKey({ toolchains: toolchains.steps,
|
|
113
|
+
prebuild: prebuild.steps,
|
|
114
|
+
key: snapshotKey({ toolchains: toolchains.steps, prebuild: prebuild.steps }),
|
|
106
115
|
};
|
|
107
116
|
}
|
|
@@ -42,9 +42,11 @@ type BranchSnapshotSave = Exclude<RunnerSave, {
|
|
|
42
42
|
* branch's entry in that checkout at that base; the snapshot it replaces is left to expire, since a run on this
|
|
43
43
|
* machine may be starting from it. Nothing here changes the run's outcome: each way it ends is a note.
|
|
44
44
|
*
|
|
45
|
-
* It searches nothing for the run's secrets: the snapshot keeps what the command
|
|
46
|
-
*
|
|
47
|
-
*
|
|
45
|
+
* It searches nothing for the run's secrets: the snapshot keeps what the command and the recipe's steps wrote to
|
|
46
|
+
* `$HOME`, the ignored files and `.git`, as a kept runner sandbox does. A resource's token is limited to one test
|
|
47
|
+
* resource. A runner secret a step that got it left behind is not: the recipe must not leave one, since later steps
|
|
48
|
+
* and commands on the snapshot can read it (`README.md`). Only a later run on the branch from this checkout starts
|
|
49
|
+
* from the snapshot.
|
|
48
50
|
*/
|
|
49
51
|
export declare function saveBranchSnapshot(context: Pick<RunnerContext, "runnerSandboxes" | "runnerSnapshots" | "clock">, request: SaveBranchSnapshotRequest, control: {
|
|
50
52
|
readonly scope: RunnerSandboxScope;
|