@adea-ai/app-framework-release-tools 0.5.0 → 0.7.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/README.md +17 -12
- package/dist/circleci/circleci-daily-workspace.js +473 -0
- package/dist/circleci/circleci-gitlab-qualification.js +103 -0
- package/dist/circleci/prepare-daily-workspace.js +155 -0
- package/dist/cli.js +3444 -797
- package/dist/index.js +2249 -565
- package/dist/release-tools-source.json +1 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -14,21 +14,26 @@ bun add -d @adea-ai/app-framework-release-tools
|
|
|
14
14
|
adea-release <command> [arguments]
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
-
| Command | What it does
|
|
18
|
-
| --------------------------- |
|
|
19
|
-
| `cut` | Cuts a release from the app's checkout
|
|
20
|
-
| `step` | Runs one release step
|
|
21
|
-
| `plan-assets` | Plans the assets of a release
|
|
22
|
-
| `
|
|
23
|
-
| `sign
|
|
24
|
-
| `
|
|
25
|
-
| `
|
|
26
|
-
| `
|
|
27
|
-
| `
|
|
28
|
-
| `
|
|
17
|
+
| Command | What it does |
|
|
18
|
+
| --------------------------- | ------------------------------------------------------------ |
|
|
19
|
+
| `cut` | Cuts a release from the app's checkout |
|
|
20
|
+
| `step` | Runs one release step |
|
|
21
|
+
| `plan-assets` | Plans the assets of a release |
|
|
22
|
+
| `build-linux-formats` | Builds private Linux format candidates from a signed archive |
|
|
23
|
+
| `sign` | Signs a release |
|
|
24
|
+
| `sign-descriptors` | Signs the release descriptors |
|
|
25
|
+
| `verify-macos-signing` | Checks a macOS build's signature |
|
|
26
|
+
| `publish` | Publishes a release once |
|
|
27
|
+
| `promote` | Promotes a release to another channel |
|
|
28
|
+
| `finalize` | Waits for the release to complete and finalizes its draft |
|
|
29
|
+
| `publish-framework-package` | Publishes the framework package to npm |
|
|
29
30
|
|
|
30
31
|
The framework's `release-*` bins run the same commands.
|
|
31
32
|
|
|
33
|
+
`build-linux-formats <source-sha> <repository> <run-id> <attempt> <daily|stable> <descriptor> <archive> <appimagetool> <runtime> <output>` reads `linux-format-build.json` from the exact source commit. That manifest names the tracked release config and versioned Linux policy; the policy supplies the renderer, package fields, and AppImage tool and runtime digests. All file arguments after the channel are absolute paths. The command verifies source object identities, descriptor signature and run identity, and extracts through the verified updater extractor before building. It emits private candidates and a receipt, not release authorization.
|
|
34
|
+
|
|
35
|
+
The caller must obtain the expected repository, source, run and attempt from a protected authority. Local `origin/main` ancestry is advisory: it does not authenticate the remote, rule out local grafts, or establish approval. Pin and independently qualify the builder image and its system tools, then complete the native lifecycle and batch gates before any publication. Historical releases without the tracked manifest need a separately authenticated policy-to-baseline binding; this command does not supply one.
|
|
36
|
+
|
|
32
37
|
## License
|
|
33
38
|
|
|
34
39
|
Apache-2.0
|
|
@@ -0,0 +1,473 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// ../../ci/circleci-daily-workspace.ts
|
|
3
|
+
import { constants } from "fs";
|
|
4
|
+
import { lstat, mkdtemp, open, rm, writeFile } from "fs/promises";
|
|
5
|
+
import { tmpdir } from "os";
|
|
6
|
+
import { isAbsolute, join, resolve } from "path";
|
|
7
|
+
|
|
8
|
+
// ../../ci/circleci-gitlab-qualification.ts
|
|
9
|
+
import { basename } from "path";
|
|
10
|
+
var project = "/projects/88944716";
|
|
11
|
+
var gitlab = "https://gitlab.com";
|
|
12
|
+
var sha = /^[0-9a-f]{40}$/;
|
|
13
|
+
var numeric = /^[1-9]\d{0,15}$/;
|
|
14
|
+
var limit = 2 * 1024 * 1024;
|
|
15
|
+
var products = { adea: 88672280, cortana: 88668306 };
|
|
16
|
+
function requireThat(ok, message) {
|
|
17
|
+
if (!ok)
|
|
18
|
+
throw new Error(message);
|
|
19
|
+
}
|
|
20
|
+
var record = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
21
|
+
var id = (value) => typeof value === "number" && Number.isSafeInteger(value) && value > 0;
|
|
22
|
+
async function qualifiedGitLabSource(input, get) {
|
|
23
|
+
requireThat(id(input.pipelineId) && sha.test(input.coordinatorSha) && sha.test(input.sourceSha) && Object.hasOwn(products, input.product), "Candidate requires an exact GitLab test pipeline, reviewed Test Suite commit, and product SHA");
|
|
24
|
+
const { pipelineId, coordinatorSha, sourceSha } = input;
|
|
25
|
+
const pipelinePath = project + "/pipelines/" + pipelineId;
|
|
26
|
+
const currentBranch = record(await get(project + "/repository/branches/main"));
|
|
27
|
+
requireThat(currentBranch.protected === true, "GitLab Test Suite main is not protected");
|
|
28
|
+
const pipeline = record(await get(pipelinePath));
|
|
29
|
+
requireThat(pipeline.id === pipelineId && pipeline.project_id === 88944716 && pipeline.ref === "main" && pipeline.sha === coordinatorSha && (pipeline.source === "schedule" || pipeline.source === "web") && pipeline.status === "success", "GitLab Test Suite pipeline is not an exact passing main run");
|
|
30
|
+
const jobs = await get(pipelinePath + "/jobs?per_page=100&include_retried=false");
|
|
31
|
+
requireThat(Array.isArray(jobs) && jobs.length < 100, "Incomplete GitLab pipeline jobs");
|
|
32
|
+
const requireJob = (name) => {
|
|
33
|
+
const matches = jobs.map(record).filter((job) => job.name === name);
|
|
34
|
+
requireThat(matches.length === 1, "Ambiguous GitLab evidence job: " + name);
|
|
35
|
+
const job = matches[0];
|
|
36
|
+
requireThat(id(job.id) && job.ref === "main" && job.status === "success" && job.allow_failure === false && record(job.commit).id === coordinatorSha && record(job.pipeline).id === pipelineId, "GitLab evidence job is not exact and successful: " + name);
|
|
37
|
+
return job.id;
|
|
38
|
+
};
|
|
39
|
+
const qualificationJob = requireJob("fleet-qualification");
|
|
40
|
+
const verdictJob = requireJob("fleet-verdict");
|
|
41
|
+
const report = record(await get(project + "/jobs/" + qualificationJob + "/artifacts/fleet-run.json"));
|
|
42
|
+
const projects = record(report.result).projects;
|
|
43
|
+
requireThat(report.schema === "adea-fleet-run/v1" && report.finalized === true && report.outcome === "passed" && Array.isArray(projects) && projects.length > 0 && projects.length <= 256, "GitLab fleet report is not finalized and passing");
|
|
44
|
+
const passed = new Map;
|
|
45
|
+
for (const entry of projects.map(record)) {
|
|
46
|
+
requireThat(id(entry.project_id) && !passed.has(entry.project_id) && entry.status === "reports_passed" && typeof entry.sha === "string" && sha.test(entry.sha) && record(entry.report).qualified_sha === entry.sha, "GitLab fleet report has an invalid or unsuccessful project");
|
|
47
|
+
passed.set(entry.project_id, entry.sha);
|
|
48
|
+
}
|
|
49
|
+
const productId = products[input.product];
|
|
50
|
+
const dependencies = record(report.fleet_dependencies)[String(productId)];
|
|
51
|
+
requireThat(Array.isArray(dependencies) && dependencies.every((dep) => id(dep) && passed.has(dep)), "GitLab fleet report does not qualify the product dependencies");
|
|
52
|
+
requireThat(passed.get(productId) === sourceSha, "GitLab fleet did not qualify this exact product SHA");
|
|
53
|
+
return { pipelineId, coordinatorSha, qualificationJob, verdictJob, productId, sourceSha };
|
|
54
|
+
}
|
|
55
|
+
async function boundedJson(response) {
|
|
56
|
+
requireThat(response.ok && response.body, "GitLab evidence GET did not succeed");
|
|
57
|
+
const reader = response.body.getReader();
|
|
58
|
+
const chunks = [];
|
|
59
|
+
let count = 0;
|
|
60
|
+
try {
|
|
61
|
+
for (;; ) {
|
|
62
|
+
const { done, value } = await reader.read();
|
|
63
|
+
if (done)
|
|
64
|
+
break;
|
|
65
|
+
count += value.byteLength;
|
|
66
|
+
requireThat(count <= limit, "GitLab evidence exceeded its byte limit");
|
|
67
|
+
chunks.push(value);
|
|
68
|
+
}
|
|
69
|
+
return JSON.parse(Buffer.concat(chunks, count).toString("utf8"));
|
|
70
|
+
} finally {
|
|
71
|
+
await reader.cancel().catch(() => {});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function gitlabGet(token) {
|
|
75
|
+
requireThat(/^[A-Za-z0-9._-]{1,512}$/.test(token), "Missing read-only GitLab evidence token");
|
|
76
|
+
return async (path) => {
|
|
77
|
+
try {
|
|
78
|
+
const response = await fetch(gitlab + "/api/v4" + path, {
|
|
79
|
+
method: "GET",
|
|
80
|
+
headers: { "PRIVATE-TOKEN": token },
|
|
81
|
+
redirect: "error",
|
|
82
|
+
signal: AbortSignal.timeout(20000)
|
|
83
|
+
});
|
|
84
|
+
return await boundedJson(response);
|
|
85
|
+
} catch {
|
|
86
|
+
throw new Error("Could not read exact GitLab evidence");
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
if (import.meta.main && /^circleci-gitlab-qualification\.(?:ts|js)$/.test(basename(process.argv[1] ?? ""))) {
|
|
91
|
+
try {
|
|
92
|
+
const [product, pipelineId, coordinatorSha, ...extra] = process.argv.slice(2);
|
|
93
|
+
requireThat(process.env.CI === "true" && process.env.CIRCLECI === "true" && process.env.GITLAB_CI !== "true" && process.env.CIRCLE_BRANCH === "main" && !process.env.CIRCLE_TAG && (product === "adea" || product === "cortana") && pipelineId && numeric.test(pipelineId) && coordinatorSha && !extra.length, "Usage on CircleCI main: circleci-gitlab-qualification adea|cortana <pipeline-id> <coordinator-sha>");
|
|
94
|
+
const input = {
|
|
95
|
+
pipelineId: Number(pipelineId),
|
|
96
|
+
coordinatorSha,
|
|
97
|
+
product,
|
|
98
|
+
sourceSha: process.env.CIRCLE_SHA1 ?? ""
|
|
99
|
+
};
|
|
100
|
+
console.log(JSON.stringify(await qualifiedGitLabSource(input, gitlabGet(process.env.GITLAB_EVIDENCE_TOKEN ?? ""))));
|
|
101
|
+
} catch (error) {
|
|
102
|
+
console.error(error instanceof Error ? error.message : "GitLab qualification could not be read");
|
|
103
|
+
process.exitCode = 1;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// ../../ci/circleci-candidate-event.ts
|
|
108
|
+
var eventTag = /^daily-candidate-p([1-9]\d{0,15})$/;
|
|
109
|
+
var sha2 = /^[0-9a-f]{40}$/;
|
|
110
|
+
var version = /^(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)$/;
|
|
111
|
+
var products2 = { adea: 88672280, cortana: 88668306 };
|
|
112
|
+
function record2(value) {
|
|
113
|
+
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
114
|
+
}
|
|
115
|
+
function identifyCandidateTag(tag) {
|
|
116
|
+
const match = eventTag.exec(tag);
|
|
117
|
+
const pipelineId = Number(match?.[1]);
|
|
118
|
+
if (!match || !Number.isSafeInteger(pipelineId))
|
|
119
|
+
return;
|
|
120
|
+
return { tag, pipelineId };
|
|
121
|
+
}
|
|
122
|
+
function candidateVersion(value) {
|
|
123
|
+
const fields = record2(value);
|
|
124
|
+
if (Object.keys(fields).length !== 4 || fields.schema !== "framework/daily-candidate/v1" || fields.product !== "adea" && fields.product !== "cortana" || typeof fields.coordinatorSha !== "string" || !sha2.test(fields.coordinatorSha) || typeof fields.version !== "string" || !version.test(fields.version))
|
|
125
|
+
throw new Error("Invalid tracked Daily candidate version file");
|
|
126
|
+
return {
|
|
127
|
+
product: fields.product,
|
|
128
|
+
coordinatorSha: fields.coordinatorSha,
|
|
129
|
+
releaseTag: "v" + fields.version
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
async function qualifyCandidateEvent(event, request, sourceSha, get) {
|
|
133
|
+
if (identifyCandidateTag(event.tag)?.pipelineId !== event.pipelineId)
|
|
134
|
+
throw new Error("Invalid Daily candidate wakeup");
|
|
135
|
+
const path = "/projects/" + products2[request.product];
|
|
136
|
+
const [main, tag] = await Promise.all([
|
|
137
|
+
get(path + "/repository/branches/main"),
|
|
138
|
+
get(path + "/repository/tags/" + encodeURIComponent(event.tag))
|
|
139
|
+
]);
|
|
140
|
+
if (record2(main).protected !== true || record2(record2(main).commit).id !== sourceSha || record2(tag).protected !== true || record2(tag).name !== event.tag || record2(record2(tag).commit).id !== sourceSha)
|
|
141
|
+
throw new Error("Daily candidate tag is not protected or does not target protected main HEAD");
|
|
142
|
+
return qualifiedGitLabSource({
|
|
143
|
+
pipelineId: event.pipelineId,
|
|
144
|
+
coordinatorSha: request.coordinatorSha,
|
|
145
|
+
product: request.product,
|
|
146
|
+
sourceSha
|
|
147
|
+
}, get);
|
|
148
|
+
}
|
|
149
|
+
async function qualifyLiveCandidateEvent(event, request, sourceSha, token) {
|
|
150
|
+
return qualifyCandidateEvent(event, request, sourceSha, gitlabGet(token));
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// ../../src/app/value-guards.ts
|
|
154
|
+
function isRecord(value) {
|
|
155
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
156
|
+
}
|
|
157
|
+
function hasExactOwnKeys(value, expected) {
|
|
158
|
+
const actual = Reflect.ownKeys(value);
|
|
159
|
+
return actual.length === expected.length && actual.every((key) => typeof key === "string" && expected.includes(key));
|
|
160
|
+
}
|
|
161
|
+
var UUID_SOURCE = /[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/.source;
|
|
162
|
+
var UUID = new RegExp(`^${UUID_SOURCE}$`, "i");
|
|
163
|
+
|
|
164
|
+
// ../../ci/daily-product-config.ts
|
|
165
|
+
var expansion = [
|
|
166
|
+
{ from: "macos-arm64", to: "macos-x64", os: "darwin", arch: "x64" },
|
|
167
|
+
{ from: "linux-x64", to: "linux-arm64", os: "linux", arch: "arm64" }
|
|
168
|
+
];
|
|
169
|
+
var legacy = ["macos-arm64", "windows-x64", "linux-x64"];
|
|
170
|
+
function invalid(detail) {
|
|
171
|
+
throw new Error("Invalid Daily candidate config: " + detail);
|
|
172
|
+
}
|
|
173
|
+
function asset(value, from, to) {
|
|
174
|
+
if (typeof value !== "string" || !/^[A-Za-z0-9_.{}-]+$/.test(value) || !value.includes("{tag}") || value.split(from).length !== 2)
|
|
175
|
+
return invalid("asset template for " + from);
|
|
176
|
+
return value.replace(from, to);
|
|
177
|
+
}
|
|
178
|
+
function keys(value, required) {
|
|
179
|
+
return isRecord(value) && hasExactOwnKeys(value, required);
|
|
180
|
+
}
|
|
181
|
+
function buildDailyProductConfig(base, policy) {
|
|
182
|
+
if (!isRecord(base) || base.dailyReleaseProfile !== undefined || !keys(base.platforms, legacy) || !isRecord(base.descriptors) || !isRecord(policy) || !hasExactOwnKeys(policy, [
|
|
183
|
+
"schema",
|
|
184
|
+
"profile",
|
|
185
|
+
"appId",
|
|
186
|
+
...Object.hasOwn(policy, "signing") ? ["signing"] : []
|
|
187
|
+
]) || policy.schema !== "framework/daily-product/v1" || policy.profile !== "desktop-v2" || typeof policy.appId !== "string" || base.appId !== policy.appId)
|
|
188
|
+
return invalid("legacy base or product binding");
|
|
189
|
+
const config = structuredClone(base);
|
|
190
|
+
if (Object.hasOwn(base, "dailyNativeSigning"))
|
|
191
|
+
return invalid("duplicate signing policy");
|
|
192
|
+
if (Object.hasOwn(policy, "signing")) {
|
|
193
|
+
const signing = policy.signing;
|
|
194
|
+
if (!keys(signing, ["macTeamId", "windowsCertificateSha256"]) || typeof signing.macTeamId !== "string" || !/^[A-Z0-9]{10}$/.test(signing.macTeamId) || typeof signing.windowsCertificateSha256 !== "string" || !/^[a-f0-9]{64}$/.test(signing.windowsCertificateSha256) || /^0+$/.test(signing.windowsCertificateSha256))
|
|
195
|
+
return invalid("reviewed public signer identifiers");
|
|
196
|
+
config.dailyNativeSigning = structuredClone(signing);
|
|
197
|
+
}
|
|
198
|
+
const platforms = config.platforms;
|
|
199
|
+
for (const name of legacy) {
|
|
200
|
+
const pair = platforms[name];
|
|
201
|
+
if (!Array.isArray(pair) || pair.length !== 2)
|
|
202
|
+
return invalid("platform pair for " + name);
|
|
203
|
+
for (const item of pair)
|
|
204
|
+
asset(item, name, name);
|
|
205
|
+
}
|
|
206
|
+
const windows = platforms["windows-x64"];
|
|
207
|
+
if (!windows[0]?.endsWith("-Setup.zip"))
|
|
208
|
+
return invalid("legacy Windows installer format");
|
|
209
|
+
windows[0] = windows[0].replace(/\.zip$/, ".exe");
|
|
210
|
+
for (const { from, to } of expansion)
|
|
211
|
+
platforms[to] = platforms[from].map((item) => asset(item, from, to));
|
|
212
|
+
if (config.commandArtifacts !== undefined) {
|
|
213
|
+
if (!isRecord(config.commandArtifacts))
|
|
214
|
+
return invalid("command artifact policy");
|
|
215
|
+
for (const artifact of Object.values(config.commandArtifacts)) {
|
|
216
|
+
if (!isRecord(artifact) || !keys(artifact.platforms, legacy))
|
|
217
|
+
return invalid("command artifact platform map");
|
|
218
|
+
const names = artifact.platforms;
|
|
219
|
+
for (const name of legacy)
|
|
220
|
+
asset(names[name], name, name);
|
|
221
|
+
for (const { from, to } of expansion)
|
|
222
|
+
names[to] = asset(names[from], from, to);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
const descriptors = config.descriptors;
|
|
226
|
+
const makeDiscovery = (channel) => {
|
|
227
|
+
const key = channel === "daily" ? "dailyDiscoveryAssets" : "stableDiscoveryAssets";
|
|
228
|
+
const names = config[key];
|
|
229
|
+
if (!Array.isArray(names) || !names.length || names.some((name) => typeof name !== "string"))
|
|
230
|
+
return invalid(channel + " discovery list");
|
|
231
|
+
const extra = [];
|
|
232
|
+
for (const { from, to, os, arch } of expansion) {
|
|
233
|
+
const originals = names.filter((name) => name.endsWith("-" + from + ".json"));
|
|
234
|
+
if (!originals.length)
|
|
235
|
+
return invalid("missing " + channel + " discovery for " + from);
|
|
236
|
+
for (const name of originals) {
|
|
237
|
+
const d = descriptors[name];
|
|
238
|
+
if (!isRecord(d) || d.channel !== channel || d.platform !== os || d.arch !== (from.endsWith("-arm64") ? "arm64" : "x64") || !Array.isArray(d.allowedPayloads) || !d.allowedPayloads.length)
|
|
239
|
+
return invalid("base descriptor " + name);
|
|
240
|
+
const copy = name.slice(0, -from.length - 5) + to + ".json";
|
|
241
|
+
if (Object.hasOwn(descriptors, copy))
|
|
242
|
+
return invalid("duplicate descriptor " + copy);
|
|
243
|
+
descriptors[copy] = {
|
|
244
|
+
...d,
|
|
245
|
+
platform: os,
|
|
246
|
+
arch,
|
|
247
|
+
allowedPayloads: d.allowedPayloads.map((item) => asset(item, from, to))
|
|
248
|
+
};
|
|
249
|
+
extra.push(copy);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
config[key] = [...names, ...extra];
|
|
253
|
+
return extra;
|
|
254
|
+
};
|
|
255
|
+
const extra = [...makeDiscovery("daily"), ...makeDiscovery("stable")];
|
|
256
|
+
if (!Array.isArray(config.releaseAssets) || config.releaseAssets.some((name) => typeof name !== "string") || new Set([...config.releaseAssets, ...extra]).size !== config.releaseAssets.length + extra.length)
|
|
257
|
+
return invalid("release assets");
|
|
258
|
+
return {
|
|
259
|
+
...config,
|
|
260
|
+
dailyReleaseProfile: "desktop-v2",
|
|
261
|
+
releaseAssets: [...config.releaseAssets, ...extra],
|
|
262
|
+
stablePlatforms: [...legacy, ...expansion.map((platform) => platform.to)]
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// ../../ci/circleci-daily-workspace.ts
|
|
267
|
+
var sha3 = /^[0-9a-f]{40}$/;
|
|
268
|
+
var uuid = /^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/;
|
|
269
|
+
var number = /^[1-9]\d{0,19}$/;
|
|
270
|
+
var name = /^[A-Za-z0-9][A-Za-z0-9._+-]{0,199}$/;
|
|
271
|
+
var worker = /^[a-z][a-z0-9-]{0,79}$/;
|
|
272
|
+
var tag = /^v(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)$/;
|
|
273
|
+
function requireThat2(ok, message) {
|
|
274
|
+
if (!ok)
|
|
275
|
+
throw new Error(message);
|
|
276
|
+
}
|
|
277
|
+
function object(v) {
|
|
278
|
+
return !!v && typeof v === "object" && !Array.isArray(v);
|
|
279
|
+
}
|
|
280
|
+
function exact(value, fields) {
|
|
281
|
+
return object(value) && Object.keys(value).length === fields.length && fields.every((f) => Object.hasOwn(value, f));
|
|
282
|
+
}
|
|
283
|
+
function circleRun(env, source, acceptedCandidateRef) {
|
|
284
|
+
const candidateRef = acceptedCandidateRef && identifyCandidateTag(acceptedCandidateRef);
|
|
285
|
+
requireThat2(env.CI === "true" && env.CIRCLECI === "true" && env.GITLAB_CI !== "true" && (env.CIRCLE_BRANCH === "main" && !env.CIRCLE_TAG && !acceptedCandidateRef || !env.CIRCLE_BRANCH && candidateRef && env.CIRCLE_TAG === candidateRef.tag) && sha3.test(source) && env.CIRCLE_SHA1 === source && uuid.test(env.CIRCLE_PROJECT_ID ?? "") && uuid.test(env.CIRCLE_PIPELINE_ID ?? "") && uuid.test(env.CIRCLE_WORKFLOW_ID ?? ""), "Candidate must run in CircleCI on the exact main checkout");
|
|
286
|
+
return {
|
|
287
|
+
project: env.CIRCLE_PROJECT_ID,
|
|
288
|
+
pipeline: env.CIRCLE_PIPELINE_ID,
|
|
289
|
+
workflow: env.CIRCLE_WORKFLOW_ID,
|
|
290
|
+
...candidateRef ? { candidateRef: candidateRef.tag } : {}
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
function createCircleDailyControl(env, source, releaseTag, acceptedCandidateRef) {
|
|
294
|
+
const run = circleRun(env, source, acceptedCandidateRef);
|
|
295
|
+
requireThat2(number.test(env.CIRCLE_BUILD_NUM ?? "") && tag.test(releaseTag), "Invalid candidate identity");
|
|
296
|
+
return {
|
|
297
|
+
schema: "framework/circleci-daily-control/v1",
|
|
298
|
+
run,
|
|
299
|
+
identity: {
|
|
300
|
+
tag: releaseTag,
|
|
301
|
+
sourceSha: source,
|
|
302
|
+
workflowSha: source,
|
|
303
|
+
runId: env.CIRCLE_BUILD_NUM,
|
|
304
|
+
runAttempt: 1
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
function readCircleDailyControl(value, env, source, releaseTag, acceptedCandidateRef) {
|
|
309
|
+
const run = circleRun(env, source, acceptedCandidateRef);
|
|
310
|
+
requireThat2(exact(value, ["schema", "run", "identity"]) && value.schema === "framework/circleci-daily-control/v1" && exact(value.run, run.candidateRef ? ["project", "pipeline", "workflow", "candidateRef"] : ["project", "pipeline", "workflow"]) && value.run.candidateRef === run.candidateRef && value.run.project === run.project && value.run.pipeline === run.pipeline && value.run.workflow === run.workflow && exact(value.identity, ["tag", "sourceSha", "workflowSha", "runId", "runAttempt"]) && value.identity.tag === releaseTag && tag.test(releaseTag) && value.identity.sourceSha === source && value.identity.workflowSha === source && typeof value.identity.runId === "string" && number.test(value.identity.runId) && value.identity.runAttempt === 1, "CircleCI candidate control is not from this workflow and source");
|
|
311
|
+
return value;
|
|
312
|
+
}
|
|
313
|
+
function circleDailyOwnership(matrix) {
|
|
314
|
+
requireThat2(object(matrix) && Array.isArray(matrix.assets) && matrix.assets.length > 0 && matrix.assets.length <= 256 && Array.isArray(matrix.checks) && matrix.checks.length > 0 && matrix.checks.length <= 56 && matrix.assets.every((n) => typeof n === "string" && name.test(n)) && new Set(matrix.assets).size === matrix.assets.length, "Invalid Daily matrix inventory");
|
|
315
|
+
const declared = new Set(matrix.assets);
|
|
316
|
+
const producers = new Map;
|
|
317
|
+
const receipts = new Map;
|
|
318
|
+
for (const check of matrix.checks) {
|
|
319
|
+
requireThat2(object(check) && typeof check.name === "string" && typeof check.platform === "string" && Array.isArray(check.assets) && check.assets.length > 0 && new Set(check.assets).size === check.assets.length, "Invalid Daily matrix check");
|
|
320
|
+
const receiptOwner = "verify-" + check.name;
|
|
321
|
+
const assetOwner = "candidate-" + check.platform;
|
|
322
|
+
requireThat2(worker.test(receiptOwner) && worker.test(assetOwner) && assetOwner !== "candidate-common" && !receipts.has(receiptOwner), "Invalid or duplicate Daily check owner");
|
|
323
|
+
receipts.set(receiptOwner, check.name + ".json");
|
|
324
|
+
for (const asset of check.assets) {
|
|
325
|
+
requireThat2(declared.has(asset), "Daily check names an undeclared artifact");
|
|
326
|
+
const prior = producers.get(asset);
|
|
327
|
+
requireThat2(!prior || prior === assetOwner, "Daily artifact has conflicting platform owners");
|
|
328
|
+
producers.set(asset, assetOwner);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
const groups = new Map;
|
|
332
|
+
const bucket = (owner) => {
|
|
333
|
+
if (!groups.has(owner))
|
|
334
|
+
groups.set(owner, { artifacts: [], receipts: [] });
|
|
335
|
+
return groups.get(owner);
|
|
336
|
+
};
|
|
337
|
+
for (const [owner, receipt] of receipts)
|
|
338
|
+
bucket(owner).receipts.push(receipt);
|
|
339
|
+
for (const asset of declared)
|
|
340
|
+
bucket(producers.get(asset) ?? "candidate-common").artifacts.push(asset);
|
|
341
|
+
requireThat2(groups.size <= 64, "Daily candidate exceeds workspace worker limit");
|
|
342
|
+
return { maxBytes: 64 * 1024 ** 3, workers: Object.fromEntries(groups) };
|
|
343
|
+
}
|
|
344
|
+
async function readJson(path) {
|
|
345
|
+
const input = await open(path, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
|
|
346
|
+
try {
|
|
347
|
+
const before = await input.stat();
|
|
348
|
+
requireThat2(before.isFile() && before.size > 0 && before.size <= 4096, "Invalid coordinator control");
|
|
349
|
+
const bytes = Buffer.alloc(before.size + 1);
|
|
350
|
+
let read = 0;
|
|
351
|
+
while (read < bytes.length) {
|
|
352
|
+
const { bytesRead } = await input.read(bytes, read, bytes.length - read, read);
|
|
353
|
+
if (!bytesRead)
|
|
354
|
+
break;
|
|
355
|
+
read += bytesRead;
|
|
356
|
+
}
|
|
357
|
+
const after = await input.stat();
|
|
358
|
+
requireThat2(read === before.size && after.size === before.size && after.ctimeMs === before.ctimeMs, "Candidate control changed while reading");
|
|
359
|
+
return JSON.parse(bytes.subarray(0, read).toString("utf8"));
|
|
360
|
+
} finally {
|
|
361
|
+
await input.close();
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
var childEnv = () => {
|
|
365
|
+
const keys = ["PATH", "TMPDIR", "TEMP", "SystemRoot", "WINDIR"];
|
|
366
|
+
return Object.fromEntries(keys.flatMap((key) => process.env[key] ? [[key, process.env[key]]] : []));
|
|
367
|
+
};
|
|
368
|
+
function mainOutput(argv, cwd, env = childEnv()) {
|
|
369
|
+
const result = Bun.spawnSync(argv, { cwd, env, stdout: "pipe", stderr: "pipe" });
|
|
370
|
+
requireThat2(result.exitCode === 0, "Daily coordinator could not read the exact checkout or matrix");
|
|
371
|
+
requireThat2(result.stdout.byteLength <= 256 * 1024, "Daily coordinator output too large");
|
|
372
|
+
return result.stdout.toString();
|
|
373
|
+
}
|
|
374
|
+
async function cli(args) {
|
|
375
|
+
const [mode, cliPath, checkout, configPath, controlPath, workspace, privateParent, ...extra] = args;
|
|
376
|
+
requireThat2(cliPath && checkout && configPath && controlPath && !extra.length && ((mode === "plan" || mode === "inspect" || mode === "render-config") && !workspace && !privateParent || mode === "prepare" && workspace && privateParent), "usage: circleci-daily-workspace plan|inspect|render-config|prepare <release-cli.js> <checkout> <relative-config.json> <control.json> [<worker-workspace> <private-parent>]");
|
|
377
|
+
const cwd = resolve(checkout);
|
|
378
|
+
requireThat2(!isAbsolute(configPath) && configPath.endsWith(".json") && configPath.split("/").every((p) => /^[A-Za-z0-9_-][A-Za-z0-9._-]*$/.test(p)), "Release config must be a tracked relative path");
|
|
379
|
+
const git = (...argv) => mainOutput(["git", "--no-replace-objects", "-c", "core.fsmonitor=false", ...argv], cwd, {
|
|
380
|
+
...childEnv(),
|
|
381
|
+
GIT_CONFIG_GLOBAL: "/dev/null",
|
|
382
|
+
GIT_CONFIG_NOSYSTEM: "1",
|
|
383
|
+
GIT_OPTIONAL_LOCKS: "0"
|
|
384
|
+
});
|
|
385
|
+
const source = git("rev-parse", "HEAD").trim();
|
|
386
|
+
const at = (path) => {
|
|
387
|
+
const entry = git("ls-tree", source, "--", path);
|
|
388
|
+
requireThat2(/^100(?:644|755) blob [0-9a-f]{40}\t/.test(entry) && entry.trimEnd().split("\t")[1] === path, "Release metadata must be a tracked regular file");
|
|
389
|
+
return git("show", source + ":" + path);
|
|
390
|
+
};
|
|
391
|
+
const preview = process.env.DAILY_CANDIDATE_PREVIEW === "true";
|
|
392
|
+
const event = preview ? identifyCandidateTag(process.env.CIRCLE_TAG ?? "") : undefined;
|
|
393
|
+
requireThat2(!preview || event, "Candidate preview must run on a non-public candidate tag");
|
|
394
|
+
const request = event ? candidateVersion(JSON.parse(at(".adea/daily-candidate.json"))) : undefined;
|
|
395
|
+
const releaseTag = request?.releaseTag ?? (() => {
|
|
396
|
+
const manifest = JSON.parse(at(".release-please-manifest.json"));
|
|
397
|
+
return "v" + (object(manifest) ? manifest["."] : "");
|
|
398
|
+
})();
|
|
399
|
+
const control = mode === "plan" ? createCircleDailyControl(process.env, source, releaseTag, event?.tag) : readCircleDailyControl(await readJson(resolve(controlPath)), process.env, source, releaseTag, event?.tag);
|
|
400
|
+
if (event && request && mode === "plan")
|
|
401
|
+
await qualifyLiveCandidateEvent(event, request, source, process.env.GITLAB_EVIDENCE_TOKEN ?? "");
|
|
402
|
+
const parent = mode === "prepare" ? resolve(privateParent) : tmpdir();
|
|
403
|
+
requireThat2((await lstat(parent)).isDirectory(), "Expected a private coordinator directory");
|
|
404
|
+
const context = await mkdtemp(join(parent, ".circleci-daily-"));
|
|
405
|
+
try {
|
|
406
|
+
const config = join(context, "config.json");
|
|
407
|
+
const raw = JSON.parse(at(configPath));
|
|
408
|
+
const policyFile = /(?:^|\/)daily-product\.json$/.test(configPath);
|
|
409
|
+
const candidate = policyFile ? buildDailyProductConfig(JSON.parse(at(configPath.replace(/daily-product\.json$/, "release-config.json"))), raw) : raw;
|
|
410
|
+
if (mode === "render-config") {
|
|
411
|
+
requireThat2(policyFile, "Rendering requires a tracked Daily product policy");
|
|
412
|
+
console.log(JSON.stringify(candidate));
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
await writeFile(config, JSON.stringify(candidate), { flag: "wx", mode: 384 });
|
|
416
|
+
const inventory = JSON.parse(mainOutput([
|
|
417
|
+
process.execPath,
|
|
418
|
+
"--no-env-file",
|
|
419
|
+
resolve(cliPath),
|
|
420
|
+
"daily-matrix",
|
|
421
|
+
"plan",
|
|
422
|
+
config,
|
|
423
|
+
releaseTag
|
|
424
|
+
], cwd));
|
|
425
|
+
const policy = circleDailyOwnership(inventory);
|
|
426
|
+
if (mode === "plan") {
|
|
427
|
+
await writeFile(resolve(controlPath), JSON.stringify(control) + `
|
|
428
|
+
`, {
|
|
429
|
+
flag: "wx",
|
|
430
|
+
mode: 384
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
if (mode !== "prepare") {
|
|
434
|
+
console.log(JSON.stringify({ identity: control.identity, ownership: policy }));
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
const identity = join(context, "identity.json");
|
|
438
|
+
const ownership = join(context, "ownership.json");
|
|
439
|
+
await writeFile(identity, JSON.stringify(control.identity), { flag: "wx", mode: 384 });
|
|
440
|
+
await writeFile(ownership, JSON.stringify(policy), {
|
|
441
|
+
flag: "wx",
|
|
442
|
+
mode: 384
|
|
443
|
+
});
|
|
444
|
+
const stage = join(import.meta.dir, import.meta.path.endsWith(".ts") ? "prepare-daily-workspace.ts" : "prepare-daily-workspace.js");
|
|
445
|
+
const result = Bun.spawnSync([
|
|
446
|
+
process.execPath,
|
|
447
|
+
"--no-env-file",
|
|
448
|
+
stage,
|
|
449
|
+
resolve(cliPath),
|
|
450
|
+
config,
|
|
451
|
+
identity,
|
|
452
|
+
resolve(workspace),
|
|
453
|
+
parent,
|
|
454
|
+
ownership
|
|
455
|
+
], { cwd, env: childEnv(), stdout: "inherit", stderr: "inherit" });
|
|
456
|
+
requireThat2(result.exitCode === 0, "CircleCI workspace did not qualify for staging");
|
|
457
|
+
} finally {
|
|
458
|
+
await rm(context, { recursive: true, force: true });
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
if (import.meta.main) {
|
|
462
|
+
try {
|
|
463
|
+
await cli(process.argv.slice(2));
|
|
464
|
+
} catch (error) {
|
|
465
|
+
console.error(error instanceof Error ? error.message : "Unable to prepare CircleCI workspace");
|
|
466
|
+
process.exitCode = 1;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
export {
|
|
470
|
+
circleDailyOwnership,
|
|
471
|
+
createCircleDailyControl,
|
|
472
|
+
readCircleDailyControl
|
|
473
|
+
};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// ../../ci/circleci-gitlab-qualification.ts
|
|
3
|
+
import { basename } from "path";
|
|
4
|
+
var project = "/projects/88944716";
|
|
5
|
+
var gitlab = "https://gitlab.com";
|
|
6
|
+
var sha = /^[0-9a-f]{40}$/;
|
|
7
|
+
var numeric = /^[1-9]\d{0,15}$/;
|
|
8
|
+
var limit = 2 * 1024 * 1024;
|
|
9
|
+
var products = { adea: 88672280, cortana: 88668306 };
|
|
10
|
+
function requireThat(ok, message) {
|
|
11
|
+
if (!ok)
|
|
12
|
+
throw new Error(message);
|
|
13
|
+
}
|
|
14
|
+
var record = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
15
|
+
var id = (value) => typeof value === "number" && Number.isSafeInteger(value) && value > 0;
|
|
16
|
+
async function qualifiedGitLabSource(input, get) {
|
|
17
|
+
requireThat(id(input.pipelineId) && sha.test(input.coordinatorSha) && sha.test(input.sourceSha) && Object.hasOwn(products, input.product), "Candidate requires an exact GitLab test pipeline, reviewed Test Suite commit, and product SHA");
|
|
18
|
+
const { pipelineId, coordinatorSha, sourceSha } = input;
|
|
19
|
+
const pipelinePath = project + "/pipelines/" + pipelineId;
|
|
20
|
+
const currentBranch = record(await get(project + "/repository/branches/main"));
|
|
21
|
+
requireThat(currentBranch.protected === true, "GitLab Test Suite main is not protected");
|
|
22
|
+
const pipeline = record(await get(pipelinePath));
|
|
23
|
+
requireThat(pipeline.id === pipelineId && pipeline.project_id === 88944716 && pipeline.ref === "main" && pipeline.sha === coordinatorSha && (pipeline.source === "schedule" || pipeline.source === "web") && pipeline.status === "success", "GitLab Test Suite pipeline is not an exact passing main run");
|
|
24
|
+
const jobs = await get(pipelinePath + "/jobs?per_page=100&include_retried=false");
|
|
25
|
+
requireThat(Array.isArray(jobs) && jobs.length < 100, "Incomplete GitLab pipeline jobs");
|
|
26
|
+
const requireJob = (name) => {
|
|
27
|
+
const matches = jobs.map(record).filter((job) => job.name === name);
|
|
28
|
+
requireThat(matches.length === 1, "Ambiguous GitLab evidence job: " + name);
|
|
29
|
+
const job = matches[0];
|
|
30
|
+
requireThat(id(job.id) && job.ref === "main" && job.status === "success" && job.allow_failure === false && record(job.commit).id === coordinatorSha && record(job.pipeline).id === pipelineId, "GitLab evidence job is not exact and successful: " + name);
|
|
31
|
+
return job.id;
|
|
32
|
+
};
|
|
33
|
+
const qualificationJob = requireJob("fleet-qualification");
|
|
34
|
+
const verdictJob = requireJob("fleet-verdict");
|
|
35
|
+
const report = record(await get(project + "/jobs/" + qualificationJob + "/artifacts/fleet-run.json"));
|
|
36
|
+
const projects = record(report.result).projects;
|
|
37
|
+
requireThat(report.schema === "adea-fleet-run/v1" && report.finalized === true && report.outcome === "passed" && Array.isArray(projects) && projects.length > 0 && projects.length <= 256, "GitLab fleet report is not finalized and passing");
|
|
38
|
+
const passed = new Map;
|
|
39
|
+
for (const entry of projects.map(record)) {
|
|
40
|
+
requireThat(id(entry.project_id) && !passed.has(entry.project_id) && entry.status === "reports_passed" && typeof entry.sha === "string" && sha.test(entry.sha) && record(entry.report).qualified_sha === entry.sha, "GitLab fleet report has an invalid or unsuccessful project");
|
|
41
|
+
passed.set(entry.project_id, entry.sha);
|
|
42
|
+
}
|
|
43
|
+
const productId = products[input.product];
|
|
44
|
+
const dependencies = record(report.fleet_dependencies)[String(productId)];
|
|
45
|
+
requireThat(Array.isArray(dependencies) && dependencies.every((dep) => id(dep) && passed.has(dep)), "GitLab fleet report does not qualify the product dependencies");
|
|
46
|
+
requireThat(passed.get(productId) === sourceSha, "GitLab fleet did not qualify this exact product SHA");
|
|
47
|
+
return { pipelineId, coordinatorSha, qualificationJob, verdictJob, productId, sourceSha };
|
|
48
|
+
}
|
|
49
|
+
async function boundedJson(response) {
|
|
50
|
+
requireThat(response.ok && response.body, "GitLab evidence GET did not succeed");
|
|
51
|
+
const reader = response.body.getReader();
|
|
52
|
+
const chunks = [];
|
|
53
|
+
let count = 0;
|
|
54
|
+
try {
|
|
55
|
+
for (;; ) {
|
|
56
|
+
const { done, value } = await reader.read();
|
|
57
|
+
if (done)
|
|
58
|
+
break;
|
|
59
|
+
count += value.byteLength;
|
|
60
|
+
requireThat(count <= limit, "GitLab evidence exceeded its byte limit");
|
|
61
|
+
chunks.push(value);
|
|
62
|
+
}
|
|
63
|
+
return JSON.parse(Buffer.concat(chunks, count).toString("utf8"));
|
|
64
|
+
} finally {
|
|
65
|
+
await reader.cancel().catch(() => {});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function gitlabGet(token) {
|
|
69
|
+
requireThat(/^[A-Za-z0-9._-]{1,512}$/.test(token), "Missing read-only GitLab evidence token");
|
|
70
|
+
return async (path) => {
|
|
71
|
+
try {
|
|
72
|
+
const response = await fetch(gitlab + "/api/v4" + path, {
|
|
73
|
+
method: "GET",
|
|
74
|
+
headers: { "PRIVATE-TOKEN": token },
|
|
75
|
+
redirect: "error",
|
|
76
|
+
signal: AbortSignal.timeout(20000)
|
|
77
|
+
});
|
|
78
|
+
return await boundedJson(response);
|
|
79
|
+
} catch {
|
|
80
|
+
throw new Error("Could not read exact GitLab evidence");
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
if (import.meta.main && /^circleci-gitlab-qualification\.(?:ts|js)$/.test(basename(process.argv[1] ?? ""))) {
|
|
85
|
+
try {
|
|
86
|
+
const [product, pipelineId, coordinatorSha, ...extra] = process.argv.slice(2);
|
|
87
|
+
requireThat(process.env.CI === "true" && process.env.CIRCLECI === "true" && process.env.GITLAB_CI !== "true" && process.env.CIRCLE_BRANCH === "main" && !process.env.CIRCLE_TAG && (product === "adea" || product === "cortana") && pipelineId && numeric.test(pipelineId) && coordinatorSha && !extra.length, "Usage on CircleCI main: circleci-gitlab-qualification adea|cortana <pipeline-id> <coordinator-sha>");
|
|
88
|
+
const input = {
|
|
89
|
+
pipelineId: Number(pipelineId),
|
|
90
|
+
coordinatorSha,
|
|
91
|
+
product,
|
|
92
|
+
sourceSha: process.env.CIRCLE_SHA1 ?? ""
|
|
93
|
+
};
|
|
94
|
+
console.log(JSON.stringify(await qualifiedGitLabSource(input, gitlabGet(process.env.GITLAB_EVIDENCE_TOKEN ?? ""))));
|
|
95
|
+
} catch (error) {
|
|
96
|
+
console.error(error instanceof Error ? error.message : "GitLab qualification could not be read");
|
|
97
|
+
process.exitCode = 1;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
export {
|
|
101
|
+
gitlabGet,
|
|
102
|
+
qualifiedGitLabSource
|
|
103
|
+
};
|