@cnc-tools/storm 0.6.0 → 0.8.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/cleanup.d.ts +3 -3
- package/dist/commands/exec/cleanup.js +1 -1
- package/dist/commands/exec/command.d.ts +797 -1
- package/dist/commands/exec/command.js +1 -1
- package/dist/commands/exec/live-view.js +32 -15
- package/dist/commands/exec/metadata.d.ts +5 -2
- package/dist/commands/exec/metadata.js +4 -0
- package/dist/commands/exec/mint-failed.d.ts +28 -0
- package/dist/commands/exec/outcomes.d.ts +526 -0
- package/dist/commands/exec/outcomes.js +9 -0
- package/dist/commands/exec/progress.d.ts +14 -2
- package/dist/commands/exec/progress.js +57 -14
- package/dist/commands/exec/run-command.d.ts +10 -4
- package/dist/commands/exec/run-command.js +41 -8
- package/dist/commands/exec/run-metadata.d.ts +6 -3
- package/dist/commands/exec/run-metadata.js +6 -3
- package/dist/commands/exec/run-record.d.ts +83 -4
- package/dist/commands/exec/run-record.js +49 -1
- package/dist/commands/exec/tests-summary.d.ts +1 -1
- package/dist/commands/exec/tests-summary.js +1 -1
- package/dist/commands/exec/view.js +36 -4
- package/dist/commands/runs/facts.d.ts +25 -0
- package/dist/commands/runs/facts.js +36 -3
- package/dist/commands/runs/list/command.d.ts +154 -1
- package/dist/commands/runs/list/command.js +1 -1
- package/dist/commands/runs/list/outcomes.d.ts +41 -0
- package/dist/commands/runs/logs/command.d.ts +263 -1
- package/dist/commands/runs/logs/command.js +1 -1
- package/dist/commands/runs/logs/outcomes.d.ts +105 -0
- package/dist/commands/runs/show/command.d.ts +354 -1
- package/dist/commands/runs/show/command.js +1 -1
- package/dist/commands/runs/show/metadata.js +1 -1
- package/dist/commands/runs/show/outcomes.d.ts +96 -0
- package/dist/commands/runs/show/outcomes.js +30 -1
- package/dist/commands/vitest/command.d.ts +912 -1
- package/dist/commands/vitest/command.js +1 -1
- package/dist/commands/vitest/metadata.d.ts +5 -2
- package/dist/commands/vitest/metadata.js +4 -0
- package/dist/commands/vitest/outcomes.d.ts +320 -0
- package/dist/config/errors.d.ts +73 -0
- package/dist/config/schema.d.ts +1 -1
- package/dist/config-file/define.d.ts +4 -3
- package/dist/config-file/define.js +1 -1
- package/dist/config-file/toolchain.js +1 -1
- package/dist/core/command-slots.d.ts +8 -2
- package/dist/core/command-slots.js +6 -2
- package/dist/core/events.d.ts +9 -7
- package/dist/core/index.d.ts +1 -1
- package/dist/core/run-state.d.ts +30 -6
- package/dist/core/run-state.js +19 -4
- package/dist/core/run.d.ts +17 -4
- package/dist/core/run.js +61 -25
- package/dist/credential/index.d.ts +1 -0
- package/dist/credential/index.js +1 -0
- package/dist/credential/settle.d.ts +20 -0
- package/dist/credential/target.d.ts +6 -0
- package/dist/credential/target.js +7 -0
- package/dist/resources/github/command.d.ts +54 -2
- package/dist/resources/github/config.js +1 -1
- package/dist/resources/github/index.js +1 -1
- package/dist/resources/github/resource.js +2 -2
- package/dist/resources/testserver/command.d.ts +208 -10
- package/dist/resources/testserver/command.js +7 -0
- package/dist/resources/testserver/commands/create/command.d.ts +808 -1
- package/dist/resources/testserver/commands/create/command.js +64 -23
- package/dist/resources/testserver/commands/create/metadata.js +6 -2
- package/dist/resources/testserver/commands/create/outcomes.d.ts +347 -0
- package/dist/resources/testserver/commands/create/outcomes.js +14 -1
- package/dist/resources/testserver/commands/list/command.d.ts +84 -1
- package/dist/resources/testserver/commands/list/command.js +1 -1
- package/dist/resources/testserver/commands/list/outcomes.d.ts +16 -0
- package/dist/resources/testserver/config.js +14 -4
- package/dist/resources/testserver/events.d.ts +9 -0
- package/dist/resources/testserver/index.js +8 -7
- package/dist/resources/testserver/lane.js +1 -0
- package/dist/resources/testserver/live/gateways.d.ts +2 -0
- package/dist/resources/testserver/live/gateways.js +16 -3
- package/dist/resources/testserver/pool/channels.d.ts +5 -2
- package/dist/resources/testserver/pool/channels.js +1 -1
- package/dist/resources/testserver/pool/create.d.ts +6 -2
- package/dist/resources/testserver/pool/create.js +6 -5
- package/dist/resources/testserver/pool/index.d.ts +1 -0
- package/dist/resources/testserver/pool/index.js +1 -0
- package/dist/resources/testserver/pool/pull-request.d.ts +89 -0
- package/dist/resources/testserver/pool/pull-request.js +85 -0
- package/dist/resources/testserver/pr-build-facts.d.ts +130 -0
- package/dist/resources/testserver/pr-build-facts.js +261 -0
- package/dist/resources/testserver/presentation.d.ts +2 -2
- package/dist/resources/testserver/presentation.js +12 -3
- package/dist/resources/testserver/provider.d.ts +16 -6
- package/dist/resources/testserver/provider.js +46 -15
- package/dist/resources/testserver/pull-request/gateways.d.ts +117 -0
- package/dist/resources/testserver/pull-request/gateways.js +5 -0
- package/dist/resources/testserver/pull-request/index.d.ts +5 -0
- package/dist/resources/testserver/pull-request/index.js +6 -0
- package/dist/resources/testserver/pull-request/live/github-rest.d.ts +28 -0
- package/dist/resources/testserver/pull-request/live/github-rest.js +114 -0
- package/dist/resources/testserver/pull-request/live/github-token-gateway.d.ts +12 -0
- package/dist/resources/testserver/pull-request/live/github-token-gateway.js +39 -0
- package/dist/resources/testserver/pull-request/live/pull-request-gateway.d.ts +10 -0
- package/dist/resources/testserver/pull-request/live/pull-request-gateway.js +27 -0
- package/dist/resources/testserver/pull-request/live/testserver-workflow-gateway.d.ts +21 -0
- package/dist/resources/testserver/pull-request/live/testserver-workflow-gateway.js +64 -0
- package/dist/resources/testserver/ran.d.ts +5 -0
- package/dist/resources/testserver/ran.js +19 -3
- package/dist/resources/testserver/resource.d.ts +5 -1
- package/dist/resources/testserver/resource.js +2 -2
- package/dist/resources/testserver/sandbox/build-reference.d.ts +38 -0
- package/dist/resources/testserver/sandbox/build-reference.js +79 -0
- package/dist/resources/testserver/sandbox/index.d.ts +1 -0
- package/dist/resources/testserver/sandbox/index.js +1 -0
- package/dist/resources.d.ts +265 -15
- package/dist/runner/events.d.ts +64 -1
- package/dist/runner/gateways.d.ts +17 -6
- package/dist/runner/index.d.ts +5 -4
- package/dist/runner/index.js +4 -3
- package/dist/runner/live/snapshot-records.js +18 -4
- package/dist/runner/prepare.d.ts +23 -4
- package/dist/runner/prepare.js +13 -3
- package/dist/runner/ready.d.ts +7 -3
- package/dist/runner/ready.js +11 -5
- package/dist/runner/scope.d.ts +17 -1
- package/dist/runner/scope.js +4 -0
- package/dist/runner/snapshot-build.d.ts +3 -1
- package/dist/runner/snapshot-build.js +12 -2
- package/dist/runner/snapshot-cache.d.ts +46 -8
- package/dist/runner/snapshot-cache.js +60 -11
- package/dist/runner/snapshot-key.d.ts +12 -1
- package/dist/runner/snapshot-key.js +17 -1
- package/dist/runner/snapshot-save.d.ts +53 -0
- package/dist/runner/snapshot-save.js +148 -0
- package/dist/sdk/index.js +2 -2
- package/dist/story/align.d.ts +1 -1
- package/dist/story/align.js +1 -1
- package/dist/story/command-line.d.ts +34 -0
- package/dist/story/command-line.js +100 -0
- package/dist/story/definition.d.ts +22 -15
- package/dist/story/definition.js +2 -2
- package/dist/story/errors.js +1 -1
- package/dist/story/gateways.d.ts +45 -25
- package/dist/story/gateways.js +2 -2
- package/dist/story/host.d.ts +11 -8
- package/dist/story/host.js +37 -37
- package/dist/story/index.d.ts +2 -1
- package/dist/story/index.js +6 -5
- package/dist/story/json.d.ts +1 -1
- package/dist/story/json.js +2 -2
- package/dist/story/live/recording-gateway.d.ts +2 -0
- package/dist/story/live/{artifact-gateway.js → recording-gateway.js} +33 -12
- package/dist/story/mode.d.ts +2 -2
- package/dist/story/mode.js +1 -1
- package/dist/story/orphans.d.ts +23 -5
- package/dist/story/orphans.js +44 -8
- package/dist/story/recording.d.ts +62 -0
- package/dist/story/{artifact.js → recording.js} +31 -27
- package/dist/story/report.d.ts +21 -9
- package/dist/story/report.js +37 -25
- package/dist/story/settle.d.ts +23 -21
- package/dist/story/settle.js +17 -16
- package/dist/story/{run.d.ts → start.d.ts} +18 -17
- package/dist/story/{run.js → start.js} +66 -43
- package/dist/vercel-cli/context.js +1 -1
- package/dist/vercel-cli/index.js +1 -1
- package/dist/vitest/config.js +2 -2
- package/dist/vitest/fixtures.d.ts +1 -1
- package/dist/vitest/fixtures.js +1 -1
- package/dist/vitest/index.js +3 -3
- package/dist/vitest/plan.js +1 -1
- package/package.json +3 -3
- package/skills/overview.md +2 -0
- package/skills/testserver-builds.md +80 -0
- package/dist/story/artifact.d.ts +0 -60
- package/dist/story/live/artifact-gateway.d.ts +0 -2
|
@@ -57,4 +57,87 @@ export declare function command(cmd: CommandBuilder<TestserverCommandApp>): impo
|
|
|
57
57
|
path: z.ZodString;
|
|
58
58
|
message: z.ZodString;
|
|
59
59
|
}, z.core.$strip>;
|
|
60
|
-
}
|
|
60
|
+
}, {
|
|
61
|
+
readonly poolUnreadable: {
|
|
62
|
+
readonly exitCode: 1;
|
|
63
|
+
readonly description: "storm couldn't read the pool.";
|
|
64
|
+
readonly schema: z.ZodObject<{
|
|
65
|
+
path: z.ZodString;
|
|
66
|
+
message: z.ZodString;
|
|
67
|
+
}, z.core.$strip>;
|
|
68
|
+
readonly render: ({ path, message }: {
|
|
69
|
+
path: string;
|
|
70
|
+
message: string;
|
|
71
|
+
}) => {
|
|
72
|
+
message: string;
|
|
73
|
+
rows: [string, string][];
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
}>, import("@vercel/clinkr").OutcomeOf<import("@vercel/clinkr").Outcomes<{
|
|
77
|
+
listed: z.ZodObject<{
|
|
78
|
+
poolPath: z.ZodString;
|
|
79
|
+
entries: z.ZodArray<z.ZodObject<{
|
|
80
|
+
testserverUrl: z.ZodString;
|
|
81
|
+
logViewerUrl: z.ZodString;
|
|
82
|
+
requestedBuild: z.ZodString;
|
|
83
|
+
resolvedBuild: z.ZodString;
|
|
84
|
+
createdAt: z.ZodString;
|
|
85
|
+
ttlMinutes: z.ZodNumber;
|
|
86
|
+
minutesLeft: z.ZodNumber;
|
|
87
|
+
lease: z.ZodObject<{
|
|
88
|
+
state: z.ZodEnum<{
|
|
89
|
+
free: "free";
|
|
90
|
+
leased: "leased";
|
|
91
|
+
stale: "stale";
|
|
92
|
+
}>;
|
|
93
|
+
pid: z.ZodNullable<z.ZodNumber>;
|
|
94
|
+
hostname: z.ZodNullable<z.ZodString>;
|
|
95
|
+
startedAt: z.ZodNullable<z.ZodString>;
|
|
96
|
+
holderAlive: z.ZodNullable<z.ZodBoolean>;
|
|
97
|
+
}, z.core.$strip>;
|
|
98
|
+
leaseGuard: z.ZodBoolean;
|
|
99
|
+
health: z.ZodObject<{
|
|
100
|
+
kind: z.ZodEnum<{
|
|
101
|
+
answers: "answers";
|
|
102
|
+
expired: "expired";
|
|
103
|
+
failed: "failed";
|
|
104
|
+
}>;
|
|
105
|
+
status: z.ZodNullable<z.ZodNumber>;
|
|
106
|
+
detail: z.ZodNullable<z.ZodString>;
|
|
107
|
+
}, z.core.$strip>;
|
|
108
|
+
}, z.core.$strip>>;
|
|
109
|
+
unreadable: z.ZodArray<z.ZodObject<{
|
|
110
|
+
file: z.ZodString;
|
|
111
|
+
reason: z.ZodString;
|
|
112
|
+
}, z.core.$strip>>;
|
|
113
|
+
channels: z.ZodArray<z.ZodObject<{
|
|
114
|
+
channel: z.ZodString;
|
|
115
|
+
build: z.ZodString;
|
|
116
|
+
learnedAt: z.ZodString;
|
|
117
|
+
ageMinutes: z.ZodNumber;
|
|
118
|
+
}, z.core.$strip>>;
|
|
119
|
+
}, z.core.$strip>;
|
|
120
|
+
}, {
|
|
121
|
+
listed: unknown;
|
|
122
|
+
}, {
|
|
123
|
+
poolUnreadable: z.ZodObject<{
|
|
124
|
+
path: z.ZodString;
|
|
125
|
+
message: z.ZodString;
|
|
126
|
+
}, z.core.$strip>;
|
|
127
|
+
}, {
|
|
128
|
+
readonly poolUnreadable: {
|
|
129
|
+
readonly exitCode: 1;
|
|
130
|
+
readonly description: "storm couldn't read the pool.";
|
|
131
|
+
readonly schema: z.ZodObject<{
|
|
132
|
+
path: z.ZodString;
|
|
133
|
+
message: z.ZodString;
|
|
134
|
+
}, z.core.$strip>;
|
|
135
|
+
readonly render: ({ path, message }: {
|
|
136
|
+
path: string;
|
|
137
|
+
message: string;
|
|
138
|
+
}) => {
|
|
139
|
+
message: string;
|
|
140
|
+
rows: [string, string][];
|
|
141
|
+
};
|
|
142
|
+
};
|
|
143
|
+
}>>, TestserverCommandApp, false>;
|
|
@@ -9,7 +9,7 @@ import { outcomes } from "./outcomes.js";
|
|
|
9
9
|
export function command(cmd) {
|
|
10
10
|
return cmd.define({
|
|
11
11
|
requestSchema: z.object({}).strict(),
|
|
12
|
-
outcomes,
|
|
12
|
+
response: outcomes,
|
|
13
13
|
handler: async ({ app }) => {
|
|
14
14
|
const inspected = await inspectPool(app.context);
|
|
15
15
|
if (!inspected.ok)
|
|
@@ -51,4 +51,20 @@ export declare const outcomes: import("@vercel/clinkr").Outcomes<{
|
|
|
51
51
|
path: z.ZodString;
|
|
52
52
|
message: z.ZodString;
|
|
53
53
|
}, z.core.$strip>;
|
|
54
|
+
}, {
|
|
55
|
+
readonly poolUnreadable: {
|
|
56
|
+
readonly exitCode: 1;
|
|
57
|
+
readonly description: "storm couldn't read the pool.";
|
|
58
|
+
readonly schema: z.ZodObject<{
|
|
59
|
+
path: z.ZodString;
|
|
60
|
+
message: z.ZodString;
|
|
61
|
+
}, z.core.$strip>;
|
|
62
|
+
readonly render: ({ path, message }: {
|
|
63
|
+
path: string;
|
|
64
|
+
message: string;
|
|
65
|
+
}) => {
|
|
66
|
+
message: string;
|
|
67
|
+
rows: [string, string][];
|
|
68
|
+
};
|
|
69
|
+
};
|
|
54
70
|
}>;
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
// and default of each option, and the checks across its options. `config` loads and merges against it, and `exec` and
|
|
3
3
|
// `vitest` check their own `--testserver-<option>` flags with its rules;
|
|
4
4
|
// the command half (`command.ts`) settles the resolved options into the run's request.
|
|
5
|
-
import { checkBoolean,
|
|
5
|
+
import { checkBoolean, describeValue, optionKeyPath, readBooleanText, readTextAsIs, readWholeNumberText, wrongValue, } from "../../config/index.js";
|
|
6
6
|
import { parseDuration, parseTtl } from "../../time/index.js";
|
|
7
7
|
import { MAX_SANDBOXES, MIN_SANDBOXES } from "./options.js";
|
|
8
|
-
import { DEFAULT_TTL_MINUTES } from "./sandbox/index.js";
|
|
8
|
+
import { buildReferenceText, DEFAULT_TTL_MINUTES, parseBuildReference } from "./sandbox/index.js";
|
|
9
9
|
/** The resource's name, its key under `resources`. */
|
|
10
10
|
const NAME = "testserverPool";
|
|
11
11
|
function sandboxCount(value) {
|
|
@@ -13,6 +13,16 @@ function sandboxCount(value) {
|
|
|
13
13
|
? { ok: true, value }
|
|
14
14
|
: wrongValue(`must be a whole number from ${MIN_SANDBOXES} to ${MAX_SANDBOXES}, not ${describeValue(value)}`);
|
|
15
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* A build, a build channel or a PR build reference, settled: a PR build reference, `pr:<N>` or the vercel/api pull
|
|
18
|
+
* request's URL, becomes `pr:<N>`, so everything after the check sees only that form.
|
|
19
|
+
*/
|
|
20
|
+
function checkBuild(value) {
|
|
21
|
+
if (typeof value !== "string" || value.length === 0)
|
|
22
|
+
return wrongValue(`must be a non-empty string, not ${describeValue(value)}`);
|
|
23
|
+
const parsed = parseBuildReference(value);
|
|
24
|
+
return parsed.ok ? { ok: true, value: buildReferenceText(parsed.reference) } : wrongValue(parsed.problem);
|
|
25
|
+
}
|
|
16
26
|
function duration(value) {
|
|
17
27
|
return typeof value === "string" && parseDuration(value) !== undefined
|
|
18
28
|
? { ok: true, value }
|
|
@@ -35,10 +45,10 @@ const KIND = "testserverPool";
|
|
|
35
45
|
*/
|
|
36
46
|
export const testserverPoolConfig = {
|
|
37
47
|
name: NAME,
|
|
38
|
-
factory: { kind: KIND, call: "testserverPool({ … })", subpath: "@
|
|
48
|
+
factory: { kind: KIND, call: "testserverPool({ … })", subpath: "@vercel/storm/testserver" },
|
|
39
49
|
options: {
|
|
40
50
|
sandboxes: { check: sandboxCount, readText: readWholeNumberText, default: MIN_SANDBOXES },
|
|
41
|
-
build: { check:
|
|
51
|
+
build: { check: checkBuild, readText: readTextAsIs, default: "stable" },
|
|
42
52
|
minTimeLeft: { check: duration, readText: readTextAsIs, default: "30m" },
|
|
43
53
|
ttl: { check: ttl, readText: readTextAsIs, default: "5h" },
|
|
44
54
|
noCreate: { check: checkBoolean, readText: readBooleanText, default: false },
|
|
@@ -8,6 +8,9 @@ import type { BuildChannel } from "./sandbox/index.ts";
|
|
|
8
8
|
* entries on the channel as written.
|
|
9
9
|
* - `old-channel-resolution`: under `noCreate`, a build channel resolved from a channel resolution `ageMinutes`
|
|
10
10
|
* old, past the hour a run trusts one for.
|
|
11
|
+
* - `pr-build-resolved`: the `build` setting was the PR build reference `pr:<pr>`, and the run resolved it to `build`,
|
|
12
|
+
* the newest PR build made from the vercel/api pull request's head commit `headSha`; `merged` says whether the pull
|
|
13
|
+
* request has merged.
|
|
11
14
|
* - `leasing`: the run lists the pool on `match` and health-checks its free Testserver sandboxes, to lease up to
|
|
12
15
|
* `requested`.
|
|
13
16
|
* - `leased`: the pool's usable Testserver sandboxes were leased, up to `requested`.
|
|
@@ -26,6 +29,12 @@ export type TestserverPoolEvent = {
|
|
|
26
29
|
readonly channel: BuildChannel;
|
|
27
30
|
readonly build: string;
|
|
28
31
|
readonly ageMinutes: number;
|
|
32
|
+
} | {
|
|
33
|
+
readonly kind: "pr-build-resolved";
|
|
34
|
+
readonly pr: number;
|
|
35
|
+
readonly headSha: string;
|
|
36
|
+
readonly build: string;
|
|
37
|
+
readonly merged: boolean;
|
|
29
38
|
} | {
|
|
30
39
|
readonly kind: "leasing";
|
|
31
40
|
readonly match: BuildMatch;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
// The Testserver pool resource's folder: the Testserver control plane and health check (`sandbox/`), the pool of
|
|
2
|
-
// Testserver sandboxes (`pool/`),
|
|
3
|
-
//
|
|
4
|
-
//
|
|
2
|
+
// Testserver sandboxes (`pool/`), a vercel/api pull request's head commit and PR builds from GitHub and the host's
|
|
3
|
+
// GitHub token (`pull-request/`), its kind and run half, its events and its lane, its resource config, its command half
|
|
4
|
+
// with its settle, its cleanup and ran reports, its live gateways, how its errors and `pool create` report a credential
|
|
5
|
+
// source's failures, its sandbox counts, and the Testserver sandboxes a run holds. Its provider value
|
|
5
6
|
// (`resource-provider.ts`) carries them to the registry (`src/resources.ts`), the one place outside this folder that
|
|
6
|
-
// takes it; `@
|
|
7
|
-
// `sandbox/` and `
|
|
8
|
-
// this file: the registry and `src/config-file/`'s type-only import. Its own commands, `pool create` and
|
|
9
|
-
// `commands/`, which the registry mounts. The rest of what it exports is for tests.
|
|
7
|
+
// takes it; `@vercel/storm/testserver` is `resource.ts`.
|
|
8
|
+
// `sandbox/`, `pool/` and `pull-request/` keep their own `index.ts` for the files in this folder; everything outside it
|
|
9
|
+
// imports only this file: the registry and `src/config-file/`'s type-only import. Its own commands, `pool create` and
|
|
10
|
+
// `pool list`, are `commands/`, which the registry mounts. The rest of what it exports is for tests.
|
|
10
11
|
export { testserverPoolCleanupReport } from "./cleanup.js";
|
|
11
12
|
export { testserverPoolConfig } from "./config.js";
|
|
12
13
|
export { testserverPoolCanceledLines, testserverPoolCommand, testserverPoolPrepareErrors, testserverPoolRefusalErrors, } from "./command.js";
|
|
@@ -47,6 +47,7 @@ function applyTestserverEvent(testserver, event, at) {
|
|
|
47
47
|
// Resolving the build is part of the lane, but changes nothing it shows.
|
|
48
48
|
case "build-unresolved":
|
|
49
49
|
case "old-channel-resolution":
|
|
50
|
+
case "pr-build-resolved":
|
|
50
51
|
case "create-progress":
|
|
51
52
|
return testserver;
|
|
52
53
|
case "leasing":
|
|
@@ -2,5 +2,7 @@ import { type ResourceHost } from "../../../core/index.ts";
|
|
|
2
2
|
import type { TestserverPoolKind } from "../provider.ts";
|
|
3
3
|
/** The Testserver control plane's origin. */
|
|
4
4
|
export declare const TESTSERVER_ORIGIN = "https://testserver.vercel.sh";
|
|
5
|
+
/** GitHub's REST API origin. */
|
|
6
|
+
export declare const GITHUB_API_ORIGIN = "https://api.github.com";
|
|
5
7
|
/** The Testserver pool's gateways, live, for `host`. */
|
|
6
8
|
export declare function liveTestserverPoolGateways(host: ResourceHost): TestserverPoolKind["gateways"];
|
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
// The Testserver pool resource's live gateways, built from the host: the Testserver control plane at
|
|
2
|
-
// `testserver.vercel.sh`, with a 3-minute create and a 10-second `GET /builds`; 5-second
|
|
3
|
-
// under the host's `XDG_STATE_HOME` or `HOME`, or, when the host names no place for it, a pool
|
|
4
|
-
// fails and says why;
|
|
2
|
+
// `testserver.vercel.sh`, with a 3-minute create and a 10-second `GET /builds`; 5-second
|
|
3
|
+
// health checks; the pool under the host's `XDG_STATE_HOME` or `HOME`, or, when the host names no place for it, a pool
|
|
4
|
+
// whose every operation fails and says why; the system timer, which a create's retries wait on; GitHub's REST API at
|
|
5
|
+
// `api.github.com`, with a 10-second call and a 30-second job log download, for a pull request's head commit and the
|
|
6
|
+
// PR builds vercel/api's `Testserver` workflow published for it; and the host's GitHub token, from its `GITHUB_TOKEN`,
|
|
7
|
+
// `GH_TOKEN` or `gh auth token`.
|
|
5
8
|
import { resolveStateDirectory } from "../../../core/index.js";
|
|
6
9
|
import { systemTimer } from "../../../time/index.js";
|
|
7
10
|
import { livePoolStoreGateway, POOL_DIRECTORY_PATTERN, POOL_SUBPATH, unavailablePoolStoreGateway, } from "../pool/index.js";
|
|
11
|
+
import { liveGitHubTokenGateway, livePullRequestGateway, liveTestserverWorkflowGateway, } from "../pull-request/index.js";
|
|
8
12
|
import { liveControlPlaneGateway, liveHealthCheckGateway } from "../sandbox/index.js";
|
|
9
13
|
/** The Testserver control plane's origin. */
|
|
10
14
|
export const TESTSERVER_ORIGIN = "https://testserver.vercel.sh";
|
|
15
|
+
/** GitHub's REST API origin. */
|
|
16
|
+
export const GITHUB_API_ORIGIN = "https://api.github.com";
|
|
11
17
|
/** The Testserver pool's gateways, live, for `host`. */
|
|
12
18
|
export function liveTestserverPoolGateways(host) {
|
|
13
19
|
const directory = resolveStateDirectory(host.env, POOL_SUBPATH);
|
|
@@ -22,5 +28,12 @@ export function liveTestserverPoolGateways(host) {
|
|
|
22
28
|
? livePoolStoreGateway({ directory: directory.directory })
|
|
23
29
|
: unavailablePoolStoreGateway(POOL_DIRECTORY_PATTERN, directory.reason),
|
|
24
30
|
timer: systemTimer,
|
|
31
|
+
pullRequests: livePullRequestGateway({ origin: GITHUB_API_ORIGIN, timeoutMs: 10_000 }),
|
|
32
|
+
testserverWorkflow: liveTestserverWorkflowGateway({
|
|
33
|
+
origin: GITHUB_API_ORIGIN,
|
|
34
|
+
timeoutMs: 10_000,
|
|
35
|
+
logTimeoutMs: 30_000,
|
|
36
|
+
}),
|
|
37
|
+
githubToken: liveGitHubTokenGateway({ env: host.env }),
|
|
25
38
|
};
|
|
26
39
|
}
|
|
@@ -2,6 +2,7 @@ import type { CredentialFailure, CredentialSource } from "../../../credential/in
|
|
|
2
2
|
import { type BuildChannel, type BuildsFailure, type ControlPlaneGateway } from "../sandbox/index.ts";
|
|
3
3
|
import type { Clock } from "../../../time/index.ts";
|
|
4
4
|
import type { PoolStoreGateway } from "./gateways.ts";
|
|
5
|
+
import type { PrBuildResolution } from "./pull-request.ts";
|
|
5
6
|
/** How long a channel resolution is trusted without asking the Testserver control plane again. */
|
|
6
7
|
export declare const CHANNEL_RESOLUTION_TRUST_MINUTES = 60;
|
|
7
8
|
/**
|
|
@@ -30,6 +31,8 @@ export type UnresolvedChannelReason = {
|
|
|
30
31
|
* - `control-plane`: a build channel the Testserver control plane resolved just now (`GET /builds`).
|
|
31
32
|
* - `as-written`: a build channel that couldn't be resolved; pool entries are matched on it as their
|
|
32
33
|
* requested build instead, and the caller says why.
|
|
34
|
+
* - `pull-request`: a PR build reference, resolved to the newest PR build made from the pull request's head commit
|
|
35
|
+
* (`resolvePrBuild`), never from a channel resolution.
|
|
33
36
|
*/
|
|
34
37
|
export type BuildResolution = {
|
|
35
38
|
readonly kind: "named";
|
|
@@ -52,7 +55,7 @@ export type BuildResolution = {
|
|
|
52
55
|
readonly kind: "as-written";
|
|
53
56
|
readonly channel: BuildChannel;
|
|
54
57
|
readonly reason: UnresolvedChannelReason;
|
|
55
|
-
};
|
|
58
|
+
} | PrBuildResolution;
|
|
56
59
|
/** Which pool entries a run may lease: those on a resolved build, or, as a fallback, those requested as written. */
|
|
57
60
|
export type BuildMatch = {
|
|
58
61
|
readonly resolvedBuild: string;
|
|
@@ -60,7 +63,7 @@ export type BuildMatch = {
|
|
|
60
63
|
readonly requestedBuild: string;
|
|
61
64
|
};
|
|
62
65
|
/**
|
|
63
|
-
* Resolves `build
|
|
66
|
+
* Resolves `build`, a build or build channel; a PR build reference is `resolvePrBuild`'s. A build named directly resolves to itself. A build channel uses its channel resolution
|
|
64
67
|
* when that is less than an hour old; otherwise it gets a credential from `credential` and asks the Testserver
|
|
65
68
|
* control plane, and records what it learns. A failed record write is ignored: it costs only a later lookup.
|
|
66
69
|
* Reading the channel resolutions failing counts as having none.
|
|
@@ -2,7 +2,7 @@ import { isBuildChannel, resolveChannel, } from "../sandbox/index.js";
|
|
|
2
2
|
/** How long a channel resolution is trusted without asking the Testserver control plane again. */
|
|
3
3
|
export const CHANNEL_RESOLUTION_TRUST_MINUTES = 60;
|
|
4
4
|
/**
|
|
5
|
-
* Resolves `build
|
|
5
|
+
* Resolves `build`, a build or build channel; a PR build reference is `resolvePrBuild`'s. A build named directly resolves to itself. A build channel uses its channel resolution
|
|
6
6
|
* when that is less than an hour old; otherwise it gets a credential from `credential` and asks the Testserver
|
|
7
7
|
* control plane, and records what it learns. A failed record write is ignored: it costs only a later lookup.
|
|
8
8
|
* Reading the channel resolutions failing counts as having none.
|
|
@@ -25,10 +25,11 @@ export type PooledCreateOutcome = {
|
|
|
25
25
|
};
|
|
26
26
|
/**
|
|
27
27
|
* Creates one Testserver sandbox on `build` living `ttlMinutes` (see `createSandbox`) and adds it to the pool, its
|
|
28
|
-
* entry recording the TTL:
|
|
28
|
+
* entry recording the TTL and `requestedBuild`, the build setting as written: for a build or build channel the same
|
|
29
|
+
* as `build`, for a PR build reference `pr:<N>` while `build` is the PR build it resolved to. Free, or, with
|
|
29
30
|
* `lease`, leased to this process, the lease written before the entry so no other run sees it free. Its
|
|
30
31
|
* `createdAt` is the clock when the create started, which underestimates the time it has left. The entry is
|
|
31
|
-
* written first, as soon as the Testserver sandbox exists; then,
|
|
32
|
+
* written first, as soon as the Testserver sandbox exists; then, when `requestedBuild` is a build channel, the channel resolution
|
|
32
33
|
* the create showed is recorded. A failed channel record is ignored: it costs only a later lookup.
|
|
33
34
|
* `progress` hears the Testserver control plane's progress messages.
|
|
34
35
|
*
|
|
@@ -42,7 +43,10 @@ export declare function createPooledSandbox(context: {
|
|
|
42
43
|
readonly clock: Clock;
|
|
43
44
|
}, request: {
|
|
44
45
|
readonly credential: Credential;
|
|
46
|
+
/** The build the control plane creates on: a build or build channel. */
|
|
45
47
|
readonly build: string;
|
|
48
|
+
/** What the build setting asked for, which the pool entry records as its requested build. */
|
|
49
|
+
readonly requestedBuild: string;
|
|
46
50
|
readonly ttlMinutes: number;
|
|
47
51
|
readonly lease: boolean;
|
|
48
52
|
}, progress?: CreateProgress): Promise<PooledCreateOutcome>;
|
|
@@ -2,10 +2,11 @@ import { createSandbox, isBuildChannel, } from "../sandbox/index.js";
|
|
|
2
2
|
import { sandboxHost } from "./host.js";
|
|
3
3
|
/**
|
|
4
4
|
* Creates one Testserver sandbox on `build` living `ttlMinutes` (see `createSandbox`) and adds it to the pool, its
|
|
5
|
-
* entry recording the TTL:
|
|
5
|
+
* entry recording the TTL and `requestedBuild`, the build setting as written: for a build or build channel the same
|
|
6
|
+
* as `build`, for a PR build reference `pr:<N>` while `build` is the PR build it resolved to. Free, or, with
|
|
6
7
|
* `lease`, leased to this process, the lease written before the entry so no other run sees it free. Its
|
|
7
8
|
* `createdAt` is the clock when the create started, which underestimates the time it has left. The entry is
|
|
8
|
-
* written first, as soon as the Testserver sandbox exists; then,
|
|
9
|
+
* written first, as soon as the Testserver sandbox exists; then, when `requestedBuild` is a build channel, the channel resolution
|
|
9
10
|
* the create showed is recorded. A failed channel record is ignored: it costs only a later lookup.
|
|
10
11
|
* `progress` hears the Testserver control plane's progress messages.
|
|
11
12
|
*
|
|
@@ -29,15 +30,15 @@ export async function createPooledSandbox(context, request, progress = {}) {
|
|
|
29
30
|
logViewerUrl,
|
|
30
31
|
createdAt: startedAt.toISOString(),
|
|
31
32
|
ttlMinutes,
|
|
32
|
-
requestedBuild: request.
|
|
33
|
+
requestedBuild: request.requestedBuild,
|
|
33
34
|
resolvedBuild,
|
|
34
35
|
};
|
|
35
36
|
const leaseOptions = request.lease ? { lease: { startedAt: context.clock.now().toISOString() } } : {};
|
|
36
37
|
const added = await context.pool.addEntry(entry, leaseOptions);
|
|
37
38
|
if (!added.ok)
|
|
38
39
|
return { kind: "pool-write-failed", entry, failure: added.failure };
|
|
39
|
-
if (isBuildChannel(request.
|
|
40
|
-
await context.pool.writeChannelResolution(request.
|
|
40
|
+
if (isBuildChannel(request.requestedBuild))
|
|
41
|
+
await context.pool.writeChannelResolution(request.requestedBuild, {
|
|
41
42
|
build: resolvedBuild,
|
|
42
43
|
learnedAt: context.clock.now().toISOString(),
|
|
43
44
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { type BuildMatch, buildMatch, type BuildResolution, resolveBuild, type UnresolvedChannelReason, } from "./channels.ts";
|
|
2
|
+
export { buildTime, PR_BUILD_LIFETIME_MS, type PrBuildContext, type PrBuildOutcome, type PrBuildRefusal, type PrBuildResolution, resolvePrBuild, } from "./pull-request.ts";
|
|
2
3
|
export { createPooledSandbox, type PooledCreateOutcome } from "./create.ts";
|
|
3
4
|
export { POOL_DIRECTORY_PATTERN, POOL_SUBPATH } from "./directory.ts";
|
|
4
5
|
export type { ChannelResolution, DropOutcome, LeaseHolder, LeaseOutcome, LeaseRecord, ListedEntry, ObservedLease, PoolEntry, PoolListing, PoolStoreFailure, PoolStoreGateway, PoolStoreOperation, PoolStoreResult, ReclaimOutcome, ReleaseOutcome, UnreadableEntry, } from "./gateways.ts";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// The Testserver folder's `pool/` barrel, for the other files in `resources/testserver/`. Code outside that folder
|
|
2
2
|
// imports `resources/testserver/index.ts` instead.
|
|
3
3
|
export { buildMatch, resolveBuild, } from "./channels.js";
|
|
4
|
+
export { buildTime, PR_BUILD_LIFETIME_MS, resolvePrBuild, } from "./pull-request.js";
|
|
4
5
|
export { createPooledSandbox } from "./create.js";
|
|
5
6
|
export { POOL_DIRECTORY_PATTERN, POOL_SUBPATH } from "./directory.js";
|
|
6
7
|
export { sandboxHost } from "./host.js";
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { GitHubFailure, GitHubTokenGateway, GitHubTokenOrigin, PullRequestGateway, TestserverWorkflowGateway } from "../pull-request/index.ts";
|
|
2
|
+
import type { Clock } from "../../../time/index.ts";
|
|
3
|
+
/** How long the Testserver control plane creates Testserver sandboxes from a PR build after it was published. */
|
|
4
|
+
export declare const PR_BUILD_LIFETIME_MS: number;
|
|
5
|
+
/**
|
|
6
|
+
* Why a PR build reference couldn't be resolved.
|
|
7
|
+
*
|
|
8
|
+
* - `pull-request-unreadable`: the host has no GitHub token (`no-token`), or GitHub didn't give the pull request's head
|
|
9
|
+
* commit; `tokenOrigin` says where the token came from, when there was one.
|
|
10
|
+
* - `pr-builds-unlisted`: GitHub didn't give the runs of vercel/api's `Testserver` workflow on the pull request, or the
|
|
11
|
+
* PR build one of them published.
|
|
12
|
+
* - `pr-build-not-ready`: no run for the pull request's head commit has published a PR build; `newest` is the newest PR
|
|
13
|
+
* build a run for an older head commit published, if any.
|
|
14
|
+
* - `pr-build-expired`: the newest PR build of the head commit is past its `expiresAt`.
|
|
15
|
+
*/
|
|
16
|
+
export type PrBuildRefusal = {
|
|
17
|
+
readonly kind: "pull-request-unreadable";
|
|
18
|
+
readonly pr: number;
|
|
19
|
+
readonly failure: {
|
|
20
|
+
readonly kind: "no-token";
|
|
21
|
+
} | GitHubFailure;
|
|
22
|
+
readonly tokenOrigin?: GitHubTokenOrigin;
|
|
23
|
+
} | {
|
|
24
|
+
readonly kind: "pr-builds-unlisted";
|
|
25
|
+
readonly pr: number;
|
|
26
|
+
readonly failure: GitHubFailure;
|
|
27
|
+
} | {
|
|
28
|
+
readonly kind: "pr-build-not-ready";
|
|
29
|
+
readonly pr: number;
|
|
30
|
+
readonly headSha: string;
|
|
31
|
+
readonly newest: {
|
|
32
|
+
readonly build: string;
|
|
33
|
+
readonly headSha: string;
|
|
34
|
+
readonly createdAt: string;
|
|
35
|
+
} | undefined;
|
|
36
|
+
} | {
|
|
37
|
+
readonly kind: "pr-build-expired";
|
|
38
|
+
readonly pr: number;
|
|
39
|
+
readonly headSha: string;
|
|
40
|
+
readonly build: string;
|
|
41
|
+
readonly expiresAt: string;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* A PR build reference resolved: pull request `pr`'s head commit, the newest PR build made from it, and whether the
|
|
45
|
+
* pull request has merged.
|
|
46
|
+
*/
|
|
47
|
+
export interface PrBuildResolution {
|
|
48
|
+
readonly kind: "pull-request";
|
|
49
|
+
readonly pr: number;
|
|
50
|
+
readonly headSha: string;
|
|
51
|
+
readonly build: string;
|
|
52
|
+
readonly merged: boolean;
|
|
53
|
+
}
|
|
54
|
+
/** How resolving a PR build reference ended. */
|
|
55
|
+
export type PrBuildOutcome = {
|
|
56
|
+
readonly ok: true;
|
|
57
|
+
readonly resolution: PrBuildResolution;
|
|
58
|
+
} | {
|
|
59
|
+
readonly ok: false;
|
|
60
|
+
readonly refusal: PrBuildRefusal;
|
|
61
|
+
};
|
|
62
|
+
/** What resolving a PR build reference reads: GitHub, with the host's GitHub token, and the clock. */
|
|
63
|
+
export interface PrBuildContext {
|
|
64
|
+
readonly pullRequests: PullRequestGateway;
|
|
65
|
+
readonly testserverWorkflow: TestserverWorkflowGateway;
|
|
66
|
+
readonly githubToken: GitHubTokenGateway;
|
|
67
|
+
readonly clock: Clock;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Resolves the PR build reference `pr:<pr>` to the newest PR build made from the pull request's current head commit,
|
|
71
|
+
* from GitHub alone. In order, it:
|
|
72
|
+
*
|
|
73
|
+
* 1. finds a GitHub token on the host; with none it refuses (`pull-request-unreadable`, `no-token`);
|
|
74
|
+
* 2. reads the pull request's head commit and branch with it; a failure refuses (`pull-request-unreadable`);
|
|
75
|
+
* 3. lists the runs of vercel/api's `Testserver` workflow on that branch; a failure refuses (`pr-builds-unlisted`);
|
|
76
|
+
* 4. takes, of the runs for the head commit, newest first, the first whose `Bundle & Publish` job published a PR build
|
|
77
|
+
* of this pull request; reading one failing refuses (`pr-builds-unlisted`), and with none it refuses
|
|
78
|
+
* (`pr-build-not-ready`), naming the newest PR build of the up to 3 newest runs for older head commits;
|
|
79
|
+
* 5. refuses one published 7 days ago or more, by the time its name gives (`pr-build-expired`).
|
|
80
|
+
*
|
|
81
|
+
* GitHub's runs carry the head commit each was for, so the PR build is the head's however the workflow built it. It
|
|
82
|
+
* needs no credential: the Testserver control plane isn't asked. The GitHub token goes only to GitHub. It reads and
|
|
83
|
+
* writes no channel resolution: a PR build reference is resolved on every run.
|
|
84
|
+
*/
|
|
85
|
+
export declare function resolvePrBuild(context: PrBuildContext, request: {
|
|
86
|
+
readonly pr: number;
|
|
87
|
+
}): Promise<PrBuildOutcome>;
|
|
88
|
+
/** The UTC time a build's name starts with, `<YYYYMMDD>T<HHMMSS>Z__…`, as an ISO string; undefined without one. */
|
|
89
|
+
export declare function buildTime(name: string): string | undefined;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { TESTSERVER_REPO } from "../sandbox/index.js";
|
|
2
|
+
/** How long the Testserver control plane creates Testserver sandboxes from a PR build after it was published. */
|
|
3
|
+
export const PR_BUILD_LIFETIME_MS = 7 * 24 * 60 * 60 * 1000;
|
|
4
|
+
/** How many runs for older head commits a refusal reads, newest first, to name the newest PR build. */
|
|
5
|
+
const OLDER_RUNS_READ = 3;
|
|
6
|
+
/**
|
|
7
|
+
* Resolves the PR build reference `pr:<pr>` to the newest PR build made from the pull request's current head commit,
|
|
8
|
+
* from GitHub alone. In order, it:
|
|
9
|
+
*
|
|
10
|
+
* 1. finds a GitHub token on the host; with none it refuses (`pull-request-unreadable`, `no-token`);
|
|
11
|
+
* 2. reads the pull request's head commit and branch with it; a failure refuses (`pull-request-unreadable`);
|
|
12
|
+
* 3. lists the runs of vercel/api's `Testserver` workflow on that branch; a failure refuses (`pr-builds-unlisted`);
|
|
13
|
+
* 4. takes, of the runs for the head commit, newest first, the first whose `Bundle & Publish` job published a PR build
|
|
14
|
+
* of this pull request; reading one failing refuses (`pr-builds-unlisted`), and with none it refuses
|
|
15
|
+
* (`pr-build-not-ready`), naming the newest PR build of the up to 3 newest runs for older head commits;
|
|
16
|
+
* 5. refuses one published 7 days ago or more, by the time its name gives (`pr-build-expired`).
|
|
17
|
+
*
|
|
18
|
+
* GitHub's runs carry the head commit each was for, so the PR build is the head's however the workflow built it. It
|
|
19
|
+
* needs no credential: the Testserver control plane isn't asked. The GitHub token goes only to GitHub. It reads and
|
|
20
|
+
* writes no channel resolution: a PR build reference is resolved on every run.
|
|
21
|
+
*/
|
|
22
|
+
export async function resolvePrBuild(context, request) {
|
|
23
|
+
const { pr } = request;
|
|
24
|
+
const token = await context.githubToken.token();
|
|
25
|
+
if (token === undefined)
|
|
26
|
+
return { ok: false, refusal: { kind: "pull-request-unreadable", pr, failure: { kind: "no-token" } } };
|
|
27
|
+
const read = await context.pullRequests.head({ repo: TESTSERVER_REPO, number: pr, token: token.token });
|
|
28
|
+
if (!read.ok)
|
|
29
|
+
return {
|
|
30
|
+
ok: false,
|
|
31
|
+
refusal: { kind: "pull-request-unreadable", pr, failure: read.failure, tokenOrigin: token.origin },
|
|
32
|
+
};
|
|
33
|
+
const { headSha, headRef, merged } = read.head;
|
|
34
|
+
const listed = await context.testserverWorkflow.runs({ repo: TESTSERVER_REPO, branch: headRef, token: token.token });
|
|
35
|
+
if (!listed.ok)
|
|
36
|
+
return { ok: false, refusal: { kind: "pr-builds-unlisted", pr, failure: listed.failure } };
|
|
37
|
+
const published = (run) => publishedBuild(context, token.token, pr, run);
|
|
38
|
+
for (const run of listed.runs.filter((each) => each.headSha === headSha)) {
|
|
39
|
+
const found = await published(run);
|
|
40
|
+
if (!found.ok)
|
|
41
|
+
return { ok: false, refusal: { kind: "pr-builds-unlisted", pr, failure: found.failure } };
|
|
42
|
+
if (found.build === undefined)
|
|
43
|
+
continue;
|
|
44
|
+
const expiresAt = new Date(Date.parse(found.build.createdAt) + PR_BUILD_LIFETIME_MS).toISOString();
|
|
45
|
+
if (!(Date.parse(expiresAt) > context.clock.now().getTime()))
|
|
46
|
+
return {
|
|
47
|
+
ok: false,
|
|
48
|
+
refusal: { kind: "pr-build-expired", pr, headSha, build: found.build.name, expiresAt },
|
|
49
|
+
};
|
|
50
|
+
return { ok: true, resolution: { kind: "pull-request", pr, headSha, build: found.build.name, merged } };
|
|
51
|
+
}
|
|
52
|
+
let newest;
|
|
53
|
+
for (const run of listed.runs.filter((each) => each.headSha !== headSha).slice(0, OLDER_RUNS_READ)) {
|
|
54
|
+
const found = await published(run);
|
|
55
|
+
if (!found.ok)
|
|
56
|
+
return { ok: false, refusal: { kind: "pr-builds-unlisted", pr, failure: found.failure } };
|
|
57
|
+
if (found.build === undefined)
|
|
58
|
+
continue;
|
|
59
|
+
newest = { build: found.build.name, headSha: run.headSha, createdAt: found.build.createdAt };
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
return { ok: false, refusal: { kind: "pr-build-not-ready", pr, headSha, newest } };
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The PR build of pull request `pr` that `run` published, with when it was published: the time its name starts with,
|
|
66
|
+
* or, for a name without one, when the run started. A build another pull request's run published, from a branch of
|
|
67
|
+
* the same name in a fork, is none.
|
|
68
|
+
*/
|
|
69
|
+
async function publishedBuild(context, token, pr, run) {
|
|
70
|
+
const read = await context.testserverWorkflow.publishedBuild({ repo: TESTSERVER_REPO, runId: run.id, token });
|
|
71
|
+
if (!read.ok)
|
|
72
|
+
return read;
|
|
73
|
+
if (read.build === undefined || read.build.pr !== pr)
|
|
74
|
+
return { ok: true, build: undefined };
|
|
75
|
+
return { ok: true, build: { name: read.build.name, createdAt: buildTime(read.build.name) ?? run.createdAt } };
|
|
76
|
+
}
|
|
77
|
+
/** The UTC time a build's name starts with, `<YYYYMMDD>T<HHMMSS>Z__…`, as an ISO string; undefined without one. */
|
|
78
|
+
export function buildTime(name) {
|
|
79
|
+
const match = /^(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})(\d{2})Z__/.exec(name);
|
|
80
|
+
if (match === null)
|
|
81
|
+
return undefined;
|
|
82
|
+
const [, year, month, day, hour, minute, second] = match;
|
|
83
|
+
const time = new Date(`${year}-${month}-${day}T${hour}:${minute}:${second}.000Z`);
|
|
84
|
+
return Number.isNaN(time.getTime()) ? undefined : time.toISOString();
|
|
85
|
+
}
|