@rightkit/ci 0.0.0-stage → 0.2.43

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/manifest.mjs ADDED
@@ -0,0 +1,1862 @@
1
+ // Loader and hand-rolled validator for the per-repo `.rightgit.json` manifest.
2
+ // Mirrors the shape documented in manifest.schema.json. No ajv dependency —
3
+ // validation is plain JS so the package stays dependency-free (node builtins only).
4
+
5
+ import fs from "node:fs";
6
+ import path from "node:path";
7
+ import { validateCheckout } from "./checkout.mjs";
8
+
9
+ export const MANIFEST_FILENAME = ".rightgit.json";
10
+
11
+ export const KNOWN_LANES = Object.freeze([
12
+ "ci",
13
+ "qualification",
14
+ "package-smoke",
15
+ "release-candidate",
16
+ "publish-npm",
17
+ "publish-package-managers",
18
+ "regenerate",
19
+ ]);
20
+
21
+ // Rendered filename for each lane, installed under <repo>/.github/workflows/.
22
+ export const LANE_FILENAMES = Object.freeze({
23
+ ci: "ci.yml",
24
+ qualification: "qualification.yml",
25
+ "package-smoke": "package-smoke.yml",
26
+ "release-candidate": "release-candidate.yml",
27
+ "publish-npm": "publish-npm.yml",
28
+ "publish-package-managers": "publish-package-managers.yml",
29
+ regenerate: "regenerate.yml",
30
+ });
31
+
32
+ const PACKAGE_MANAGER_RE = /^(pnpm|npm|yarn)@\d+\.\d+\.\d+$/;
33
+ const TEMPLATE_VERSION_RE = /^\d+\.\d+\.\d+$/;
34
+
35
+ // F15 fix: every one of these fields is manifest (attacker-controlled)
36
+ // input that flows verbatim into a rendered workflow file via render.mjs's
37
+ // literal `${TOKEN}` substitution — render.mjs does no escaping, by design
38
+ // (it is a byte-deterministic template engine, not a YAML/expression-aware
39
+ // one). The re-validation proved a hostile `publish.homebrew.formulaName`
40
+ // containing GitHub Actions expression syntax (`${{ secrets.APPLE_... }}`)
41
+ // survived unmodified into rendered YAML, which GitHub Actions would then
42
+ // evaluate as a real expression — a workflow-expression injection, not just
43
+ // a cosmetic issue. The fix is at the INPUT boundary, not the render step:
44
+ // every manifest field that reaches a template must match a strict
45
+ // allowlist charset that cannot express `${{ }}`, backticks, `$()`,
46
+ // newlines, or any other shell/YAML/expression metacharacter — validated
47
+ // once here, so render.mjs can stay a dumb, deterministic string replacer.
48
+ const SAFE_MATRIX_VALUE_RE = /^[A-Za-z0-9][A-Za-z0-9._/*-]*$/;
49
+ const GITHUB_OWNER_RE = /^[A-Za-z0-9](?:[A-Za-z0-9-]{0,38})$/;
50
+ const GITHUB_REPO_RE = /^[A-Za-z0-9](?:[A-Za-z0-9._-]{0,99})$/;
51
+ const HOMEBREW_FORMULA_NAME_RE = /^[A-Za-z0-9][A-Za-z0-9+_.-]*$/;
52
+ const WINGET_PACKAGE_IDENTIFIER_RE = /^[A-Za-z0-9][A-Za-z0-9-]*(?:\.[A-Za-z0-9][A-Za-z0-9-]*)+$/;
53
+
54
+ const TOP_LEVEL_KEYS = new Set([
55
+ "schemaVersion",
56
+ "compile",
57
+ "lanes",
58
+ "matrix",
59
+ "packageManager",
60
+ "publish",
61
+ "templateVersion",
62
+ "profile",
63
+ "gate",
64
+ "rustCache",
65
+ "qaEvidencePath",
66
+ "qaEvidenceRetentionDays",
67
+ "ciAllOs",
68
+ "ciIncremental",
69
+ "concurrency",
70
+ "devArtifact",
71
+ "regenerate",
72
+ "candidate",
73
+ "ownership",
74
+ "swift",
75
+ "checkout",
76
+ "defaultBranch",
77
+ ]);
78
+ // Optional QA evidence upload (rust-hybrid ci only). qaEvidencePath is a safe
79
+ // relative path under $RUNNER_TEMP; it renders as `${{ runner.temp }}/<path>`.
80
+ const QA_EVIDENCE_DEFAULT_RETENTION_DAYS = 7;
81
+ const QA_EVIDENCE_MAX_RETENTION_DAYS = 90;
82
+ // Pinned to the same upload-artifact release the rust-hybrid release-candidate template uses.
83
+ const UPLOAD_ARTIFACT_PIN = "actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4";
84
+ const GATE_PATH_RE = /^(?!.*\.\.)(?!.*\s)[A-Za-z0-9][A-Za-z0-9._/-]*$/;
85
+ const RUST_WORKSPACE_PATH_RE = /^(?:\.|(?!.*\.\.)(?!.*\s)[A-Za-z0-9][A-Za-z0-9._/-]*)$/;
86
+ const PACKAGE_SCRIPT_RE = /^[A-Za-z0-9][A-Za-z0-9:_-]*$/;
87
+ const GITHUB_VARIABLE_RE = /^[A-Z][A-Z0-9_]*$/;
88
+ const RELEASE_PLATFORMS = new Set(["windows", "macos", "linux"]);
89
+ const RELEASE_ARCHITECTURES = new Set(["x86_64", "arm64"]);
90
+ const NATIVE_RUNNER_TARGETS = new Map([
91
+ ["windows-2025", ["windows", "x86_64"]],
92
+ ["windows-11-arm", ["windows", "arm64"]],
93
+ ["macos-15", ["macos", "arm64"]],
94
+ ["macos-15-intel", ["macos", "x86_64"]],
95
+ ]);
96
+
97
+ // Hosted `macos-*` runners plus the self-hosted Xcode runner labels (`xcode-27`).
98
+ const MACOS_RUNNER_RE = /^(macos|xcode)-/i;
99
+
100
+ function inferredTarget(os) {
101
+ const platform = /^windows-/i.test(os) ? "windows" : MACOS_RUNNER_RE.test(os) ? "macos" : "linux";
102
+ return { os, platform, architecture: platform === "macos" ? "arm64" : "x86_64" };
103
+ }
104
+
105
+ function candidateTargets(candidate) {
106
+ return Array.isArray(candidate?.targets) ? candidate.targets : (candidate?.os ?? []).map(inferredTarget);
107
+ }
108
+
109
+ /**
110
+ * Validate a parsed manifest object against the right-git manifest contract.
111
+ * Never throws. Returns { valid, errors }.
112
+ */
113
+ export function validateManifest(manifest) {
114
+ const errors = [];
115
+
116
+ if (manifest === null || typeof manifest !== "object" || Array.isArray(manifest)) {
117
+ return { valid: false, errors: ["manifest must be a JSON object"] };
118
+ }
119
+
120
+ for (const key of Object.keys(manifest)) {
121
+ if (!TOP_LEVEL_KEYS.has(key)) errors.push(`unknown top-level field: ${key}`);
122
+ }
123
+
124
+ if (manifest.schemaVersion !== 1) {
125
+ errors.push("schemaVersion must be exactly 1");
126
+ }
127
+ if (manifest.compile !== "github-actions-only") {
128
+ errors.push("compile must be exactly 'github-actions-only' for public repositories");
129
+ }
130
+
131
+ let lanes = [];
132
+ if (!Array.isArray(manifest.lanes) || manifest.lanes.length === 0) {
133
+ errors.push("lanes must be a non-empty array");
134
+ } else {
135
+ lanes = manifest.lanes;
136
+ const seen = new Set();
137
+ for (const lane of lanes) {
138
+ if (typeof lane !== "string" || !KNOWN_LANES.includes(lane)) {
139
+ errors.push(`unknown lane: ${JSON.stringify(lane)}`);
140
+ } else if (seen.has(lane)) {
141
+ errors.push(`duplicate lane: ${lane}`);
142
+ } else {
143
+ seen.add(lane);
144
+ }
145
+ }
146
+ }
147
+
148
+ if (manifest.matrix === null || typeof manifest.matrix !== "object" || Array.isArray(manifest.matrix)) {
149
+ errors.push("matrix must be an object with os and node arrays");
150
+ } else {
151
+ for (const field of ["os", "node"]) {
152
+ const value = manifest.matrix[field];
153
+ if (!Array.isArray(value) || value.length === 0 || !value.every((v) => typeof v === "string" && SAFE_MATRIX_VALUE_RE.test(v))) {
154
+ errors.push(
155
+ `matrix.${field} must be a non-empty array of safe runner/version labels (letters, digits, '.', '_', '-', '/', '*' only — no expression or shell syntax)`,
156
+ );
157
+ }
158
+ }
159
+ for (const key of Object.keys(manifest.matrix)) {
160
+ if (key !== "os" && key !== "node") errors.push(`unknown matrix field: ${key}`);
161
+ }
162
+ }
163
+
164
+ if (typeof manifest.packageManager !== "string" || !PACKAGE_MANAGER_RE.test(manifest.packageManager)) {
165
+ errors.push("packageManager must match '<pnpm|npm|yarn>@X.Y.Z'");
166
+ }
167
+
168
+ if (typeof manifest.templateVersion !== "string" || !TEMPLATE_VERSION_RE.test(manifest.templateVersion)) {
169
+ errors.push("templateVersion must be a semver string 'X.Y.Z'");
170
+ }
171
+
172
+ const profile = manifest.profile === undefined ? "node" : manifest.profile;
173
+ if (profile !== "node" && profile !== "rust-hybrid") errors.push("profile must be 'node' or 'rust-hybrid'");
174
+ if (profile === "rust-hybrid") {
175
+ if (lanes.some((lane) => lane !== "ci" && lane !== "release-candidate" && lane !== "regenerate") || !lanes.includes("ci")) {
176
+ errors.push("profile 'rust-hybrid' requires lane 'ci' and supports optional lanes 'release-candidate' and 'regenerate'");
177
+ }
178
+ if (!manifest.gate || typeof manifest.gate !== "object" || Array.isArray(manifest.gate) || Object.keys(manifest.gate).some((key) => key !== "path") || typeof manifest.gate.path !== "string" || !GATE_PATH_RE.test(manifest.gate.path)) {
179
+ errors.push("profile 'rust-hybrid' requires gate.path with a safe relative path");
180
+ }
181
+ } else if (manifest.gate !== undefined) {
182
+ errors.push("gate is only valid for profile 'rust-hybrid'");
183
+ }
184
+
185
+ validateCheckout(manifest.checkout, errors);
186
+ // defaultBranch: the branch the push triggers and the release-candidate admission use. Default "main".
187
+ if (manifest.defaultBranch !== undefined
188
+ && (typeof manifest.defaultBranch !== "string" || !/^[A-Za-z0-9][A-Za-z0-9._-]{0,99}$/.test(manifest.defaultBranch) || manifest.defaultBranch.includes(".."))) {
189
+ errors.push("defaultBranch must be one safe branch name (letters, digits, '.', '_', '-'; no '/', whitespace, '..' or expression syntax)");
190
+ }
191
+
192
+ if (manifest.qaEvidencePath !== undefined) {
193
+ if (profile !== "rust-hybrid") {
194
+ errors.push("qaEvidencePath is only valid for profile 'rust-hybrid'");
195
+ } else if (typeof manifest.qaEvidencePath !== "string" || !GATE_PATH_RE.test(manifest.qaEvidencePath)) {
196
+ errors.push("qaEvidencePath must be a safe relative path under $RUNNER_TEMP (no '..', whitespace, leading '/', or expression syntax)");
197
+ }
198
+ }
199
+ if (manifest.qaEvidenceRetentionDays !== undefined) {
200
+ if (manifest.qaEvidencePath === undefined) {
201
+ errors.push("qaEvidenceRetentionDays requires qaEvidencePath");
202
+ } else if (!Number.isInteger(manifest.qaEvidenceRetentionDays) || manifest.qaEvidenceRetentionDays < 1 || manifest.qaEvidenceRetentionDays > QA_EVIDENCE_MAX_RETENTION_DAYS) {
203
+ errors.push(`qaEvidenceRetentionDays must be an integer from 1 to ${QA_EVIDENCE_MAX_RETENTION_DAYS}`);
204
+ }
205
+ }
206
+
207
+ // ciAllOs (rust-hybrid ci only): run the gate on every matrix.os runner
208
+ // instead of one declared runner. Omitted or false keeps the single-runner ci job.
209
+ if (manifest.ciAllOs !== undefined) {
210
+ if (typeof manifest.ciAllOs !== "boolean") {
211
+ errors.push("ciAllOs must be a boolean");
212
+ } else if (manifest.ciAllOs === true && profile !== "rust-hybrid") {
213
+ errors.push("ciAllOs is only valid for profile 'rust-hybrid'");
214
+ }
215
+ }
216
+
217
+ // ciIncremental (rust-hybrid ci only): opt-in incremental Rust + DerivedData caching.
218
+ if (manifest.ciIncremental !== undefined) {
219
+ if (typeof manifest.ciIncremental !== "boolean") {
220
+ errors.push("ciIncremental must be a boolean");
221
+ } else if (manifest.ciIncremental === true && profile !== "rust-hybrid") {
222
+ errors.push("ciIncremental is only valid for profile 'rust-hybrid'");
223
+ }
224
+ }
225
+
226
+ if (manifest.concurrency !== undefined) validateConcurrency(manifest, lanes, errors);
227
+ validateDevArtifact(manifest, profile, errors);
228
+ validateRegenerate(manifest, lanes, errors);
229
+
230
+ const rustCache = manifest.rustCache;
231
+ if (rustCache !== undefined) {
232
+ if (profile !== "rust-hybrid") {
233
+ errors.push("rustCache is only valid for profile 'rust-hybrid'");
234
+ } else if (rustCache === null || typeof rustCache !== "object" || Array.isArray(rustCache)) {
235
+ errors.push("rustCache must be an object");
236
+ } else {
237
+ for (const key of Object.keys(rustCache)) {
238
+ if (!["workspaces", "requiredForGate", "keySuffix"].includes(key)) errors.push(`unknown rustCache field: ${key}`);
239
+ }
240
+ if (!Array.isArray(rustCache.workspaces) || rustCache.workspaces.length === 0) {
241
+ errors.push("rustCache.workspaces must be a non-empty array");
242
+ } else if (rustCache.workspaces.some((value) => typeof value !== "string" || !RUST_WORKSPACE_PATH_RE.test(value))) {
243
+ errors.push("rustCache.workspaces entries must be safe relative paths");
244
+ } else if (new Set(rustCache.workspaces).size !== rustCache.workspaces.length) {
245
+ errors.push("rustCache.workspaces entries must be unique");
246
+ }
247
+ if (rustCache.requiredForGate !== undefined && typeof rustCache.requiredForGate !== "boolean") {
248
+ errors.push("rustCache.requiredForGate must be a boolean");
249
+ }
250
+ if (rustCache.keySuffix !== undefined && (typeof rustCache.keySuffix !== "string" || !RUST_CACHE_KEY_SUFFIX_RE.test(rustCache.keySuffix))) {
251
+ errors.push("rustCache.keySuffix must be 1 to 64 characters: letters, digits, '.', '_', '-', starting with a letter or digit");
252
+ }
253
+ }
254
+ }
255
+
256
+ const candidate = manifest.candidate;
257
+ if (candidate !== undefined) {
258
+ if (candidate === null || typeof candidate !== "object" || Array.isArray(candidate)) {
259
+ errors.push("candidate must be an object");
260
+ } else {
261
+ for (const key of Object.keys(candidate)) {
262
+ if (!["buildScript", "checkScript", "admissionScript", "stageSummaryScript", "artifactRoot", "os", "targets", "signWindows", "signMacos", "releaseChain"].includes(key)) errors.push(`unknown candidate field: ${key}`);
263
+ }
264
+ // admissionScript & stageSummaryScript are required for EVERY release-candidate
265
+ // lane, not just signed/full-releaseChain ones: the tag-last workflow's
266
+ // `admission` job (dispatch-envelope validation) and the `candidate` job's
267
+ // stage-summary init/finalize steps are unconditional parts of the rendered
268
+ // template, independent of candidate.signWindows/signMacos/releaseChain. If
269
+ // either script were only required inside the optional releaseChain object,
270
+ // an unsigned release-candidate manifest (no releaseChain at all) would still
271
+ // render those unconditional steps with an unresolved script name.
272
+ for (const key of ["buildScript", "checkScript", "admissionScript", "stageSummaryScript"]) {
273
+ if (typeof candidate[key] !== "string" || !PACKAGE_SCRIPT_RE.test(candidate[key])) {
274
+ errors.push(`candidate.${key} must be one safe package script name`);
275
+ }
276
+ }
277
+ if (typeof candidate.artifactRoot !== "string" || !GATE_PATH_RE.test(candidate.artifactRoot)) {
278
+ errors.push("candidate.artifactRoot must be one safe relative path");
279
+ }
280
+ if (!Array.isArray(candidate.os) || candidate.os.length === 0 || candidate.os.some((value) => typeof value !== "string" || !SAFE_MATRIX_VALUE_RE.test(value))) {
281
+ errors.push("candidate.os must be a non-empty array of safe runner labels");
282
+ } else if (candidate.targets === undefined && candidate.os.some((value) => !manifest.matrix?.os?.includes(value))) {
283
+ errors.push("candidate.os entries must also exist in matrix.os");
284
+ }
285
+ if (candidate.targets !== undefined) {
286
+ if (!Array.isArray(candidate.targets) || candidate.targets.length === 0) {
287
+ errors.push("candidate.targets must be a non-empty array");
288
+ } else {
289
+ const targetKeys = new Set();
290
+ for (const target of candidate.targets) {
291
+ if (target === null || typeof target !== "object" || Array.isArray(target)) {
292
+ errors.push("candidate.targets entries must be objects");
293
+ continue;
294
+ }
295
+ if (Object.keys(target).some((key) => !["os", "platform", "architecture"].includes(key))) errors.push("candidate.targets entries may only contain os, platform, architecture");
296
+ if (typeof target.os !== "string" || !SAFE_MATRIX_VALUE_RE.test(target.os)) errors.push("candidate.targets[].os must be a safe runner label");
297
+ if (!RELEASE_PLATFORMS.has(target.platform)) errors.push("candidate.targets[].platform must be windows, macos, or linux");
298
+ if (!RELEASE_ARCHITECTURES.has(target.architecture)) errors.push("candidate.targets[].architecture must be x86_64 or arm64");
299
+ const nativeTarget = NATIVE_RUNNER_TARGETS.get(target.os);
300
+ if (nativeTarget && (target.platform !== nativeTarget[0] || target.architecture !== nativeTarget[1])) {
301
+ errors.push(`candidate.targets[] must declare ${target.os} as ${nativeTarget[0]}/${nativeTarget[1]}`);
302
+ }
303
+ if ((target.platform === "windows" && !/^windows-/i.test(target.os)) || (target.platform === "macos" && !MACOS_RUNNER_RE.test(target.os))) {
304
+ errors.push("candidate.targets[].os must match its Windows or macOS platform");
305
+ }
306
+ const targetKey = `${target.os}|${target.platform}|${target.architecture}`;
307
+ if (targetKeys.has(targetKey)) errors.push("candidate.targets entries must be unique");
308
+ targetKeys.add(targetKey);
309
+ }
310
+ const targetOs = new Set(candidate.targets.map((target) => target?.os));
311
+ if (candidate.os.some((os) => !targetOs.has(os)) || targetOs.size !== new Set(candidate.os).size || candidate.os.length !== new Set(candidate.os).size) {
312
+ errors.push("candidate.os must contain exactly candidate.targets runner labels");
313
+ }
314
+ }
315
+ }
316
+ const targets = candidateTargets(candidate);
317
+ if (candidate.signWindows !== undefined && typeof candidate.signWindows !== "boolean") {
318
+ errors.push("candidate.signWindows must be a boolean");
319
+ }
320
+ if (candidate.signWindows === true && targets.filter((target) => target?.platform === "windows").length === 0) {
321
+ errors.push("candidate.signWindows requires at least one Windows target");
322
+ }
323
+ if (candidate.signMacos !== undefined && typeof candidate.signMacos !== "boolean") {
324
+ errors.push("candidate.signMacos must be a boolean");
325
+ }
326
+ if (candidate.signMacos === true && targets.filter((target) => target?.platform === "macos").length === 0) {
327
+ errors.push("candidate.signMacos requires at least one macOS target");
328
+ }
329
+ if ((candidate.signWindows === true || candidate.signMacos === true) && manifest.matrix?.node?.length !== 1) {
330
+ errors.push("candidate signing requires exactly one matrix.node version");
331
+ }
332
+ if (candidate.releaseChain !== undefined) {
333
+ const chain = candidate.releaseChain;
334
+ // admissionScript & stageSummaryScript live on candidate directly (see
335
+ // above) — the full signed release chain adds evidenceVerificationScript
336
+ // (runs before publish, verifying aggregated same-run evidence) plus the
337
+ // finalize/qualify/publish scripts.
338
+ const allowedChainKeys = ["evidenceVerificationScript", "windowsFinalizeScript", "macosFinalizeScript", "installedQualificationScript", "publishScript", "qualificationRunnerVariable", "publishSecrets", "environments"];
339
+ if (chain === null || typeof chain !== "object" || Array.isArray(chain)) {
340
+ errors.push("candidate.releaseChain must be an object");
341
+ } else {
342
+ for (const key of Object.keys(chain)) {
343
+ if (!allowedChainKeys.includes(key)) errors.push(`unknown candidate.releaseChain field: ${key}`);
344
+ }
345
+ for (const key of ["evidenceVerificationScript", "windowsFinalizeScript", "installedQualificationScript", "publishScript"]) {
346
+ if (typeof chain[key] !== "string" || !PACKAGE_SCRIPT_RE.test(chain[key])) {
347
+ errors.push(`candidate.releaseChain.${key} must be one safe package script name`);
348
+ }
349
+ }
350
+ if (chain.macosFinalizeScript !== undefined && (typeof chain.macosFinalizeScript !== "string" || !PACKAGE_SCRIPT_RE.test(chain.macosFinalizeScript))) {
351
+ if (chain.environments !== undefined) {
352
+ const environments = chain.environments;
353
+ if (environments === null || typeof environments !== "object" || Array.isArray(environments)) {
354
+ errors.push("candidate.releaseChain.environments must be an object");
355
+ } else {
356
+ for (const key of Object.keys(environments)) {
357
+ if (!["signing", "qualification", "publication"].includes(key)) errors.push(`unknown candidate.releaseChain.environments field: ${key}`);
358
+ else if (typeof environments[key] !== "string" || !/^[A-Za-z0-9][A-Za-z0-9._-]{0,62}$/.test(environments[key])) {
359
+ errors.push(`candidate.releaseChain.environments.${key} must be one safe GitHub environment name`);
360
+ }
361
+ }
362
+ }
363
+ }
364
+ errors.push("candidate.releaseChain.macosFinalizeScript must be one safe package script name");
365
+ }
366
+ if (typeof chain.qualificationRunnerVariable !== "string" || !GITHUB_VARIABLE_RE.test(chain.qualificationRunnerVariable)) {
367
+ errors.push("candidate.releaseChain.qualificationRunnerVariable must be one uppercase GitHub variable name");
368
+ }
369
+ if (chain.publishSecrets !== undefined && (!Array.isArray(chain.publishSecrets) || new Set(chain.publishSecrets).size !== chain.publishSecrets.length || chain.publishSecrets.some((value) => typeof value !== "string" || !GITHUB_VARIABLE_RE.test(value)))) {
370
+ errors.push("candidate.releaseChain.publishSecrets must be unique uppercase GitHub secret names");
371
+ }
372
+ if (candidate.signWindows !== true) errors.push("candidate.releaseChain requires candidate.signWindows=true");
373
+ if (targets.filter((target) => target?.platform === "windows").length !== 1 || targets.filter((target) => target?.platform === "macos").length > 1) {
374
+ errors.push("candidate.releaseChain requires at most one target per signing platform; multi-target aggregation is not supported");
375
+ }
376
+ if (candidate.signMacos === true && !chain.macosFinalizeScript) errors.push("candidate.releaseChain with candidate.signMacos=true requires macosFinalizeScript");
377
+ if (chain.macosFinalizeScript && candidate.signMacos !== true) errors.push("candidate.releaseChain.macosFinalizeScript requires candidate.signMacos=true");
378
+ }
379
+ }
380
+ }
381
+ }
382
+ if (profile === "rust-hybrid" && lanes.includes("release-candidate") && candidate === undefined) {
383
+ errors.push("rust-hybrid release-candidate lane requires candidate { buildScript, checkScript, artifactRoot }");
384
+ }
385
+
386
+ if (manifest.ownership !== undefined) {
387
+ if (!manifest.ownership || typeof manifest.ownership !== "object" || Array.isArray(manifest.ownership)
388
+ || Object.keys(manifest.ownership).some((key) => key !== "roots")) {
389
+ errors.push("ownership must be an object containing only roots");
390
+ } else if (!Array.isArray(manifest.ownership.roots) || manifest.ownership.roots.length === 0
391
+ || manifest.ownership.roots.some((root) => typeof root !== "string" || (root !== "." && !/^(?!.*\.\.)(?!.*\\)(?!.*\s)[A-Za-z0-9][A-Za-z0-9._/-]*$/.test(root)) || root.startsWith("/"))) {
392
+ errors.push("ownership.roots must contain safe, non-empty repository-relative paths");
393
+ } else if (new Set(manifest.ownership.roots).size !== manifest.ownership.roots.length) {
394
+ errors.push("ownership.roots must not contain duplicates");
395
+ }
396
+ }
397
+ if (manifest.swift !== undefined) validateSwift(manifest, lanes, errors);
398
+ if (profile !== "rust-hybrid" && candidate !== undefined) {
399
+ errors.push("candidate is only valid for profile 'rust-hybrid'");
400
+ }
401
+
402
+ const publish = manifest.publish;
403
+ if (publish !== undefined) {
404
+ if (publish === null || typeof publish !== "object" || Array.isArray(publish)) {
405
+ errors.push("publish must be an object");
406
+ } else {
407
+ for (const key of Object.keys(publish)) {
408
+ if (!["npm", "homebrew", "winget"].includes(key)) errors.push(`unknown publish field: ${key}`);
409
+ }
410
+ if (publish.npm !== undefined) {
411
+ const npm = publish.npm;
412
+ if (npm === null || typeof npm !== "object") {
413
+ errors.push("publish.npm must be an object");
414
+ } else {
415
+ if (npm.oidc !== true) errors.push("publish.npm.oidc must be true (I2: OIDC is the only publish credential)");
416
+ if (typeof npm.provenance !== "boolean") errors.push("publish.npm.provenance must be a boolean");
417
+ }
418
+ }
419
+ if (publish.homebrew !== undefined) {
420
+ const hb = publish.homebrew;
421
+ if (hb === null || typeof hb !== "object") {
422
+ errors.push("publish.homebrew must be an object");
423
+ } else {
424
+ const tapMatch = typeof hb.tap === "string" ? /^([^/]+)\/([^/]+)$/.exec(hb.tap) : null;
425
+ if (!tapMatch || !GITHUB_OWNER_RE.test(tapMatch[1]) || !GITHUB_REPO_RE.test(tapMatch[2])) {
426
+ errors.push(
427
+ "publish.homebrew.tap must be 'owner/repo' using GitHub-safe characters only (letters, digits, '-', '_', '.' — no expression or shell syntax)",
428
+ );
429
+ }
430
+ if (typeof hb.formulaName !== "string" || !HOMEBREW_FORMULA_NAME_RE.test(hb.formulaName)) {
431
+ errors.push(
432
+ "publish.homebrew.formulaName must be a Homebrew-safe identifier (letters, digits, '+', '_', '.', '-' only — no expression or shell syntax)",
433
+ );
434
+ }
435
+ }
436
+ }
437
+ if (publish.winget !== undefined) {
438
+ const wg = publish.winget;
439
+ if (wg === null || typeof wg !== "object" || typeof wg.packageIdentifier !== "string" || !WINGET_PACKAGE_IDENTIFIER_RE.test(wg.packageIdentifier)) {
440
+ errors.push(
441
+ "publish.winget.packageIdentifier must be a dotted WinGet-safe identifier, e.g. 'Publisher.Package' (letters, digits, '-', '.' only — no expression or shell syntax)",
442
+ );
443
+ }
444
+ }
445
+ }
446
+ }
447
+
448
+ if (lanes.includes("publish-npm")) {
449
+ if (!publish || !publish.npm) {
450
+ errors.push("lane 'publish-npm' requires publish.npm { oidc: true, provenance }");
451
+ }
452
+ }
453
+
454
+ if (lanes.includes("publish-package-managers")) {
455
+ if (!publish || !publish.homebrew) {
456
+ errors.push("lane 'publish-package-managers' requires publish.homebrew { tap, formulaName }");
457
+ }
458
+ if (!publish || !publish.winget) {
459
+ errors.push("lane 'publish-package-managers' requires publish.winget { packageIdentifier }");
460
+ }
461
+ }
462
+
463
+ return { valid: errors.length === 0, errors };
464
+ }
465
+
466
+ /**
467
+ * Read and validate `<repoPath>/.rightgit.json`.
468
+ * Never throws — returns a typed result: { ok, manifest, errors, path }.
469
+ */
470
+ export function loadManifest(repoPath) {
471
+ const manifestPath = path.join(repoPath, MANIFEST_FILENAME);
472
+ let raw;
473
+ try {
474
+ raw = fs.readFileSync(manifestPath, "utf8");
475
+ } catch (error) {
476
+ return { ok: false, manifest: null, errors: [`cannot read ${manifestPath}: ${error.message}`], path: manifestPath };
477
+ }
478
+
479
+ let manifest;
480
+ try {
481
+ manifest = JSON.parse(raw);
482
+ } catch (error) {
483
+ return { ok: false, manifest: null, errors: [`invalid JSON in ${manifestPath}: ${error.message}`], path: manifestPath };
484
+ }
485
+
486
+ const { valid, errors } = validateManifest(manifest);
487
+ if (!valid) {
488
+ return { ok: false, manifest, errors, path: manifestPath };
489
+ }
490
+ return { ok: true, manifest, errors: [], path: manifestPath };
491
+ }
492
+
493
+ function parsePackageManager(spec) {
494
+ const match = /^(pnpm|npm|yarn)@(\d+\.\d+\.\d+)$/.exec(spec);
495
+ if (!match) throw new Error(`invalid packageManager spec: ${spec}`);
496
+ const [, name, version] = match;
497
+ const installCommand = {
498
+ pnpm: "pnpm install --frozen-lockfile",
499
+ npm: "npm ci",
500
+ yarn: "yarn install --frozen-lockfile",
501
+ }[name];
502
+ const runPrefix = { pnpm: "pnpm run", npm: "npm run", yarn: "yarn run" }[name];
503
+ const setup = {
504
+ pnpm: ` - uses: pnpm/action-setup@0977fd99725f1db4007ccb2928dbb4e90d06cc86 # v6.0.10\n with:\n version: ${version}`,
505
+ npm: "",
506
+ yarn: ` - run: corepack enable && corepack prepare yarn@${version} --activate`,
507
+ }[name];
508
+ return { name, version, installCommand, runPrefix, setup };
509
+ }
510
+
511
+ function yamlFlowStringList(values) {
512
+ return `[${values.map((v) => JSON.stringify(String(v))).join(", ")}]`;
513
+ }
514
+
515
+ function candidateMatrix(manifest) {
516
+ const entries = [];
517
+ for (const target of candidateTargets(manifest.candidate ?? { os: manifest.matrix.os })) {
518
+ for (const node of manifest.matrix.node) entries.push({ ...target, node, targetTriple: targetTriple(target) });
519
+ }
520
+ return [
521
+ " include:",
522
+ ...entries.flatMap((entry) => [
523
+ ` - os: ${JSON.stringify(entry.os)}`,
524
+ ` node: ${JSON.stringify(entry.node)}`,
525
+ ` platform: ${JSON.stringify(entry.platform)}`,
526
+ ` architecture: ${JSON.stringify(entry.architecture)}`,
527
+ ` targetTriple: ${JSON.stringify(entry.targetTriple)}`,
528
+ ]),
529
+ ].join("\n");
530
+ }
531
+
532
+ function targetTriple(target) {
533
+ const rustArchitecture = target.architecture === "arm64" ? "aarch64" : target.architecture;
534
+ if (target.platform === "windows") return `${rustArchitecture}-pc-windows-msvc`;
535
+ if (target.platform === "macos") return `${rustArchitecture}-apple-darwin`;
536
+ return `${rustArchitecture}-unknown-linux-gnu`;
537
+ }
538
+
539
+ function signingMatrix(manifest, platform) {
540
+ const node = String(manifest.matrix.node[0]);
541
+ const entries = candidateTargets(manifest.candidate)
542
+ .filter((target) => target.platform === platform)
543
+ .map((target) => ({ ...target, node, targetTriple: targetTriple(target) }));
544
+ return [
545
+ " include:",
546
+ ...entries.flatMap((entry) => [
547
+ ` - os: ${JSON.stringify(entry.os)}`,
548
+ ` platform: ${JSON.stringify(entry.platform)}`,
549
+ ` architecture: ${JSON.stringify(entry.architecture)}`,
550
+ ` targetTriple: ${JSON.stringify(entry.targetTriple)}`,
551
+ ` node: ${JSON.stringify(entry.node)}`,
552
+ ]),
553
+ ].join("\n");
554
+ }
555
+
556
+ const AZURE_LOGIN_SHA = "7ddb5af1ef8758cf1353cf3b42f940aee27ba21c"; // v3
557
+ const DOWNLOAD_ARTIFACT_SHA = "d3f86a106a0bac45b974a628896c90dbdf5c8093"; // v4.3.0
558
+ const UPLOAD_ARTIFACT_SHA = "ea165f8d65b6e75b540449e92b4886f43607fa02"; // v4
559
+ const ARTIFACT_SIGNING_CLIENT_VERSION = "1.0.128";
560
+ const ARTIFACT_SIGNING_CLIENT_SHA256 = "74BD7D27E6CE1051409C38D9B46BC8DF0400ECD643D51FFBF2AC00869061E40B";
561
+ const WINDOWS_SDK_BUILD_TOOLS_VERSION = "10.0.26100.4188";
562
+ const WINDOWS_SDK_BUILD_TOOLS_SHA256 = "180DEB372659029864C10A0C04787833234D64AACD1D2C0661D2C00295D8E022";
563
+
564
+ // Signing and publication credentials must be reachable behind distinct
565
+ // protected environments, so a job that may sign cannot also publish. Products
566
+ // opt in per environment; absent configuration keeps the single `release`
567
+ // environment they use today, so enabling the split cannot strand secrets.
568
+ function releaseEnvironment(manifest, role) {
569
+ const configured = manifest?.candidate?.releaseChain?.environments?.[role];
570
+ return typeof configured === "string" && configured.length > 0 ? configured : "release";
571
+ }
572
+
573
+ // Dev artifacts (rust-hybrid ci only): fast, non-release builds on push to the default branch.
574
+ const DEV_ARTIFACT_DEFAULT_RETENTION_DAYS = 7;
575
+ const DEV_ARTIFACT_MAX_RETENTION_DAYS = 90;
576
+ const DEV_MAC_PATH_RE = /^(?!.*\.\.)[A-Za-z0-9][A-Za-z0-9._/ -]*$/;
577
+ const DEV_WINDOWS_GLOB_RE = /^(?!.*\.\.)[A-Za-z0-9][A-Za-z0-9._/*?-]*$/;
578
+ const CACHE_ACTION_PIN = "actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4";
579
+
580
+ function effectiveCiRunners(manifest) {
581
+ const os = manifest.matrix?.os;
582
+ if (!Array.isArray(os) || os.length === 0) return [];
583
+ if (manifest.ciAllOs === true) return os;
584
+ return [os.find((runner) => typeof runner === "string" && runner.startsWith("windows-")) ?? os[0]];
585
+ }
586
+
587
+ // The regenerate lane is manual-only: it runs `regenerate.script`, checks the
588
+ // result, and opens a pull request from a right-git/regenerate-<run> branch.
589
+ // It never writes to the default branch.
590
+ function validateRegenerate(manifest, lanes, errors) {
591
+ const regenerate = manifest.regenerate;
592
+ const hasLane = Array.isArray(lanes) && lanes.includes("regenerate");
593
+ if (regenerate === undefined) {
594
+ if (hasLane) errors.push("lane 'regenerate' requires regenerate { script }");
595
+ return;
596
+ }
597
+ if (regenerate === null || typeof regenerate !== "object" || Array.isArray(regenerate)) {
598
+ errors.push("regenerate must be an object");
599
+ return;
600
+ }
601
+ if (!hasLane) errors.push("regenerate requires lane 'regenerate'");
602
+ for (const key of Object.keys(regenerate)) {
603
+ if (key !== "script") errors.push(`unknown regenerate field: ${key}`);
604
+ }
605
+ if (typeof regenerate.script !== "string" || !PACKAGE_SCRIPT_RE.test(regenerate.script)) {
606
+ errors.push("regenerate.script must be a package.json script name (letters, digits, ':', '_', '-')");
607
+ }
608
+ }
609
+
610
+ // swift.privatePackages (ci, qualification, release-candidate and regenerate lanes;
611
+ // the parallel dev-artifact-mac job): read access to private Swift package
612
+ // mirrors from a public repository's CI. The secret is a GitHub Actions secret
613
+ // name; the token value never appears in the rendered workflow.
614
+ const SWIFT_PRIVATE_MAX_ENTRIES = 4;
615
+ // Lanes whose workflows carry the configure and cleanup steps. package-smoke,
616
+ // publish-npm and publish-package-managers never do (clean-room or credentialed jobs).
617
+ const SWIFT_PRIVATE_LANES = ["ci", "qualification", "release-candidate", "regenerate"];
618
+ const SWIFT_PRIVATE_HOST_RE = /^[A-Za-z0-9](?:[A-Za-z0-9-]{0,62})(?:\.[A-Za-z0-9](?:[A-Za-z0-9-]{0,62}))*$/;
619
+
620
+ function isSwiftPrivateSecretName(value) {
621
+ return typeof value === "string" && /^[A-Za-z_][A-Za-z0-9_]{0,99}$/.test(value) && !/^github_/i.test(value);
622
+ }
623
+
624
+ function validateSwift(manifest, lanes, errors) {
625
+ const swift = manifest.swift;
626
+ if (swift === null || typeof swift !== "object" || Array.isArray(swift)) {
627
+ errors.push("swift must be an object");
628
+ return;
629
+ }
630
+ for (const key of Object.keys(swift)) {
631
+ if (key !== "privatePackages") errors.push(`unknown swift field: ${key}`);
632
+ }
633
+ const entries = swift.privatePackages;
634
+ if (!Array.isArray(entries) || entries.length === 0 || entries.length > SWIFT_PRIVATE_MAX_ENTRIES) {
635
+ errors.push(`swift.privatePackages must be an array of 1 to ${SWIFT_PRIVATE_MAX_ENTRIES} { host, secret } entries`);
636
+ return;
637
+ }
638
+ const hosts = new Set();
639
+ entries.forEach((entry, index) => {
640
+ if (entry === null || typeof entry !== "object" || Array.isArray(entry) || Object.keys(entry).some((key) => key !== "host" && key !== "secret")) {
641
+ errors.push(`swift.privatePackages[${index}] must be an object with only host and secret`);
642
+ return;
643
+ }
644
+ if (typeof entry.host !== "string" || !SWIFT_PRIVATE_HOST_RE.test(entry.host)) {
645
+ errors.push(`swift.privatePackages[${index}].host must be a bare host name such as github.com`);
646
+ } else if (hosts.has(entry.host)) {
647
+ errors.push(`swift.privatePackages host must be unique: ${entry.host}`);
648
+ } else {
649
+ hosts.add(entry.host);
650
+ }
651
+ if (!isSwiftPrivateSecretName(entry.secret)) {
652
+ errors.push(`swift.privatePackages[${index}].secret must be a GitHub Actions secret name (letters, digits, '_'; not starting with a digit or GITHUB_)`);
653
+ }
654
+ });
655
+ if (!Array.isArray(lanes) || !lanes.some((lane) => SWIFT_PRIVATE_LANES.includes(lane))) {
656
+ errors.push(`swift.privatePackages requires one of the lanes ${SWIFT_PRIVATE_LANES.map((lane) => `'${lane}'`).join(", ")} (the steps render into those workflows)`);
657
+ }
658
+ // Dispatched runs of ci.yml can come from any ref; the private-package secret must never reach one.
659
+ if (manifest.devArtifact?.dispatch === true) {
660
+ errors.push("swift.privatePackages cannot be combined with devArtifact.dispatch: a manual dispatch of any ref would reach the secret");
661
+ }
662
+ }
663
+
664
+ function validateDevArtifact(manifest, profile, errors) {
665
+ const dev = manifest.devArtifact;
666
+ if (dev === undefined) return;
667
+ if (profile !== "rust-hybrid") {
668
+ errors.push("devArtifact is only valid for profile 'rust-hybrid'");
669
+ return;
670
+ }
671
+ if (dev === null || typeof dev !== "object" || Array.isArray(dev)) {
672
+ errors.push("devArtifact must be an object");
673
+ return;
674
+ }
675
+ for (const key of Object.keys(dev)) {
676
+ if (!["mac", "windows", "retentionDays", "macAppPath", "macEntitlements", "windowsGlob", "dispatch", "parallel", "buildScript"].includes(key)) errors.push(`unknown devArtifact field: ${key}`);
677
+ }
678
+ if (dev.mac !== undefined && !["sign", "notarize", "unsigned", "none"].includes(dev.mac)) errors.push("devArtifact.mac must be 'sign', 'notarize', 'unsigned' or 'none'");
679
+ if (dev.windows !== undefined && dev.windows !== "unsigned" && dev.windows !== "none") errors.push("devArtifact.windows must be 'unsigned' or 'none'");
680
+ const macSigned = dev.mac === "sign" || dev.mac === "notarize";
681
+ const macActive = macSigned || dev.mac === "unsigned";
682
+ if (!macActive && dev.windows !== "unsigned") errors.push("devArtifact requires mac 'sign'/'unsigned' and/or windows 'unsigned'");
683
+ if (dev.dispatch !== undefined && dev.dispatch !== true) errors.push("devArtifact.dispatch must be true when present");
684
+ if (dev.dispatch === true && dev.mac !== "unsigned" && dev.windows !== "unsigned") {
685
+ errors.push("devArtifact.dispatch builds only unsigned legs; declare mac 'unsigned' and/or windows 'unsigned'");
686
+ }
687
+ if (dev.retentionDays !== undefined && (!Number.isInteger(dev.retentionDays) || dev.retentionDays < 1 || dev.retentionDays > DEV_ARTIFACT_MAX_RETENTION_DAYS)) {
688
+ errors.push(`devArtifact.retentionDays must be an integer from 1 to ${DEV_ARTIFACT_MAX_RETENTION_DAYS}`);
689
+ }
690
+ if (dev.parallel !== undefined && typeof dev.parallel !== "boolean") errors.push("devArtifact.parallel must be a boolean");
691
+ if (dev.buildScript !== undefined && dev.parallel !== true) errors.push("devArtifact.buildScript requires devArtifact.parallel: true");
692
+ if (dev.parallel === true && (typeof dev.buildScript !== "string" || !PACKAGE_SCRIPT_RE.test(dev.buildScript))) {
693
+ errors.push("devArtifact.buildScript must be one safe package script name when parallel is true (it compiles the dev app in the dev-artifact job)");
694
+ }
695
+ // parallel jobs run on their own platform runners, so they do not depend on ciAllOs.
696
+ const runners = (dev.parallel === true ? (Array.isArray(manifest.matrix?.os) ? manifest.matrix.os : []) : effectiveCiRunners(manifest))
697
+ .filter((runner) => typeof runner === "string");
698
+ if (macActive) {
699
+ if (typeof dev.macAppPath !== "string" || !DEV_MAC_PATH_RE.test(dev.macAppPath) || !dev.macAppPath.endsWith(".app")) {
700
+ errors.push(`devArtifact.macAppPath must be a safe repository-relative path ending in .app when mac is '${dev.mac}'`);
701
+ }
702
+ if (dev.macEntitlements !== undefined && !macSigned) {
703
+ errors.push("devArtifact.macEntitlements requires mac 'sign' or 'notarize'");
704
+ } else if (dev.macEntitlements !== undefined && (typeof dev.macEntitlements !== "string" || !GATE_PATH_RE.test(dev.macEntitlements))) {
705
+ errors.push("devArtifact.macEntitlements must be a safe repository-relative path");
706
+ }
707
+ if (!runners.some((runner) => MACOS_RUNNER_RE.test(runner))) {
708
+ errors.push(dev.parallel === true
709
+ ? `devArtifact.mac '${dev.mac}' needs a macOS runner (macos-* or xcode-*) in matrix.os`
710
+ : `devArtifact.mac '${dev.mac}' needs the ci gate to run on a macOS runner (set ciAllOs and include a macos-* or xcode-* runner in matrix.os)`);
711
+ }
712
+ } else if (dev.macAppPath !== undefined || dev.macEntitlements !== undefined) {
713
+ errors.push("devArtifact.macAppPath and macEntitlements require mac 'sign', 'notarize' or 'unsigned'");
714
+ }
715
+ if (dev.windows === "unsigned") {
716
+ if (typeof dev.windowsGlob !== "string" || !DEV_WINDOWS_GLOB_RE.test(dev.windowsGlob)) {
717
+ errors.push("devArtifact.windowsGlob must be a safe repository-relative glob when windows is 'unsigned'");
718
+ }
719
+ if (!runners.some((runner) => /^windows-/i.test(runner))) {
720
+ errors.push(dev.parallel === true
721
+ ? "devArtifact.windows 'unsigned' needs a windows-* runner in matrix.os"
722
+ : "devArtifact.windows 'unsigned' needs the ci gate to run on a windows-* runner");
723
+ }
724
+ } else if (dev.windowsGlob !== undefined) {
725
+ errors.push("devArtifact.windowsGlob requires windows 'unsigned'");
726
+ }
727
+ }
728
+
729
+ const DEV_PUSH_CONDITION = "github.event_name == 'push' && github.ref_name == github.event.repository.default_branch";
730
+
731
+ // concurrency.mainPushes: "queue" stops default-branch pushes from cancelling each other.
732
+ // PR runs keep cancel-in-progress true, so superseded PR runs still cancel.
733
+ const CONCURRENCY_MAIN_PUSHES = ["cancel", "queue"];
734
+ const CI_CANCEL_MAIN_QUEUE_EXPRESSION = "${{ !(github.event_name == 'push' && github.ref_name == github.event.repository.default_branch) }}";
735
+ // rustCache.keySuffix: charset-checked before it reaches the rendered `key` input.
736
+ const RUST_CACHE_KEY_SUFFIX_RE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
737
+
738
+ function validateConcurrency(manifest, lanes, errors) {
739
+ const concurrency = manifest.concurrency;
740
+ if (concurrency === null || typeof concurrency !== "object" || Array.isArray(concurrency)) {
741
+ errors.push("concurrency must be an object");
742
+ return;
743
+ }
744
+ for (const key of Object.keys(concurrency)) {
745
+ if (key !== "mainPushes") errors.push(`unknown concurrency field: ${key}`);
746
+ }
747
+ if (concurrency.mainPushes !== undefined && !CONCURRENCY_MAIN_PUSHES.includes(concurrency.mainPushes)) {
748
+ errors.push("concurrency.mainPushes must be 'cancel' or 'queue'");
749
+ }
750
+ if (!Array.isArray(lanes) || !lanes.includes("ci")) {
751
+ errors.push("concurrency requires lane 'ci' (it sets the ci workflow's concurrency)");
752
+ }
753
+ }
754
+
755
+ /**
756
+ * rustCache.keySuffix as the Swatinem/rust-cache `key` input: `<lane>-<suffix>`.
757
+ * Returns "" when unset, so unopted renders stay byte-identical. rust-cache
758
+ * never re-saves on an exact key hit; changing the suffix produces a new key,
759
+ * so the next run on the default branch saves a fresh entry.
760
+ */
761
+ function rustCacheKeyLine(manifest, lane) {
762
+ const suffix = manifest.rustCache?.keySuffix;
763
+ return suffix === undefined ? "" : ` key: ${lane}-${suffix}`;
764
+ }
765
+
766
+ /** ciIncremental: Xcode DerivedData cache step (leading newline; "" when unset). */
767
+ function derivedDataStep(manifest) {
768
+ if (manifest.ciIncremental !== true) return "";
769
+ return [
770
+ "",
771
+ " - name: Cache Xcode DerivedData",
772
+ " if: ${{ runner.os == 'macOS' }}",
773
+ ` uses: ${CACHE_ACTION_PIN}`,
774
+ " with:",
775
+ " path: ~/Library/Developer/Xcode/DerivedData",
776
+ " key: ${{ runner.os }}-${{ matrix.os }}-deriveddata-${{ hashFiles('**/Cargo.lock', '**/Package.resolved', '**/*.xcodeproj/project.pbxproj') }}",
777
+ " restore-keys: |",
778
+ " ${{ runner.os }}-${{ matrix.os }}-deriveddata-",
779
+ ].join("\n");
780
+ }
781
+
782
+ /**
783
+ * Dev artifact steps appended to the ci job (unsigned, no secrets) plus the
784
+ * separate signing job. Returns "" when devArtifact is unset.
785
+ */
786
+ // Unsigned legs may also run on a manual dispatch of any ref when
787
+ // `devArtifact.dispatch` is set; the signing job never does (push to the
788
+ // default branch only), so no secret is reachable from a dispatched run.
789
+ function devUnsignedCondition(dev) {
790
+ return dev.dispatch === true
791
+ ? `(${DEV_PUSH_CONDITION} || github.event_name == 'workflow_dispatch')`
792
+ : DEV_PUSH_CONDITION;
793
+ }
794
+
795
+ export function devArtifactDispatchTrigger(manifest) {
796
+ return manifest.devArtifact?.dispatch === true ? " workflow_dispatch:\n" : "";
797
+ }
798
+
799
+ export function devArtifactCi(manifest, options = {}) {
800
+ const dev = manifest.devArtifact;
801
+ if (dev === undefined) return "";
802
+ if (dev.parallel === true) return devArtifactParallelJobs(manifest, options);
803
+ const retention = dev.retentionDays ?? DEV_ARTIFACT_DEFAULT_RETENTION_DAYS;
804
+ const unsignedCondition = devUnsignedCondition(dev);
805
+ const parts = [];
806
+ if (dev.windows === "unsigned") {
807
+ parts.push([
808
+ " - name: Upload unsigned dev build (Windows)",
809
+ ` if: \${{ ${unsignedCondition} && runner.os == 'Windows' }}`,
810
+ ` uses: ${UPLOAD_ARTIFACT_PIN}`,
811
+ " with:",
812
+ " name: dev-windows-${{ github.sha }}",
813
+ ` path: ${dev.windowsGlob}`,
814
+ ` retention-days: ${retention}`,
815
+ " if-no-files-found: error",
816
+ "",
817
+ ].join("\n"));
818
+ }
819
+ if (dev.mac === "sign" || dev.mac === "notarize") {
820
+ parts.push([
821
+ " - name: Package unsigned dev app (macOS)",
822
+ ` if: \${{ ${DEV_PUSH_CONDITION} && runner.os == 'macOS' }}`,
823
+ " shell: bash",
824
+ " env:",
825
+ ` DEV_APP_PATH: ${JSON.stringify(dev.macAppPath)}`,
826
+ " run: |",
827
+ " set -euo pipefail",
828
+ " test -d \"$DEV_APP_PATH\"",
829
+ " mkdir -p \"$RUNNER_TEMP/dev-unsigned\"",
830
+ " ditto -c -k --keepParent \"$DEV_APP_PATH\" \"$RUNNER_TEMP/dev-unsigned/app.zip\"",
831
+ " - name: Upload unsigned dev app for signing (macOS)",
832
+ ` if: \${{ ${DEV_PUSH_CONDITION} && runner.os == 'macOS' }}`,
833
+ ` uses: ${UPLOAD_ARTIFACT_PIN}`,
834
+ " with:",
835
+ " name: dev-unsigned-mac-${{ github.sha }}",
836
+ " path: ${{ runner.temp }}/dev-unsigned/app.zip",
837
+ " retention-days: 1",
838
+ " if-no-files-found: error",
839
+ "",
840
+ ].join("\n"));
841
+ }
842
+ if (dev.mac === "unsigned") {
843
+ parts.push([
844
+ " - name: Package unsigned dev app (macOS)",
845
+ ` if: \${{ ${unsignedCondition} && runner.os == 'macOS' }}`,
846
+ " shell: bash",
847
+ " env:",
848
+ ` DEV_APP_PATH: ${JSON.stringify(dev.macAppPath)}`,
849
+ " run: |",
850
+ " set -euo pipefail",
851
+ " test -d \"$DEV_APP_PATH\"",
852
+ " mkdir -p \"$RUNNER_TEMP/dev-unsigned\"",
853
+ " ditto -c -k --keepParent \"$DEV_APP_PATH\" \"$RUNNER_TEMP/dev-unsigned/app.zip\"",
854
+ " - name: Upload unsigned dev app (macOS)",
855
+ ` if: \${{ ${unsignedCondition} && runner.os == 'macOS' }}`,
856
+ ` uses: ${UPLOAD_ARTIFACT_PIN}`,
857
+ " with:",
858
+ " name: dev-mac-unsigned-${{ github.sha }}",
859
+ " path: ${{ runner.temp }}/dev-unsigned/app.zip",
860
+ ` retention-days: ${retention}`,
861
+ " if-no-files-found: error",
862
+ "",
863
+ ].join("\n"));
864
+ }
865
+ let text = parts.join("");
866
+ if (dev.mac === "sign" || dev.mac === "notarize") text += devMacSigningJob(manifest, dev, retention);
867
+ return text;
868
+ }
869
+
870
+ // devArtifact.parallel: true. Each platform gets its own job that compiles the
871
+ // dev app (devArtifact.buildScript) and stages it. These jobs need only the
872
+ // private-repo guard, so they run beside the QA gate job instead of after it.
873
+ // Unsigned uploads therefore do not wait for the gate; the signing job still
874
+ // needs ci, so nothing is Developer ID-signed from a failed gate.
875
+ function devArtifactParallelJobs(manifest, options) {
876
+ const dev = manifest.devArtifact;
877
+ if (!options.artifactPrefix) throw new Error("devArtifactCi: options.artifactPrefix is required when devArtifact.parallel is true");
878
+ const lane = options.lane ?? "ci";
879
+ const retention = dev.retentionDays ?? DEV_ARTIFACT_DEFAULT_RETENTION_DAYS;
880
+ const shared = { manifest, lane, artifactPrefix: options.artifactPrefix, retention };
881
+ const parts = [];
882
+ if (dev.mac === "sign" || dev.mac === "notarize" || dev.mac === "unsigned") parts.push(devMacArtifactJob(shared));
883
+ if (dev.windows === "unsigned") parts.push(devWindowsArtifactJob(shared));
884
+ if (dev.mac === "sign" || dev.mac === "notarize") parts.push(devMacSigningJob(manifest, dev, retention));
885
+ return parts.join("");
886
+ }
887
+
888
+ function firstMatchingRunner(manifest, pattern, platform) {
889
+ const runner = manifest.matrix.os.find((os) => typeof os === "string" && pattern.test(os));
890
+ if (!runner) throw new Error(`devArtifact.parallel: no ${platform} runner in matrix.os`);
891
+ return runner;
892
+ }
893
+
894
+ function devMacArtifactJob({ manifest, lane, artifactPrefix, retention }) {
895
+ const dev = manifest.devArtifact;
896
+ const signed = dev.mac === "sign" || dev.mac === "notarize";
897
+ const stage = [
898
+ " - name: Package unsigned dev app (macOS)",
899
+ " shell: bash",
900
+ " env:",
901
+ ` DEV_APP_PATH: ${JSON.stringify(dev.macAppPath)}`,
902
+ " run: |",
903
+ " set -euo pipefail",
904
+ " test -d \"$DEV_APP_PATH\"",
905
+ " mkdir -p \"$RUNNER_TEMP/dev-unsigned\"",
906
+ " ditto -c -k --keepParent \"$DEV_APP_PATH\" \"$RUNNER_TEMP/dev-unsigned/app.zip\"",
907
+ ...(signed
908
+ ? [
909
+ " - name: Upload unsigned dev app for signing (macOS)",
910
+ ` uses: ${UPLOAD_ARTIFACT_PIN}`,
911
+ " with:",
912
+ " name: dev-unsigned-mac-${{ github.sha }}",
913
+ " path: ${{ runner.temp }}/dev-unsigned/app.zip",
914
+ " retention-days: 1",
915
+ " if-no-files-found: error",
916
+ ]
917
+ : [
918
+ " - name: Upload unsigned dev app (macOS)",
919
+ ` uses: ${UPLOAD_ARTIFACT_PIN}`,
920
+ " with:",
921
+ " name: dev-mac-unsigned-${{ github.sha }}",
922
+ " path: ${{ runner.temp }}/dev-unsigned/app.zip",
923
+ ` retention-days: ${retention}`,
924
+ " if-no-files-found: error",
925
+ ]),
926
+ ];
927
+ return devPlatformJob({
928
+ manifest,
929
+ id: "dev-artifact-mac",
930
+ label: "macOS",
931
+ runner: firstMatchingRunner(manifest, MACOS_RUNNER_RE, "macOS"),
932
+ condition: signed ? DEV_PUSH_CONDITION : devUnsignedCondition(dev),
933
+ lane,
934
+ artifactPrefix,
935
+ stage,
936
+ swift: true,
937
+ });
938
+ }
939
+
940
+ function devWindowsArtifactJob({ manifest, lane, artifactPrefix, retention }) {
941
+ const dev = manifest.devArtifact;
942
+ const stage = [
943
+ " - name: Upload unsigned dev build (Windows)",
944
+ ` uses: ${UPLOAD_ARTIFACT_PIN}`,
945
+ " with:",
946
+ " name: dev-windows-${{ github.sha }}",
947
+ ` path: ${dev.windowsGlob}`,
948
+ ` retention-days: ${retention}`,
949
+ " if-no-files-found: error",
950
+ ];
951
+ return devPlatformJob({
952
+ manifest,
953
+ id: "dev-artifact-windows",
954
+ label: "Windows",
955
+ runner: firstMatchingRunner(manifest, /^windows-/i, "windows-*"),
956
+ condition: devUnsignedCondition(dev),
957
+ lane,
958
+ artifactPrefix,
959
+ stage,
960
+ });
961
+ }
962
+
963
+ // One platform job: toolchain + dependency install + dev build, then the
964
+ // platform staging steps. Mirrors the ci job's setup without the gate, the
965
+ // ownership scan, or any secret.
966
+ // swift: true renders the shared private Swift package steps around the build
967
+ // (macOS job only; the Windows job never gets them). The credential exists only
968
+ // between those two steps, so the staging and upload steps run without it.
969
+ function devPlatformJob({ manifest, id, label, runner, condition, lane, artifactPrefix, stage, swift = false }) {
970
+ const dev = manifest.devArtifact;
971
+ const swiftLines = (step) => (swift && step ? step.slice(1).split("\n") : []);
972
+ const swiftConfigure = swiftLines(swiftPrivatePackagesConfigureStep(manifest));
973
+ const swiftCleanup = swiftLines(swiftPrivatePackagesCleanupStep(manifest));
974
+ const pm = parsePackageManager(manifest.packageManager);
975
+ const workspaces = (manifest.rustCache?.workspaces ?? ["engine"]).map((workspace) => ` ${workspace} -> target`).join("\n");
976
+ const cacheKey = rustCacheKeyLine(manifest, `${lane}-${id}`);
977
+ return [
978
+ "",
979
+ ` ${id}:`,
980
+ ` # ${label} dev app: builds devArtifact.buildScript and stages it. Runs beside the`,
981
+ swiftConfigure.length > 0
982
+ ? " # QA gate job, not after it, and reaches only the private Swift package secret."
983
+ : " # QA gate job, not after it, and never reaches a secret.",
984
+ " needs: [private-repo-guard]",
985
+ ` if: \${{ ${condition} }}`,
986
+ ` runs-on: ${runner}`,
987
+ " permissions:",
988
+ " contents: read",
989
+ " steps:",
990
+ " - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1",
991
+ " with:",
992
+ " persist-credentials: false",
993
+ " - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0",
994
+ " with:",
995
+ ` node-version: ${JSON.stringify(String(manifest.matrix.node[0]))}`,
996
+ " package-manager-cache: false",
997
+ ...(pm.setup ? [pm.setup] : []),
998
+ ` - run: ${pm.installCommand}`,
999
+ " - uses: dtolnay/rust-toolchain@f8be11a05b1d4f3fcebe6410cc16743212b999b0",
1000
+ " - uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2",
1001
+ " with:",
1002
+ " workspaces: |",
1003
+ workspaces,
1004
+ ` shared-key: ${artifactPrefix}-rust`,
1005
+ ...(cacheKey ? [cacheKey] : []),
1006
+ " add-job-id-key: false",
1007
+ ` cache-workspace-crates: ${manifest.ciIncremental === true ? "true" : "false"}`,
1008
+ " cache-on-failure: true",
1009
+ " save-if: true",
1010
+ ...swiftConfigure,
1011
+ " - name: Build dev app",
1012
+ ` run: ${pm.runPrefix} ${dev.buildScript}`,
1013
+ ...swiftCleanup,
1014
+ ...stage,
1015
+ "",
1016
+ ].join("\n");
1017
+ }
1018
+
1019
+ function devMacSigningJob(manifest, dev, retention) {
1020
+ const parallel = dev.parallel === true;
1021
+ const runner = (parallel ? manifest.matrix.os : effectiveCiRunners(manifest)).find((os) => MACOS_RUNNER_RE.test(os));
1022
+ const entitlements = dev.macEntitlements ? ` --entitlements "$GITHUB_WORKSPACE/${dev.macEntitlements}"` : "";
1023
+ const checkout = dev.macEntitlements
1024
+ ? ` - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
1025
+ with:
1026
+ ref: \${{ github.sha }}
1027
+ persist-credentials: false
1028
+ `
1029
+ : "";
1030
+ // `mac: "notarize"` also submits the signed app to the notary service and
1031
+ // staples the ticket, so app extensions (Finder Sync, Share, ...) register on
1032
+ // current macOS, which refuses them from unnotarized Developer ID apps.
1033
+ const notarize = dev.mac === "notarize";
1034
+ const apiKeyEnv = notarize ? `
1035
+ APPLE_API_KEY_BASE64: \${{ secrets.APPLE_API_KEY_BASE64 }}` : "";
1036
+ const apiKeyInstall = notarize ? `
1037
+ printf '%s' "$APPLE_API_KEY_BASE64" | base64 --decode > "$RUNNER_TEMP/AuthKey.p8"` : "";
1038
+ const notarizeStep = notarize ? ` - name: Notarize and staple dev app
1039
+ shell: bash
1040
+ env:
1041
+ APPLE_API_KEY: \${{ secrets.APPLE_API_KEY }}
1042
+ APPLE_API_ISSUER: \${{ secrets.APPLE_API_ISSUER }}
1043
+ run: |
1044
+ set -euo pipefail
1045
+ app="$(find "$RUNNER_TEMP/dev-sign" -maxdepth 1 -name '*.app' -print -quit)"
1046
+ test -n "$app"
1047
+ zip="$RUNNER_TEMP/dev-signed/$(basename "$app").zip"
1048
+ xcrun notarytool submit "$zip" --key "$RUNNER_TEMP/AuthKey.p8" --key-id "$APPLE_API_KEY" --issuer "$APPLE_API_ISSUER" --wait
1049
+ xcrun stapler staple "$app"
1050
+ xcrun stapler validate "$app"
1051
+ rm -f "$zip"
1052
+ ditto -c -k --keepParent "$app" "$zip"
1053
+ ` : "";
1054
+ const uploadLabel = notarize ? "Upload signed and notarized dev app" : "Upload signed (not notarized) dev app";
1055
+ return `
1056
+ dev-mac-sign:
1057
+ # Push to the default branch only. The release environment's protection
1058
+ # rules (required reviewers, branch policy) apply to this job.
1059
+ needs: ${parallel ? "[ci, dev-artifact-mac]" : "[ci]"}
1060
+ if: \${{ ${DEV_PUSH_CONDITION} }}
1061
+ environment: ${releaseEnvironment(manifest, "signing")}
1062
+ runs-on: ${runner}
1063
+ permissions:
1064
+ contents: read
1065
+ steps:
1066
+ ${checkout} - name: Download unsigned dev app
1067
+ uses: actions/download-artifact@${DOWNLOAD_ARTIFACT_SHA} # v4.3.0
1068
+ with:
1069
+ name: dev-unsigned-mac-\${{ github.sha }}
1070
+ path: \${{ runner.temp }}/dev-unsigned
1071
+ - name: Install Apple signing identity in temporary keychain
1072
+ shell: bash
1073
+ env:
1074
+ APPLE_CERTIFICATE_BASE64: \${{ secrets.APPLE_CERTIFICATE_BASE64 }}
1075
+ APPLE_CERTIFICATE_PASSWORD: \${{ secrets.APPLE_CERTIFICATE_PASSWORD }}
1076
+ APPLE_KEYCHAIN_PASSWORD: \${{ secrets.APPLE_KEYCHAIN_PASSWORD }}${apiKeyEnv}
1077
+ run: |
1078
+ set -euo pipefail
1079
+ certificate_path="$RUNNER_TEMP/apple-signing.p12"
1080
+ keychain_path="$RUNNER_TEMP/apple-signing.keychain-db"
1081
+ printf '%s' "$APPLE_CERTIFICATE_BASE64" | base64 --decode > "$certificate_path"${apiKeyInstall}
1082
+ security create-keychain -p "$APPLE_KEYCHAIN_PASSWORD" "$keychain_path"
1083
+ security set-keychain-settings -lut 21600 "$keychain_path"
1084
+ security unlock-keychain -p "$APPLE_KEYCHAIN_PASSWORD" "$keychain_path"
1085
+ security import "$certificate_path" -P "$APPLE_CERTIFICATE_PASSWORD" -A -t cert -f pkcs12 -k "$keychain_path"
1086
+ security set-key-partition-list -S apple-tool:,apple: -k "$APPLE_KEYCHAIN_PASSWORD" "$keychain_path"
1087
+ security list-keychain -d user -s "$keychain_path"
1088
+ - name: Developer ID sign dev app${notarize ? "" : " (no notarization)"}
1089
+ shell: bash
1090
+ env:
1091
+ APPLE_DEVELOPER_ID: \${{ vars.APPLE_DEVELOPER_ID }}
1092
+ run: |
1093
+ set -euo pipefail
1094
+ work="$RUNNER_TEMP/dev-sign"
1095
+ rm -rf "$work" && mkdir -p "$work"
1096
+ ditto -x -k "$RUNNER_TEMP/dev-unsigned/app.zip" "$work"
1097
+ app="$(find "$work" -maxdepth 1 -name '*.app' -print -quit)"
1098
+ test -n "$app"
1099
+ codesign --force --deep --strict --options runtime --timestamp${entitlements} --sign "$APPLE_DEVELOPER_ID" "$app"
1100
+ codesign --verify --deep --strict "$app"
1101
+ mkdir -p "$RUNNER_TEMP/dev-signed"
1102
+ ditto -c -k --keepParent "$app" "$RUNNER_TEMP/dev-signed/$(basename "$app").zip"
1103
+ ${notarizeStep} - name: ${uploadLabel}
1104
+ uses: ${UPLOAD_ARTIFACT_PIN}
1105
+ with:
1106
+ name: dev-mac-\${{ github.sha }}
1107
+ path: \${{ runner.temp }}/dev-signed/*.zip
1108
+ retention-days: ${retention}
1109
+ if-no-files-found: error
1110
+ - name: Remove Apple signing material
1111
+ if: \${{ always() }}
1112
+ shell: bash
1113
+ run: |
1114
+ security delete-keychain "$RUNNER_TEMP/apple-signing.keychain-db" 2>/dev/null || true
1115
+ rm -f "$RUNNER_TEMP/apple-signing.p12"${notarize ? ' "$RUNNER_TEMP/AuthKey.p8"' : ""}
1116
+ `;
1117
+ }
1118
+
1119
+ function windowsSigningJob(manifest, pm, artifactPrefix) {
1120
+ if (manifest.candidate?.signWindows !== true) return "";
1121
+ const nodeVersion = String(manifest.matrix.node[0]);
1122
+ const releaseChain = manifest.candidate.releaseChain;
1123
+ const finalizeCommand = releaseChain
1124
+ ? `${pm.runPrefix} ${releaseChain.windowsFinalizeScript}`
1125
+ : "pnpm exec right-release build --platform win --skip-checks";
1126
+ const finalizeEnvironment = releaseChain
1127
+ ? ` RIGHT_GIT_UNSIGNED_CANDIDATE_ROOT: \${{ runner.temp }}/unsigned-windows-candidate
1128
+ RIGHT_GIT_FINALIZED_WINDOWS_ROOT: \${{ runner.temp }}/finalized-windows
1129
+ RIGHT_GIT_SOURCE_REVISION: \${{ needs.admission.outputs.source_revision }}`
1130
+ : ` LEGION_UNSIGNED_CANDIDATE_ROOT: \${{ runner.temp }}/unsigned-windows-candidate
1131
+ RIGHT_GIT_SOURCE_REVISION: \${{ needs.admission.outputs.source_revision }}
1132
+ LEGION_SOURCE_REVISION: \${{ needs.admission.outputs.source_revision }}`;
1133
+ const uploadPath = releaseChain
1134
+ ? " ${{ runner.temp }}/finalized-windows/**"
1135
+ : " dist/releases/windows/**\n .right-release/receipts/windows-*.json";
1136
+ return `
1137
+ windows-sign:
1138
+ needs: [admission, candidate]
1139
+ if: \${{ needs.admission.outputs.signed_qualification == 'true' }}
1140
+ environment: ${releaseEnvironment(manifest, "signing")}
1141
+ strategy:
1142
+ fail-fast: false
1143
+ matrix:
1144
+ ${signingMatrix(manifest, "windows")}
1145
+ runs-on: \${{ matrix.os }}
1146
+ permissions:
1147
+ contents: read
1148
+ id-token: write
1149
+ steps:
1150
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
1151
+ with:
1152
+ ref: \${{ needs.admission.outputs.source_revision }}
1153
+ fetch-depth: 0
1154
+ persist-credentials: false
1155
+ - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
1156
+ with:
1157
+ node-version: ${nodeVersion}
1158
+ package-manager-cache: false
1159
+ ${pm.setup}
1160
+ - uses: dtolnay/rust-toolchain@f8be11a05b1d4f3fcebe6410cc16743212b999b0
1161
+ with:
1162
+ targets: \${{ matrix.targetTriple }}
1163
+ - run: ${pm.installCommand}
1164
+ - name: Initialize Windows signing stage summary
1165
+ run: ${pm.runPrefix} ${manifest.candidate.stageSummaryScript}
1166
+ env:
1167
+ RIGHT_GIT_STAGE_ACTION: init
1168
+ RIGHT_GIT_STAGE_ROOT: \${{ runner.temp }}/right-git-stage-summary
1169
+ RIGHT_GIT_STAGE_EVIDENCE_ROOT: \${{ runner.temp }}/finalized-windows
1170
+ RIGHT_GIT_STAGE: windows-sign
1171
+ RIGHT_GIT_STAGE_PRODUCER: windows-sign-\${{ matrix.architecture }}
1172
+ RIGHT_GIT_RELEASE_VERSION: \${{ needs.admission.outputs.version }}
1173
+ RIGHT_GIT_SOURCE_REVISION: \${{ needs.admission.outputs.source_revision }}
1174
+ RIGHT_GIT_RELEASE_PLATFORM: \${{ matrix.platform }}
1175
+ RIGHT_GIT_RELEASE_ARCHITECTURE: \${{ matrix.architecture }}
1176
+ RIGHT_GIT_RUN_ID: \${{ github.run_id }}
1177
+ RIGHT_GIT_RUN_ATTEMPT: \${{ github.run_attempt }}
1178
+ - name: Download exact unsigned Windows candidate
1179
+ uses: actions/download-artifact@${DOWNLOAD_ARTIFACT_SHA} # v4.3.0
1180
+ with:
1181
+ name: ${artifactPrefix}-\${{ github.run_id }}-\${{ github.run_attempt }}-candidate-\${{ matrix.platform }}-\${{ matrix.architecture }}-\${{ needs.admission.outputs.version }}-\${{ needs.admission.outputs.source_revision }}\${{ needs.admission.outputs.artifact_suffix }}
1182
+ path: \${{ runner.temp }}/unsigned-windows-candidate
1183
+ - name: Authenticate to Azure with GitHub OIDC
1184
+ uses: azure/login@${AZURE_LOGIN_SHA} # v3
1185
+ with:
1186
+ client-id: \${{ vars.AZURE_CLIENT_ID }}
1187
+ tenant-id: \${{ vars.AZURE_TENANT_ID }}
1188
+ subscription-id: \${{ vars.AZURE_SUBSCRIPTION_ID }}
1189
+ - name: Install pinned Artifact Signing client
1190
+ shell: pwsh
1191
+ run: |
1192
+ $ErrorActionPreference = 'Stop'
1193
+ $tools = Join-Path $env:RUNNER_TEMP 'artifact-signing-tools'
1194
+ New-Item -ItemType Directory -Force -Path $tools | Out-Null
1195
+ $client = Join-Path $tools 'client.zip'
1196
+ $sdk = Join-Path $tools 'sdk.zip'
1197
+ Invoke-WebRequest 'https://api.nuget.org/v3-flatcontainer/microsoft.artifactsigning.client/${ARTIFACT_SIGNING_CLIENT_VERSION}/microsoft.artifactsigning.client.${ARTIFACT_SIGNING_CLIENT_VERSION}.nupkg' -OutFile $client
1198
+ Invoke-WebRequest 'https://api.nuget.org/v3-flatcontainer/microsoft.windows.sdk.buildtools/${WINDOWS_SDK_BUILD_TOOLS_VERSION}/microsoft.windows.sdk.buildtools.${WINDOWS_SDK_BUILD_TOOLS_VERSION}.nupkg' -OutFile $sdk
1199
+ if ((Get-FileHash $client -Algorithm SHA256).Hash -ne '${ARTIFACT_SIGNING_CLIENT_SHA256}') { throw 'Artifact Signing client hash mismatch' }
1200
+ if ((Get-FileHash $sdk -Algorithm SHA256).Hash -ne '${WINDOWS_SDK_BUILD_TOOLS_SHA256}') { throw 'Windows SDK Build Tools hash mismatch' }
1201
+ Expand-Archive $client (Join-Path $tools 'client')
1202
+ Expand-Archive $sdk (Join-Path $tools 'sdk')
1203
+ "AZURE_ARTIFACT_SIGNING_DLIB_PATH=$tools\\client\\bin\\x64\\Azure.CodeSigning.Dlib.dll" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
1204
+ "AZURE_SIGNTOOL_PATH=$tools\\sdk\\bin\\10.0.26100.0\\x64\\signtool.exe" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
1205
+ - name: Sign & finalize Windows candidate
1206
+ run: ${finalizeCommand}
1207
+ env:
1208
+ ${finalizeEnvironment}
1209
+ RIGHT_GIT_RELEASE_PLATFORM: \${{ matrix.platform }}
1210
+ RIGHT_GIT_RELEASE_ARCHITECTURE: \${{ matrix.architecture }}
1211
+ AZURE_ARTIFACT_SIGNING_ENDPOINT: \${{ vars.AZURE_ARTIFACT_SIGNING_ENDPOINT }}
1212
+ AZURE_ARTIFACT_SIGNING_ACCOUNT: \${{ vars.AZURE_ARTIFACT_SIGNING_ACCOUNT }}
1213
+ AZURE_ARTIFACT_SIGNING_PROFILE: \${{ vars.AZURE_ARTIFACT_SIGNING_PROFILE }}
1214
+ - name: Finalize Windows signing stage summary
1215
+ if: \${{ always() }}
1216
+ run: ${pm.runPrefix} ${manifest.candidate.stageSummaryScript}
1217
+ env:
1218
+ RIGHT_GIT_STAGE_ACTION: finalize
1219
+ RIGHT_GIT_STAGE_ROOT: \${{ runner.temp }}/right-git-stage-summary
1220
+ RIGHT_GIT_STAGE_EVIDENCE_ROOT: \${{ runner.temp }}/finalized-windows
1221
+ RIGHT_GIT_STAGE: windows-sign
1222
+ RIGHT_GIT_STAGE_PRODUCER: windows-sign-\${{ matrix.architecture }}
1223
+ RIGHT_GIT_STAGE_STATUS: \${{ job.status == 'success' && 'SUCCEEDED' || 'FAILED' }}
1224
+ RIGHT_GIT_STAGE_EXIT_CODE: \${{ job.status == 'success' && '0' || '1' }}
1225
+ RIGHT_GIT_RELEASE_VERSION: \${{ needs.admission.outputs.version }}
1226
+ RIGHT_GIT_SOURCE_REVISION: \${{ needs.admission.outputs.source_revision }}
1227
+ RIGHT_GIT_RELEASE_PLATFORM: \${{ matrix.platform }}
1228
+ RIGHT_GIT_RELEASE_ARCHITECTURE: \${{ matrix.architecture }}
1229
+ RIGHT_GIT_RUN_ID: \${{ github.run_id }}
1230
+ RIGHT_GIT_RUN_ATTEMPT: \${{ github.run_attempt }}
1231
+ - name: Upload signed Windows candidate
1232
+ if: \${{ always() }}
1233
+ uses: actions/upload-artifact@${UPLOAD_ARTIFACT_SHA} # v4
1234
+ with:
1235
+ name: ${artifactPrefix}-\${{ github.run_id }}-\${{ github.run_attempt }}-signed-windows-\${{ matrix.architecture }}-\${{ needs.admission.outputs.version }}-\${{ needs.admission.outputs.source_revision }}\${{ needs.admission.outputs.artifact_suffix }}
1236
+ path: |
1237
+ ${uploadPath}
1238
+ if-no-files-found: error
1239
+ - name: Upload Windows signing stage summary
1240
+ if: \${{ always() }}
1241
+ uses: actions/upload-artifact@${UPLOAD_ARTIFACT_SHA} # v4
1242
+ with:
1243
+ name: ${artifactPrefix}-\${{ github.run_id }}-\${{ github.run_attempt }}-summary-windows-sign-\${{ matrix.architecture }}-\${{ needs.admission.outputs.version }}-\${{ needs.admission.outputs.source_revision }}\${{ needs.admission.outputs.artifact_suffix }}
1244
+ path: \${{ runner.temp }}/right-git-stage-summary/stage-summary.json
1245
+ if-no-files-found: error
1246
+ `.trimEnd();
1247
+ }
1248
+
1249
+ function macosSigningJob(manifest, pm, artifactPrefix) {
1250
+ if (manifest.candidate?.signMacos !== true) return "";
1251
+ const nodeVersion = String(manifest.matrix.node[0]);
1252
+ const releaseChain = manifest.candidate.releaseChain;
1253
+ const finalizeCommand = releaseChain
1254
+ ? `${pm.runPrefix} ${releaseChain.macosFinalizeScript}`
1255
+ : "pnpm exec right-release build --platform mac --skip-checks";
1256
+ const finalizeEnvironment = releaseChain
1257
+ ? ` RIGHT_GIT_UNSIGNED_CANDIDATE_ROOT: \${{ runner.temp }}/unsigned-macos-candidate
1258
+ RIGHT_GIT_FINALIZED_MACOS_ROOT: \${{ runner.temp }}/finalized-macos
1259
+ RIGHT_GIT_SOURCE_REVISION: \${{ needs.admission.outputs.source_revision }}`
1260
+ : ` LEGION_UNSIGNED_CANDIDATE_ROOT: \${{ runner.temp }}/unsigned-macos-candidate
1261
+ RIGHT_GIT_SOURCE_REVISION: \${{ needs.admission.outputs.source_revision }}
1262
+ LEGION_SOURCE_REVISION: \${{ needs.admission.outputs.source_revision }}`;
1263
+ const uploadPath = releaseChain
1264
+ ? " ${{ runner.temp }}/finalized-macos/**"
1265
+ : " dist/releases/mac/**\n .right-release/receipts/macos-*.json";
1266
+ return `
1267
+ macos-sign:
1268
+ needs: [admission, candidate]
1269
+ if: \${{ needs.admission.outputs.signed_qualification == 'true' }}
1270
+ environment: ${releaseEnvironment(manifest, "signing")}
1271
+ strategy:
1272
+ fail-fast: false
1273
+ matrix:
1274
+ ${signingMatrix(manifest, "macos")}
1275
+ runs-on: \${{ matrix.os }}
1276
+ permissions:
1277
+ contents: read
1278
+ steps:
1279
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
1280
+ with:
1281
+ ref: \${{ needs.admission.outputs.source_revision }}
1282
+ fetch-depth: 0
1283
+ persist-credentials: false
1284
+ - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
1285
+ with:
1286
+ node-version: ${nodeVersion}
1287
+ package-manager-cache: false
1288
+ ${pm.setup}
1289
+ - uses: dtolnay/rust-toolchain@f8be11a05b1d4f3fcebe6410cc16743212b999b0
1290
+ with:
1291
+ targets: \${{ matrix.targetTriple }}
1292
+ - run: ${pm.installCommand}
1293
+ - name: Initialize macOS signing stage summary
1294
+ run: ${pm.runPrefix} ${manifest.candidate.stageSummaryScript}
1295
+ env:
1296
+ RIGHT_GIT_STAGE_ACTION: init
1297
+ RIGHT_GIT_STAGE_ROOT: \${{ runner.temp }}/right-git-stage-summary
1298
+ RIGHT_GIT_STAGE_EVIDENCE_ROOT: \${{ runner.temp }}/finalized-macos
1299
+ RIGHT_GIT_STAGE: macos-sign
1300
+ RIGHT_GIT_STAGE_PRODUCER: macos-sign-\${{ matrix.architecture }}
1301
+ RIGHT_GIT_RELEASE_VERSION: \${{ needs.admission.outputs.version }}
1302
+ RIGHT_GIT_SOURCE_REVISION: \${{ needs.admission.outputs.source_revision }}
1303
+ RIGHT_GIT_RELEASE_PLATFORM: \${{ matrix.platform }}
1304
+ RIGHT_GIT_RELEASE_ARCHITECTURE: \${{ matrix.architecture }}
1305
+ RIGHT_GIT_RUN_ID: \${{ github.run_id }}
1306
+ RIGHT_GIT_RUN_ATTEMPT: \${{ github.run_attempt }}
1307
+ - name: Download exact unsigned macOS candidate
1308
+ uses: actions/download-artifact@${DOWNLOAD_ARTIFACT_SHA} # v4.3.0
1309
+ with:
1310
+ name: ${artifactPrefix}-\${{ github.run_id }}-\${{ github.run_attempt }}-candidate-\${{ matrix.platform }}-\${{ matrix.architecture }}-\${{ needs.admission.outputs.version }}-\${{ needs.admission.outputs.source_revision }}\${{ needs.admission.outputs.artifact_suffix }}
1311
+ path: \${{ runner.temp }}/unsigned-macos-candidate
1312
+ - name: Install Apple signing identity in temporary keychain
1313
+ shell: bash
1314
+ env:
1315
+ APPLE_CERTIFICATE_BASE64: \${{ secrets.APPLE_CERTIFICATE_BASE64 }}
1316
+ APPLE_CERTIFICATE_PASSWORD: \${{ secrets.APPLE_CERTIFICATE_PASSWORD }}
1317
+ APPLE_KEYCHAIN_PASSWORD: \${{ secrets.APPLE_KEYCHAIN_PASSWORD }}
1318
+ APPLE_API_KEY_BASE64: \${{ secrets.APPLE_API_KEY_BASE64 }}
1319
+ run: |
1320
+ set -euo pipefail
1321
+ certificate_path="$RUNNER_TEMP/apple-signing.p12"
1322
+ key_path="$RUNNER_TEMP/AuthKey.p8"
1323
+ keychain_path="$RUNNER_TEMP/apple-signing.keychain-db"
1324
+ printf '%s' "$APPLE_CERTIFICATE_BASE64" | base64 --decode > "$certificate_path"
1325
+ printf '%s' "$APPLE_API_KEY_BASE64" | base64 --decode > "$key_path"
1326
+ security create-keychain -p "$APPLE_KEYCHAIN_PASSWORD" "$keychain_path"
1327
+ security set-keychain-settings -lut 21600 "$keychain_path"
1328
+ security unlock-keychain -p "$APPLE_KEYCHAIN_PASSWORD" "$keychain_path"
1329
+ security import "$certificate_path" -P "$APPLE_CERTIFICATE_PASSWORD" -A -t cert -f pkcs12 -k "$keychain_path"
1330
+ security set-key-partition-list -S apple-tool:,apple: -k "$APPLE_KEYCHAIN_PASSWORD" "$keychain_path"
1331
+ security list-keychain -d user -s "$keychain_path"
1332
+ printf 'APPLE_API_KEY_PATH=%s\\n' "$key_path" >> "$GITHUB_ENV"
1333
+ - name: Sign, notarize & finalize macOS candidate
1334
+ run: ${finalizeCommand}
1335
+ env:
1336
+ ${finalizeEnvironment}
1337
+ RIGHT_GIT_RELEASE_PLATFORM: \${{ matrix.platform }}
1338
+ RIGHT_GIT_RELEASE_ARCHITECTURE: \${{ matrix.architecture }}
1339
+ APPLE_DEVELOPER_ID: \${{ vars.APPLE_DEVELOPER_ID }}
1340
+ APPLE_API_KEY: \${{ secrets.APPLE_API_KEY }}
1341
+ APPLE_API_ISSUER: \${{ secrets.APPLE_API_ISSUER }}
1342
+ - name: Finalize macOS signing stage summary
1343
+ if: \${{ always() }}
1344
+ run: ${pm.runPrefix} ${manifest.candidate.stageSummaryScript}
1345
+ env:
1346
+ RIGHT_GIT_STAGE_ACTION: finalize
1347
+ RIGHT_GIT_STAGE_ROOT: \${{ runner.temp }}/right-git-stage-summary
1348
+ RIGHT_GIT_STAGE_EVIDENCE_ROOT: \${{ runner.temp }}/finalized-macos
1349
+ RIGHT_GIT_STAGE: macos-sign
1350
+ RIGHT_GIT_STAGE_PRODUCER: macos-sign-\${{ matrix.architecture }}
1351
+ RIGHT_GIT_STAGE_STATUS: \${{ job.status == 'success' && 'SUCCEEDED' || 'FAILED' }}
1352
+ RIGHT_GIT_STAGE_EXIT_CODE: \${{ job.status == 'success' && '0' || '1' }}
1353
+ RIGHT_GIT_RELEASE_VERSION: \${{ needs.admission.outputs.version }}
1354
+ RIGHT_GIT_SOURCE_REVISION: \${{ needs.admission.outputs.source_revision }}
1355
+ RIGHT_GIT_RELEASE_PLATFORM: \${{ matrix.platform }}
1356
+ RIGHT_GIT_RELEASE_ARCHITECTURE: \${{ matrix.architecture }}
1357
+ RIGHT_GIT_RUN_ID: \${{ github.run_id }}
1358
+ RIGHT_GIT_RUN_ATTEMPT: \${{ github.run_attempt }}
1359
+ - name: Upload signed & notarized macOS candidate
1360
+ if: \${{ always() }}
1361
+ uses: actions/upload-artifact@${UPLOAD_ARTIFACT_SHA} # v4
1362
+ with:
1363
+ name: ${artifactPrefix}-\${{ github.run_id }}-\${{ github.run_attempt }}-signed-macos-\${{ matrix.architecture }}-\${{ needs.admission.outputs.version }}-\${{ needs.admission.outputs.source_revision }}\${{ needs.admission.outputs.artifact_suffix }}
1364
+ path: |
1365
+ ${uploadPath}
1366
+ if-no-files-found: error
1367
+ - name: Upload macOS signing stage summary
1368
+ if: \${{ always() }}
1369
+ uses: actions/upload-artifact@${UPLOAD_ARTIFACT_SHA} # v4
1370
+ with:
1371
+ name: ${artifactPrefix}-\${{ github.run_id }}-\${{ github.run_attempt }}-summary-macos-sign-\${{ matrix.architecture }}-\${{ needs.admission.outputs.version }}-\${{ needs.admission.outputs.source_revision }}\${{ needs.admission.outputs.artifact_suffix }}
1372
+ path: \${{ runner.temp }}/right-git-stage-summary/stage-summary.json
1373
+ if-no-files-found: error
1374
+ - name: Remove Apple signing material
1375
+ if: \${{ always() }}
1376
+ shell: bash
1377
+ run: |
1378
+ security delete-keychain "$RUNNER_TEMP/apple-signing.keychain-db" 2>/dev/null || true
1379
+ rm -f "$RUNNER_TEMP/apple-signing.p12" "$RUNNER_TEMP/AuthKey.p8"
1380
+ `.trimEnd();
1381
+ }
1382
+
1383
+ function releaseChainJobs(manifest, pm, artifactPrefix) {
1384
+ const chain = manifest.candidate?.releaseChain;
1385
+ if (!chain) return "";
1386
+ const windowsTarget = candidateTargets(manifest.candidate).find((target) => target.platform === "windows");
1387
+ const windowsRunner = windowsTarget.os;
1388
+ const windowsArchitecture = windowsTarget.architecture;
1389
+ const macosTarget = candidateTargets(manifest.candidate).find((target) => target.platform === "macos");
1390
+ const signMacos = manifest.candidate.signMacos === true;
1391
+ const macosDependency = signMacos ? ", macos-sign" : "";
1392
+ const macosSuccess = signMacos ? " && needs.macos-sign.result == 'success'" : "";
1393
+ // Run- and identity-bound: matches exactly what windows-sign/macos-sign
1394
+ // uploaded (see windowsSigningJob/macosSigningJob) — no matrix context is
1395
+ // available in these non-matrixed jobs, so the platform architecture is a
1396
+ // literal derived from the manifest's single windows/macos target.
1397
+ const VERSION = "${{ needs.admission.outputs.version }}";
1398
+ // Identity-bound artifact names end with the admission artifact_suffix (`-dry-run` on a rehearsal, empty otherwise).
1399
+ const SOURCE_REVISION = "${{ needs.admission.outputs.source_revision }}${{ needs.admission.outputs.artifact_suffix }}";
1400
+ const windowsSignedArtifact = `${artifactPrefix}-\${{ github.run_id }}-\${{ github.run_attempt }}-signed-windows-${windowsArchitecture}-${VERSION}-${SOURCE_REVISION}`;
1401
+ const windowsSummaryArtifact = `${artifactPrefix}-\${{ github.run_id }}-\${{ github.run_attempt }}-summary-windows-sign-${windowsArchitecture}-${VERSION}-${SOURCE_REVISION}`;
1402
+ const macosSignedArtifact = signMacos ? `${artifactPrefix}-\${{ github.run_id }}-\${{ github.run_attempt }}-signed-macos-${macosTarget.architecture}-${VERSION}-${SOURCE_REVISION}` : "";
1403
+ const macosSummaryArtifact = signMacos ? `${artifactPrefix}-\${{ github.run_id }}-\${{ github.run_attempt }}-summary-macos-sign-${macosTarget.architecture}-${VERSION}-${SOURCE_REVISION}` : "";
1404
+ // Candidate stage summaries are per (platform, architecture) — see the
1405
+ // `Upload candidate stage summary` step in the template. releaseChain
1406
+ // requires at most one target per signing platform (validateManifest), so
1407
+ // exactly one candidate-windows summary and at most one candidate-macos
1408
+ // summary exist for this manifest.
1409
+ const candidateWindowsSummaryArtifact = `${artifactPrefix}-\${{ github.run_id }}-\${{ github.run_attempt }}-summary-candidate-windows-${windowsArchitecture}-${VERSION}-${SOURCE_REVISION}`;
1410
+ const candidateMacosSummaryArtifact = signMacos ? `${artifactPrefix}-\${{ github.run_id }}-\${{ github.run_attempt }}-summary-candidate-macos-${macosTarget.architecture}-${VERSION}-${SOURCE_REVISION}` : "";
1411
+ const qualificationArtifact = `${artifactPrefix}-\${{ github.run_id }}-\${{ github.run_attempt }}-installed-qualification-${VERSION}-${SOURCE_REVISION}`;
1412
+ const qualificationSummaryArtifact = `${artifactPrefix}-\${{ github.run_id }}-\${{ github.run_attempt }}-summary-installed-qualification-${VERSION}-${SOURCE_REVISION}`;
1413
+ const macosDownload = signMacos
1414
+ ? ` - name: Download same-run signed & notarized macOS release
1415
+ uses: actions/download-artifact@${DOWNLOAD_ARTIFACT_SHA} # v4.3.0
1416
+ with:
1417
+ name: ${macosSignedArtifact}
1418
+ path: \${{ runner.temp }}/right-git-release/macos`
1419
+ : "";
1420
+ const macosSummaryDownload = signMacos
1421
+ ? ` - name: Download same-run macOS signing stage summary
1422
+ uses: actions/download-artifact@${DOWNLOAD_ARTIFACT_SHA} # v4.3.0
1423
+ with:
1424
+ name: ${macosSummaryArtifact}
1425
+ path: \${{ runner.temp }}/right-git-release/stage-summaries/macos-sign`
1426
+ : "";
1427
+ const candidateMacosSummaryDownload = signMacos
1428
+ ? ` - name: Download same-run candidate (macOS) stage summary
1429
+ uses: actions/download-artifact@${DOWNLOAD_ARTIFACT_SHA} # v4.3.0
1430
+ with:
1431
+ name: ${candidateMacosSummaryArtifact}
1432
+ path: \${{ runner.temp }}/right-git-release/stage-summaries/candidate-macos`
1433
+ : "";
1434
+ const finalizedMacosEnv = signMacos ? `\n RIGHT_GIT_FINALIZED_MACOS_ROOT: \${{ runner.temp }}/right-git-release/macos` : "";
1435
+ // Evidence must be bound to this exact run — not merely this
1436
+ // version+source_revision — so a stale artifact from a different run
1437
+ // cannot satisfy verification. Every job/step from installed-qualification
1438
+ // onward carries RIGHT_GIT_RUN_ID/RIGHT_GIT_RUN_ATTEMPT alongside version
1439
+ // and source_revision.
1440
+ const runIdentityEnv = ` RIGHT_GIT_RUN_ID: \${{ github.run_id }}
1441
+ RIGHT_GIT_RUN_ATTEMPT: \${{ github.run_attempt }}`;
1442
+ const publishSecretEnvironment = (chain.publishSecrets ?? [])
1443
+ .map((name) => ` ${name}: \${{ secrets.${name} }}`)
1444
+ .join("\n");
1445
+ return `
1446
+ installed-qualification:
1447
+ needs: [admission, candidate, windows-sign]
1448
+ if: \${{ always() && needs.admission.outputs.signed_qualification == 'true' && needs.candidate.result == 'success' }}
1449
+ environment: ${releaseEnvironment(manifest, "qualification")}
1450
+ runs-on: \${{ vars.${chain.qualificationRunnerVariable} || '${windowsRunner}' }}
1451
+ steps:
1452
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
1453
+ with:
1454
+ ref: \${{ needs.admission.outputs.source_revision }}
1455
+ fetch-depth: 0
1456
+ persist-credentials: false
1457
+ - name: Fail closed when protected finalization is absent
1458
+ if: \${{ needs.windows-sign.result != 'success' }}
1459
+ shell: pwsh
1460
+ run: |
1461
+ throw 'installed_qualification_failed { reason: prerequisites_absent, detail: "same-run Windows signing/finalization did not succeed" }'
1462
+ - name: Download same-run finalized Windows release
1463
+ uses: actions/download-artifact@${DOWNLOAD_ARTIFACT_SHA} # v4.3.0
1464
+ with:
1465
+ name: ${windowsSignedArtifact}
1466
+ path: \${{ runner.temp }}/right-git-release/windows
1467
+ - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
1468
+ with:
1469
+ node-version: ${String(manifest.matrix.node[0])}
1470
+ package-manager-cache: false
1471
+ ${pm.setup}
1472
+ - run: ${pm.installCommand}
1473
+ - name: Initialize installed-qualification stage summary
1474
+ run: ${pm.runPrefix} ${manifest.candidate.stageSummaryScript}
1475
+ env:
1476
+ RIGHT_GIT_STAGE_ACTION: init
1477
+ RIGHT_GIT_STAGE_ROOT: \${{ runner.temp }}/right-git-stage-summary
1478
+ RIGHT_GIT_STAGE_EVIDENCE_ROOT: \${{ runner.temp }}/right-git-release/qualification
1479
+ RIGHT_GIT_STAGE: installed-qualification
1480
+ RIGHT_GIT_STAGE_PRODUCER: installed-qualification
1481
+ RIGHT_GIT_RELEASE_VERSION: \${{ needs.admission.outputs.version }}
1482
+ RIGHT_GIT_SOURCE_REVISION: \${{ needs.admission.outputs.source_revision }}
1483
+ ${runIdentityEnv}
1484
+ - name: Run installed-artifact qualification
1485
+ run: ${pm.runPrefix} ${chain.installedQualificationScript}
1486
+ env:
1487
+ GH_TOKEN: \${{ github.token }}
1488
+ RIGHT_GIT_FINALIZED_WINDOWS_ROOT: \${{ runner.temp }}/right-git-release/windows
1489
+ RIGHT_GIT_QUALIFICATION_EVIDENCE_ROOT: \${{ runner.temp }}/right-git-release/qualification
1490
+ RIGHT_GIT_RELEASE_VERSION: \${{ needs.admission.outputs.version }}
1491
+ RIGHT_GIT_SOURCE_REVISION: \${{ needs.admission.outputs.source_revision }}
1492
+ - name: Finalize installed-qualification stage summary
1493
+ if: \${{ always() }}
1494
+ run: ${pm.runPrefix} ${manifest.candidate.stageSummaryScript}
1495
+ env:
1496
+ RIGHT_GIT_STAGE_ACTION: finalize
1497
+ RIGHT_GIT_STAGE_ROOT: \${{ runner.temp }}/right-git-stage-summary
1498
+ RIGHT_GIT_STAGE_EVIDENCE_ROOT: \${{ runner.temp }}/right-git-release/qualification
1499
+ RIGHT_GIT_STAGE: installed-qualification
1500
+ RIGHT_GIT_STAGE_PRODUCER: installed-qualification
1501
+ RIGHT_GIT_STAGE_STATUS: \${{ job.status == 'success' && 'SUCCEEDED' || 'FAILED' }}
1502
+ RIGHT_GIT_STAGE_EXIT_CODE: \${{ job.status == 'success' && '0' || '1' }}
1503
+ RIGHT_GIT_RELEASE_VERSION: \${{ needs.admission.outputs.version }}
1504
+ RIGHT_GIT_SOURCE_REVISION: \${{ needs.admission.outputs.source_revision }}
1505
+ ${runIdentityEnv}
1506
+ - name: Upload installed qualification evidence
1507
+ if: \${{ always() }}
1508
+ uses: actions/upload-artifact@${UPLOAD_ARTIFACT_SHA} # v4
1509
+ with:
1510
+ name: ${qualificationArtifact}
1511
+ path: \${{ runner.temp }}/right-git-release/qualification/**
1512
+ if-no-files-found: error
1513
+ - name: Upload installed-qualification stage summary
1514
+ if: \${{ always() }}
1515
+ uses: actions/upload-artifact@${UPLOAD_ARTIFACT_SHA} # v4
1516
+ with:
1517
+ name: ${qualificationSummaryArtifact}
1518
+ path: \${{ runner.temp }}/right-git-stage-summary/stage-summary.json
1519
+ if-no-files-found: error
1520
+ publish:
1521
+ needs: [admission, installed-qualification${macosDependency}]
1522
+ if: \${{ needs.admission.outputs.publish == 'true' && needs.installed-qualification.result == 'success'${macosSuccess} }}
1523
+ environment: ${releaseEnvironment(manifest, "publication")}
1524
+ runs-on: \${{ vars.${chain.qualificationRunnerVariable} || '${windowsRunner}' }}
1525
+ permissions:
1526
+ contents: write
1527
+ steps:
1528
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
1529
+ with:
1530
+ ref: \${{ needs.admission.outputs.source_revision }}
1531
+ fetch-depth: 0
1532
+ persist-credentials: false
1533
+ - name: Download same-run finalized Windows release
1534
+ uses: actions/download-artifact@${DOWNLOAD_ARTIFACT_SHA} # v4.3.0
1535
+ with:
1536
+ name: ${windowsSignedArtifact}
1537
+ path: \${{ runner.temp }}/right-git-release/windows
1538
+ ${macosDownload}
1539
+ - name: Download same-run installed qualification evidence
1540
+ uses: actions/download-artifact@${DOWNLOAD_ARTIFACT_SHA} # v4.3.0
1541
+ with:
1542
+ name: ${qualificationArtifact}
1543
+ path: \${{ runner.temp }}/right-git-release/qualification
1544
+ - name: Download same-run candidate (Windows) stage summary
1545
+ uses: actions/download-artifact@${DOWNLOAD_ARTIFACT_SHA} # v4.3.0
1546
+ with:
1547
+ name: ${candidateWindowsSummaryArtifact}
1548
+ path: \${{ runner.temp }}/right-git-release/stage-summaries/candidate-windows
1549
+ ${candidateMacosSummaryDownload}
1550
+ - name: Download same-run Windows signing stage summary
1551
+ uses: actions/download-artifact@${DOWNLOAD_ARTIFACT_SHA} # v4.3.0
1552
+ with:
1553
+ name: ${windowsSummaryArtifact}
1554
+ path: \${{ runner.temp }}/right-git-release/stage-summaries/windows-sign
1555
+ ${macosSummaryDownload}
1556
+ - name: Download same-run installed-qualification stage summary
1557
+ uses: actions/download-artifact@${DOWNLOAD_ARTIFACT_SHA} # v4.3.0
1558
+ with:
1559
+ name: ${qualificationSummaryArtifact}
1560
+ path: \${{ runner.temp }}/right-git-release/stage-summaries/installed-qualification
1561
+ - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
1562
+ with:
1563
+ node-version: ${String(manifest.matrix.node[0])}
1564
+ package-manager-cache: false
1565
+ ${pm.setup}
1566
+ - run: ${pm.installCommand}
1567
+ - name: Verify aggregated release evidence
1568
+ run: ${pm.runPrefix} ${chain.evidenceVerificationScript}
1569
+ env:
1570
+ GH_TOKEN: \${{ github.token }}
1571
+ RIGHT_GIT_FINALIZED_WINDOWS_ROOT: \${{ runner.temp }}/right-git-release/windows${finalizedMacosEnv}
1572
+ RIGHT_GIT_QUALIFICATION_EVIDENCE_ROOT: \${{ runner.temp }}/right-git-release/qualification
1573
+ RIGHT_GIT_STAGE_SUMMARY_ROOT: \${{ runner.temp }}/right-git-release/stage-summaries
1574
+ RIGHT_GIT_RELEASE_VERSION: \${{ needs.admission.outputs.version }}
1575
+ RIGHT_GIT_SOURCE_REVISION: \${{ needs.admission.outputs.source_revision }}
1576
+ ${runIdentityEnv}
1577
+ - name: Publish qualified signed release
1578
+ run: ${pm.runPrefix} ${chain.publishScript}
1579
+ env:
1580
+ GH_TOKEN: \${{ github.token }}
1581
+ RIGHT_GIT_FINALIZED_WINDOWS_ROOT: \${{ runner.temp }}/right-git-release/windows${finalizedMacosEnv}
1582
+ RIGHT_GIT_QUALIFICATION_EVIDENCE_ROOT: \${{ runner.temp }}/right-git-release/qualification
1583
+ RIGHT_GIT_STAGE_SUMMARY_ROOT: \${{ runner.temp }}/right-git-release/stage-summaries
1584
+ RIGHT_GIT_RELEASE_VERSION: \${{ needs.admission.outputs.version }}
1585
+ RIGHT_GIT_SOURCE_REVISION: \${{ needs.admission.outputs.source_revision }}
1586
+ ${runIdentityEnv}
1587
+ ${publishSecretEnvironment}
1588
+ `.trimEnd();
1589
+ }
1590
+
1591
+ /**
1592
+ * Derive one project name from the target repo's package.json, falling back
1593
+ * to the repo directory's basename. Never throws.
1594
+ */
1595
+ export function deriveProjectName(repoPath) {
1596
+ try {
1597
+ const pkgRaw = fs.readFileSync(path.join(repoPath, "package.json"), "utf8");
1598
+ const pkg = JSON.parse(pkgRaw);
1599
+ if (typeof pkg.name === "string" && pkg.name.length > 0) {
1600
+ return pkg.name.replace(/^@[^/]+\//, "");
1601
+ }
1602
+ } catch {
1603
+ // fall through to directory name
1604
+ }
1605
+ return path.basename(path.resolve(repoPath));
1606
+ }
1607
+
1608
+ /**
1609
+ * Build the flat placeholder -> value map used by render.mjs, from a
1610
+ * validated manifest plus the target repo's derived project name.
1611
+ */
1612
+ /** Every managed public workflow runs ownership scanning; repository metadata cannot opt it out. */
1613
+ export function ownershipStep(manifest, lane = "ci") {
1614
+ const { name } = parsePackageManager(manifest.packageManager);
1615
+ const command = name === "pnpm" ? "pnpm exec right-release ownership --app ."
1616
+ : name === "npm" ? "npm exec -- right-release ownership --app ."
1617
+ : "yarn exec right-release ownership --app .";
1618
+ // Every lane stays advisory until ownership approval keys are enrolled (Adrian, 2026-10-09);
1619
+ // once enrolled, the flag is inert and findings block again.
1620
+ const ownershipCommand = `${command} --advisory-when-pending`;
1621
+ // Only release-candidate dispatches declare source_revision. Referencing
1622
+ // inputs.source_revision from other lanes makes actionlint reject their
1623
+ // generated workflows, even when guarded by an event-name expression.
1624
+ // rust-hybrid release-candidate is dispatch-only. The node release-candidate
1625
+ // also runs on a v* tag push, which has no input: it compares against the
1626
+ // pushed commit instead.
1627
+ const sourceRevision = lane !== "release-candidate"
1628
+ ? "\${{ github.sha }}"
1629
+ : manifest.profile === "rust-hybrid"
1630
+ ? "\${{ inputs.source_revision }}"
1631
+ : "\${{ inputs.source_revision || github.sha }}";
1632
+ return `\n - name: RightKit ownership (protected registry roots)\n shell: bash\n run: test "$(git rev-parse HEAD)" = "${sourceRevision}" && ${ownershipCommand}`;
1633
+ }
1634
+
1635
+ /**
1636
+ * pnpm stale-lockfile hint for the ci lane. The step runs only when the step
1637
+ * before it (the frozen install) failed. It regenerates the lockfile with
1638
+ * `pnpm install --lockfile-only` and prints the lockfile's git diff as a patch
1639
+ * block. It never changes the job result, which the failed install already
1640
+ * decided. Returns "" for npm and yarn, so their renders stay unchanged.
1641
+ */
1642
+ export function lockfilePatchStep(manifest) {
1643
+ const { name } = parsePackageManager(manifest.packageManager);
1644
+ if (name !== "pnpm") return "";
1645
+ return [
1646
+ "",
1647
+ " - name: Print pnpm-lock.yaml patch when the lockfile is stale",
1648
+ " if: failure()",
1649
+ " shell: bash",
1650
+ " run: |",
1651
+ " if pnpm install --lockfile-only; then",
1652
+ " if git diff --quiet -- pnpm-lock.yaml; then",
1653
+ ' echo "::notice::pnpm-lock.yaml already matches package.json; the frozen install failed for another reason."',
1654
+ " else",
1655
+ ' echo "::group::pnpm-lock.yaml patch (apply and commit)"',
1656
+ " git diff -- pnpm-lock.yaml",
1657
+ ' echo "::endgroup::"',
1658
+ ' echo "::error file=pnpm-lock.yaml::pnpm-lock.yaml is stale; commit the patch above."',
1659
+ " fi",
1660
+ " else",
1661
+ ' echo "::error::pnpm install --lockfile-only failed; no lockfile patch was produced."',
1662
+ " fi",
1663
+ ].join("\n");
1664
+ }
1665
+
1666
+ /**
1667
+ * swift.privatePackages: configure step, placed directly before the first step
1668
+ * in each opted-in job that builds or tests project code (the ci job, the
1669
+ * qualification job, the release-candidate candidate job, the regenerate job and
1670
+ * the parallel dev-artifact-mac job). It refuses to overwrite an
1671
+ * existing ~/.netrc, writes one machine entry per private host with mode 600,
1672
+ * and adds a job-scoped git insteadOf rewrite. The token reaches the step only
1673
+ * through env, never through the run script text. Returns "" when unset; the
1674
+ * value starts with a newline and has no trailing newline.
1675
+ */
1676
+ export function swiftPrivatePackagesConfigureStep(manifest) {
1677
+ const entries = manifest.swift?.privatePackages;
1678
+ if (!Array.isArray(entries) || entries.length === 0) return "";
1679
+ const env = entries.map((entry, index) => ` RIGHT_GIT_PRIVATE_TOKEN_${index}: \${{ secrets.${entry.secret} }}`);
1680
+ const checks = entries.map((entry, index) => ` test -n "$RIGHT_GIT_PRIVATE_TOKEN_${index}" || { echo "::error::right-git: secret ${entry.secret} is unavailable to this run"; exit 1; }`);
1681
+ const netrc = entries.map((entry, index) => ` printf 'machine %s\\nlogin x-access-token\\npassword %s\\n' '${entry.host}' "$RIGHT_GIT_PRIVATE_TOKEN_${index}" >> "$HOME/.netrc"`);
1682
+ const insteadOf = entries.map((entry, index) => ` git config --global "url.https://x-access-token:$RIGHT_GIT_PRIVATE_TOKEN_${index}@${entry.host}/.insteadOf" "https://${entry.host}/"`);
1683
+ return [
1684
+ "",
1685
+ " - name: Configure private Swift package access",
1686
+ " shell: bash",
1687
+ " env:",
1688
+ ...env,
1689
+ " run: |",
1690
+ " set -euo pipefail",
1691
+ " umask 077",
1692
+ ...checks,
1693
+ " test ! -e \"$HOME/.netrc\" || { echo \"::error::right-git: $HOME/.netrc already exists on this runner; refusing to overwrite it\"; exit 1; }",
1694
+ " : > \"$HOME/.netrc\"",
1695
+ // The marker follows creation so cleanup removes this file even if a later line fails.
1696
+ " : > \"$RUNNER_TEMP/right-git-private-netrc\"",
1697
+ ...netrc,
1698
+ " chmod 600 \"$HOME/.netrc\"",
1699
+ ...insteadOf,
1700
+ ].join("\n");
1701
+ }
1702
+
1703
+ /**
1704
+ * swift.privatePackages: cleanup step, rendered after the last step that builds
1705
+ * or tests project code in the same job (the end of the ci job; before any
1706
+ * push or upload elsewhere) and run even after a failed build. It only removes
1707
+ * what the configure step created (the marker file), so a cancelled run never
1708
+ * deletes a pre-existing ~/.netrc. Returns "" when unset; same newline convention as the configure step.
1709
+ */
1710
+ export function swiftPrivatePackagesCleanupStep(manifest) {
1711
+ const entries = manifest.swift?.privatePackages;
1712
+ if (!Array.isArray(entries) || entries.length === 0) return "";
1713
+ const env = entries.map((entry, index) => ` RIGHT_GIT_PRIVATE_TOKEN_${index}: \${{ secrets.${entry.secret} }}`);
1714
+ const removals = entries.map((entry, index) => ` git config --global --remove-section "url.https://x-access-token:$RIGHT_GIT_PRIVATE_TOKEN_${index}@${entry.host}/" || true`);
1715
+ return [
1716
+ "",
1717
+ " - name: Remove private Swift package access",
1718
+ " if: ${{ always() }}",
1719
+ " shell: bash",
1720
+ " env:",
1721
+ ...env,
1722
+ " run: |",
1723
+ " if [ -f \"$RUNNER_TEMP/right-git-private-netrc\" ]; then",
1724
+ " rm -f \"$HOME/.netrc\"",
1725
+ ...removals,
1726
+ " rm -f \"$RUNNER_TEMP/right-git-private-netrc\"",
1727
+ " fi",
1728
+ ].join("\n");
1729
+ }
1730
+
1731
+ /**
1732
+ * Optional QA evidence upload, rendered after the rust-hybrid gate step.
1733
+ * Returns "" when qaEvidencePath is unset, so the rendered workflow stays
1734
+ * byte-identical to a manifest without the key.
1735
+ */
1736
+ export function qaEvidenceStep(manifest) {
1737
+ if (manifest.qaEvidencePath === undefined) return "";
1738
+ const retentionDays = manifest.qaEvidenceRetentionDays ?? QA_EVIDENCE_DEFAULT_RETENTION_DAYS;
1739
+ return [
1740
+ " - name: Upload QA evidence",
1741
+ " if: always()",
1742
+ ` uses: ${UPLOAD_ARTIFACT_PIN}`,
1743
+ " with:",
1744
+ " name: qa-evidence-${{ matrix.os || runner.os }}-${{ github.run_attempt }}",
1745
+ ` path: \${{ runner.temp }}/${manifest.qaEvidencePath}`,
1746
+ ` retention-days: ${retentionDays}`,
1747
+ " if-no-files-found: ignore",
1748
+ "",
1749
+ ].join("\n");
1750
+ }
1751
+
1752
+ export function buildRenderContext(manifest, repoPath, lane = "ci") {
1753
+ const pm = parsePackageManager(manifest.packageManager);
1754
+ const projectName = deriveProjectName(repoPath);
1755
+ const artifactPrefix = projectName.toLowerCase().replace(/[^a-z0-9-]+/g, "-");
1756
+ const rustWorkspaces = manifest.rustCache?.workspaces ?? ["engine"];
1757
+ const configuredWindowsRunner = manifest.matrix.os.find((runner) => runner.startsWith("windows-"));
1758
+ const ciOs = configuredWindowsRunner ?? manifest.matrix.os[0];
1759
+ const ciMatrixOs = manifest.ciAllOs === true
1760
+ ? [
1761
+ " # ciAllOs: the gate runs on every matrix.os runner, in declared order.",
1762
+ ` os: ${yamlFlowStringList(manifest.matrix.os)}`,
1763
+ ]
1764
+ : [
1765
+ " # Full validation stays on one declared runner; prefer configured",
1766
+ " # Windows when available, otherwise preserve first configured OS.",
1767
+ ` os: ${yamlFlowStringList([ciOs])}`,
1768
+ ];
1769
+
1770
+ const cacheKeyLine = rustCacheKeyLine(manifest, lane);
1771
+ const context = {
1772
+ OS_MATRIX: yamlFlowStringList(manifest.matrix.os),
1773
+ CI_MATRIX_OS: ciMatrixOs.join("\n"),
1774
+ NODE_MATRIX: yamlFlowStringList(manifest.matrix.node),
1775
+ NODE_PUBLISH_VERSION: JSON.stringify(String(manifest.matrix.node[0])),
1776
+ PM_NAME: pm.name,
1777
+ PM_VERSION: pm.version,
1778
+ PM_CACHE: pm.name,
1779
+ INSTALL_COMMAND: pm.installCommand,
1780
+ PM_RUN: pm.runPrefix,
1781
+ PACKAGE_MANAGER_SETUP: pm.setup,
1782
+ ARTIFACT_PREFIX: artifactPrefix,
1783
+ DEFAULT_BRANCH: manifest.defaultBranch ?? "main",
1784
+ TEMPLATE_VERSION: manifest.templateVersion,
1785
+ RUST_CACHE_WORKSPACES: rustWorkspaces.map((workspace) => ` ${workspace} -> target`).join("\n"),
1786
+ RUST_REQUIRED_FOR_GATE: manifest.rustCache?.requiredForGate === true ? "true" : "false",
1787
+ WINDOWS_SIGNING_JOB: windowsSigningJob(manifest, pm, artifactPrefix),
1788
+ MACOS_SIGNING_JOB: macosSigningJob(manifest, pm, artifactPrefix),
1789
+ RELEASE_CHAIN_JOBS: releaseChainJobs(manifest, pm, artifactPrefix),
1790
+ OWNERSHIP_STEP: ownershipStep(manifest, lane),
1791
+ PNPM_LOCK_PATCH_STEP: lockfilePatchStep(manifest),
1792
+ SWIFT_PRIVATE_CONFIGURE_STEP: swiftPrivatePackagesConfigureStep(manifest),
1793
+ SWIFT_PRIVATE_CLEANUP_STEP: swiftPrivatePackagesCleanupStep(manifest),
1794
+ QA_EVIDENCE_STEP: qaEvidenceStep(manifest) + devArtifactCi(manifest, { lane, artifactPrefix }),
1795
+ CI_DISPATCH_TRIGGER: devArtifactDispatchTrigger(manifest),
1796
+ CI_CACHE_WORKSPACE_CRATES: manifest.ciIncremental === true ? "true" : "false",
1797
+ CI_CARGO_INCREMENTAL: manifest.ciIncremental === true ? "1" : "0",
1798
+ // sccache refuses CARGO_INCREMENTAL=1; incremental CI relies on the rust-cache target dir instead.
1799
+ CI_RUSTC_WRAPPER: manifest.ciIncremental === true ? '""' : "${{ steps.rust-changes.outputs.required == 'true' && 'sccache' || '' }}",
1800
+ CI_DERIVED_DATA_STEP: derivedDataStep(manifest),
1801
+ CI_CANCEL_IN_PROGRESS: manifest.concurrency?.mainPushes === "queue" ? CI_CANCEL_MAIN_QUEUE_EXPRESSION : "true",
1802
+ RUST_CACHE_KEY: cacheKeyLine ? `${cacheKeyLine}\n` : "",
1803
+ };
1804
+
1805
+ // Every key below is populated ONLY when its source manifest section is
1806
+ // actually present — mirroring the publish.npm/homebrew/winget pattern.
1807
+ // This keeps the fail-closed check just below honest: a key that is
1808
+ // legitimately inapplicable to this manifest (e.g. CANDIDATE_* for a
1809
+ // non-rust-hybrid manifest, GATE_PATH for a non-rust-hybrid profile) is
1810
+ // simply ABSENT from the context rather than present-with-undefined, so
1811
+ // render.mjs's own `Object.hasOwn` check does the right thing if a
1812
+ // template ever references a token this manifest didn't opt into.
1813
+ if (manifest.gate) {
1814
+ context.GATE_PATH = manifest.gate.path;
1815
+ }
1816
+ if (manifest.regenerate) {
1817
+ context.REGENERATE_SCRIPT = manifest.regenerate.script;
1818
+ }
1819
+ if (manifest.candidate) {
1820
+ context.CANDIDATE_BUILD_SCRIPT = manifest.candidate.buildScript;
1821
+ context.CANDIDATE_CHECK_SCRIPT = manifest.candidate.checkScript;
1822
+ context.CANDIDATE_ARTIFACT_ROOT = manifest.candidate.artifactRoot;
1823
+ context.CANDIDATE_OS_MATRIX = yamlFlowStringList(manifest.candidate.os ?? manifest.matrix.os);
1824
+ context.CANDIDATE_MATRIX = candidateMatrix(manifest);
1825
+ // admissionScript & stageSummaryScript are required candidate fields
1826
+ // (see validateManifest) whenever release-candidate is configured at
1827
+ // all — the admission job and the candidate job's stage-summary steps
1828
+ // are unconditional parts of the rendered template, independent of
1829
+ // signing/releaseChain.
1830
+ context.RELEASE_ADMISSION_SCRIPT = manifest.candidate.admissionScript;
1831
+ context.RELEASE_STAGE_SUMMARY_SCRIPT = manifest.candidate.stageSummaryScript;
1832
+ }
1833
+
1834
+ if (manifest.publish?.npm) {
1835
+ context.NPM_PROVENANCE_FLAG = manifest.publish.npm.provenance ? " --provenance" : "";
1836
+ }
1837
+ if (manifest.publish?.homebrew) {
1838
+ context.HOMEBREW_TAP = manifest.publish.homebrew.tap;
1839
+ context.HOMEBREW_FORMULA_NAME = manifest.publish.homebrew.formulaName;
1840
+ }
1841
+ if (manifest.publish?.winget) {
1842
+ context.WINGET_PACKAGE_IDENTIFIER = manifest.publish.winget.packageIdentifier;
1843
+ }
1844
+
1845
+ // F-undefined-script fix: render.mjs's `Object.hasOwn` check only proves a
1846
+ // key EXISTS in the context — it does not prove the key resolved to a real
1847
+ // value. Every field above that is sourced from an optional manifest path
1848
+ // (candidate.*, candidate.releaseChain.* via the job-builder functions,
1849
+ // gate.path) must resolve to a real string once its guarding `if` above
1850
+ // decided the section applies; a bug in one of those guards (or a
1851
+ // mis-nested manifest field) must fail the render loudly here rather than
1852
+ // silently emit a literal "undefined" into a workflow file that GitHub
1853
+ // Actions will then try to execute as a real step (e.g. `run: pnpm run
1854
+ // undefined`).
1855
+ for (const [key, value] of Object.entries(context)) {
1856
+ if (value === undefined || value === null) {
1857
+ throw new Error(`buildRenderContext: placeholder \${${key}} resolved to ${value} — check the manifest's candidate/releaseChain/gate/publish configuration`);
1858
+ }
1859
+ }
1860
+
1861
+ return context;
1862
+ }