@rightkit/ci 0.2.45 → 0.2.49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +57 -3
- package/checkout.test.mjs +1 -0
- package/guard-coverage.test.mjs +1 -0
- package/manifest.mjs +539 -27
- package/manifest.schema.json +101 -6
- package/manifest.test.mjs +48 -0
- package/package.json +1 -1
- package/render.test.mjs +362 -27
- package/supersede.mjs +127 -0
- package/supersede.test.mjs +84 -0
- package/swift-check.test.mjs +95 -0
- package/templates/ci.yml +4 -4
- package/templates/profiles/rust-hybrid/ci.yml +4 -4
- package/templates/profiles/rust-hybrid/release-candidate.yml +2 -1
- package/templates/profiles/rust-hybrid/sign-existing.yml +36 -0
- package/templates/swift-check.yml +85 -0
package/render.test.mjs
CHANGED
|
@@ -32,7 +32,8 @@ function renderAllLanes(manifest, repoPath) {
|
|
|
32
32
|
for (const lane of manifest.lanes) {
|
|
33
33
|
const templatePath = path.join(templatesDir, LANE_FILENAMES[lane]);
|
|
34
34
|
const templateText = fs.readFileSync(templatePath, "utf8");
|
|
35
|
-
|
|
35
|
+
const configured = lane === "swift-check" ? { ...manifest, swift: { ...manifest.swift, check: { runner: "macos-15", xcodeVersion: "16.4", projectDirectory: "ios", spec: "project.yml", project: "Widgets.xcodeproj", scheme: "Widgets", xcodegenVersion: "2.44.1" } } } : manifest;
|
|
36
|
+
rendered[lane] = renderTemplate(templateText, buildRenderContext(configured, repoPath, lane));
|
|
36
37
|
}
|
|
37
38
|
return rendered;
|
|
38
39
|
}
|
|
@@ -55,8 +56,8 @@ test("rust-hybrid ci renders its pinned package manager and gate", () => {
|
|
|
55
56
|
assert.match(content, /version: 11\.24\.0/);
|
|
56
57
|
assert.match(content, /components: rustfmt, clippy/);
|
|
57
58
|
assert.doesNotMatch(content, /toolchain:/);
|
|
58
|
-
assert.match(content, /group: \$\{\{ github\.workflow \}\}-\$\{\{ github\.ref \}\}/);
|
|
59
|
-
assert.match(content, /cancel-in-progress:
|
|
59
|
+
assert.match(content, /group: \$\{\{ github\.workflow \}\}-\$\{\{ github\.event_name == 'push'[^\n]*github\.run_id \|\| github\.ref \}\}/);
|
|
60
|
+
assert.match(content, /cancel-in-progress: \$\{\{ !\(github\.event_name == 'push' && github\.ref_name == github\.event\.repository\.default_branch\) \}\}/);
|
|
60
61
|
assert.match(content, /bash \.\/scripts\/gate\.sh/);
|
|
61
62
|
assert.match(content, /name: Detect Rust-affecting changes\n id: rust-changes/);
|
|
62
63
|
assert.match(content, /RIGHT_GIT_DIFF_BASE: \$\{\{ github\.event_name == 'pull_request' && github\.event\.pull_request\.base\.sha \|\| '' \}\}/);
|
|
@@ -96,10 +97,10 @@ test("every generated workflow profile runs ownership scanning independent of op
|
|
|
96
97
|
for (const [lane, content] of Object.entries(withoutRoots)) assert.match(content, /right-release ownership --app \./, lane);
|
|
97
98
|
});
|
|
98
99
|
|
|
99
|
-
test("ordinary CI templates cancel superseded runs on the same ref", () => {
|
|
100
|
+
test("ordinary CI templates cancel superseded pull-request runs on the same ref", () => {
|
|
100
101
|
const generic = renderAllLanes(FULL_MANIFEST, "/repos/widgets").ci;
|
|
101
|
-
assert.match(generic, /group: \$\{\{ github\.workflow \}\}-\$\{\{ github\.ref \}\}/);
|
|
102
|
-
assert.match(generic, /cancel-in-progress:
|
|
102
|
+
assert.match(generic, /group: \$\{\{ github\.workflow \}\}-\$\{\{ github\.event_name == 'push'[^\n]*github\.run_id \|\| github\.ref \}\}/);
|
|
103
|
+
assert.match(generic, /cancel-in-progress: \$\{\{ !\(github\.event_name == 'push' && github\.ref_name == github\.event\.repository\.default_branch\) \}\}/);
|
|
103
104
|
});
|
|
104
105
|
|
|
105
106
|
test("ownership revision expression matches each lane trigger contract", () => {
|
|
@@ -156,6 +157,36 @@ test("rust-hybrid ci runs every matrix.os runner when ciAllOs is true, in declar
|
|
|
156
157
|
assert.equal(render({ ...base, ciAllOs: false }), render(base));
|
|
157
158
|
});
|
|
158
159
|
|
|
160
|
+
test("rust-hybrid ci skips the ownership step on a Linux ciAllOs leg and is otherwise unchanged", () => {
|
|
161
|
+
const base = {
|
|
162
|
+
...FULL_MANIFEST,
|
|
163
|
+
lanes: ["ci"],
|
|
164
|
+
profile: "rust-hybrid",
|
|
165
|
+
gate: { path: "scripts/gate.sh" },
|
|
166
|
+
matrix: { os: ["macos-15", "windows-2025", "ubuntu-24.04"], node: ["26.8.1"] },
|
|
167
|
+
};
|
|
168
|
+
const render = (manifest) => renderTemplate(
|
|
169
|
+
fs.readFileSync(path.join(templatesDir, "profiles/rust-hybrid/ci.yml"), "utf8"),
|
|
170
|
+
buildRenderContext(manifest, "/repos/ember"),
|
|
171
|
+
);
|
|
172
|
+
const guarded = " - name: RightKit ownership (protected registry roots)\n if: ${{ runner.os != 'Linux' }}\n shell: bash\n";
|
|
173
|
+
const all = render({ ...base, ciAllOs: true });
|
|
174
|
+
assert.match(all, /^ {8}os: \["macos-15", "windows-2025", "ubuntu-24\.04"\]$/m);
|
|
175
|
+
assert.ok(all.includes(guarded));
|
|
176
|
+
// Not ciAllOs: single runner, step unguarded; the Linux guard never appears.
|
|
177
|
+
for (const manifest of [base, { ...base, ciAllOs: false }]) {
|
|
178
|
+
const single = render(manifest);
|
|
179
|
+
assert.doesNotMatch(single, /runner\.os != 'Linux'/);
|
|
180
|
+
assert.match(single, /RightKit ownership \(protected registry roots\)\n shell: bash\n/);
|
|
181
|
+
}
|
|
182
|
+
// ciAllOs without a Linux runner renders byte-identically to before.
|
|
183
|
+
const noLinux = { ...base, matrix: { os: ["macos-15", "windows-2025"], node: ["26.8.1"] }, ciAllOs: true };
|
|
184
|
+
assert.doesNotMatch(render(noLinux), /runner\.os != 'Linux'/);
|
|
185
|
+
assert.match(render(noLinux), /RightKit ownership \(protected registry roots\)\n shell: bash\n/);
|
|
186
|
+
// The guard is the only difference the Linux runner makes to the ownership step.
|
|
187
|
+
assert.equal(all.split(guarded).length, 2);
|
|
188
|
+
});
|
|
189
|
+
|
|
159
190
|
test("rust-hybrid release candidate renders product scripts, artifact handoff, and no signing secret", () => {
|
|
160
191
|
const manifest = {
|
|
161
192
|
...FULL_MANIFEST,
|
|
@@ -304,6 +335,8 @@ test("rust-hybrid release candidate can opt into OIDC Windows signing without lo
|
|
|
304
335
|
assert.match(content, /vars\.AZURE_CLIENT_ID/);
|
|
305
336
|
assert.match(content, /right-release build --platform win --skip-checks/);
|
|
306
337
|
assert.match(content, /Artifact Signing client hash mismatch/);
|
|
338
|
+
// #183: the signing step reads a source QA receipt carried in the downloaded candidate handoff.
|
|
339
|
+
assert.ok(content.includes("RIGHT_RELEASE_QA_RECEIPT: ${{ runner.temp }}/unsigned-windows-candidate/qa"));
|
|
307
340
|
// Every downstream job (admission, candidate, and windows-sign here) checks
|
|
308
341
|
// out the exact admitted revision by SHA, never by resolving HEAD after a
|
|
309
342
|
// ref-triggered checkout.
|
|
@@ -348,6 +381,7 @@ test("rust-hybrid release candidate can opt into protected macOS signing & notar
|
|
|
348
381
|
assert.match(content, /temporary keychain/i);
|
|
349
382
|
assert.match(content, /right-release build --platform mac --skip-checks/);
|
|
350
383
|
assert.match(content, /secrets\.APPLE_API_KEY_BASE64/);
|
|
384
|
+
assert.ok(content.includes("RIGHT_RELEASE_QA_RECEIPT: ${{ runner.temp }}/unsigned-macos-candidate/qa"));
|
|
351
385
|
assert.match(content, /macos-sign:[\s\S]*?ref: \$\{\{ needs\.admission\.outputs\.source_revision \}\}\n\s+fetch-depth: 0\n\s+persist-credentials: false/);
|
|
352
386
|
assert.match(content, /git rev-parse HEAD.*inputs\.source_revision/);
|
|
353
387
|
assert.ok(content.includes("LEGION_SOURCE_REVISION: ${{ needs.admission.outputs.source_revision }}"));
|
|
@@ -1074,6 +1108,159 @@ test("devArtifact entitlements add a checkout and --entitlements", () => {
|
|
|
1074
1108
|
assert.match(out.split(" dev-mac-sign:")[1], /actions\/checkout@/);
|
|
1075
1109
|
});
|
|
1076
1110
|
|
|
1111
|
+
// Orthic-Labs/rightkit#257: macSignManifest swaps `codesign --deep` for the per-file sign-dev-artifact command.
|
|
1112
|
+
const PER_FILE_DEV = { ...DEV_MANIFEST.devArtifact, macSignManifest: "build/dev-sign.json", macPayloadMetadata: "Pulse.app/Contents/Resources/payload.json" };
|
|
1113
|
+
|
|
1114
|
+
test("devArtifact macSignManifest signs per file through right-release sign-dev-artifact, not codesign --deep", () => {
|
|
1115
|
+
const out = renderRustCi({ ...DEV_MANIFEST, devArtifact: PER_FILE_DEV });
|
|
1116
|
+
const sign = out.split(" dev-mac-sign:")[1];
|
|
1117
|
+
assert.doesNotMatch(sign, /codesign --force --deep/);
|
|
1118
|
+
assert.match(sign, /pnpm exec right-release sign-dev-artifact --artifact "\$work" --manifest "\$GITHUB_WORKSPACE\/build\/dev-sign\.json" --metadata "\$work\/Pulse\.app\/Contents\/Resources\/payload\.json" --evidence "\$RUNNER_TEMP\/dev-signed\/sign-evidence\.json"/);
|
|
1119
|
+
assert.match(sign, /actions\/checkout@[\s\S]*actions\/setup-node@[\s\S]*pnpm install --frozen-lockfile[\s\S]*Install Apple signing identity/);
|
|
1120
|
+
assert.match(sign, /sign-evidence\.json\n/);
|
|
1121
|
+
assert.doesNotMatch(sign, /notarytool/, "the per-file lane never notarizes");
|
|
1122
|
+
});
|
|
1123
|
+
|
|
1124
|
+
test("devArtifact without macSignManifest keeps the codesign --deep lane", () => {
|
|
1125
|
+
const out = renderRustCi(DEV_MANIFEST);
|
|
1126
|
+
assert.match(out.split(" dev-mac-sign:")[1], /codesign --force --deep --strict --options runtime --timestamp --sign "\$APPLE_DEVELOPER_ID" "\$app"\n codesign --verify --deep --strict "\$app"/);
|
|
1127
|
+
assert.doesNotMatch(out, /sign-dev-artifact/);
|
|
1128
|
+
});
|
|
1129
|
+
|
|
1130
|
+
test("devArtifact macSignManifest validation", () => {
|
|
1131
|
+
const check = (devArtifact) => validateManifest({ ...DEV_MANIFEST, regenerate: undefined, devArtifact });
|
|
1132
|
+
assert.equal(check(PER_FILE_DEV).valid, true);
|
|
1133
|
+
assert.equal(check({ ...PER_FILE_DEV, macPayloadMetadata: undefined }).valid, false, "metadata path required");
|
|
1134
|
+
assert.equal(check({ ...PER_FILE_DEV, mac: "notarize" }).valid, false, "no notarize");
|
|
1135
|
+
assert.equal(check({ ...PER_FILE_DEV, mac: "unsigned" }).valid, false, "needs sign");
|
|
1136
|
+
assert.equal(check({ ...PER_FILE_DEV, macEntitlements: "build/pulse.entitlements" }).valid, false, "no entitlements beside a manifest");
|
|
1137
|
+
assert.equal(check({ ...PER_FILE_DEV, macSignManifest: "../x.json" }).valid, false, "safe path");
|
|
1138
|
+
assert.equal(check({ ...DEV_MANIFEST.devArtifact, macPayloadMetadata: "a/payload.json" }).valid, false, "metadata alone");
|
|
1139
|
+
});
|
|
1140
|
+
|
|
1141
|
+
// Orthic-Labs/rightkit#257: the sign-existing lane signs an already-qualified artifact of another run; it never builds.
|
|
1142
|
+
const SIGN_EXISTING_MANIFEST = {
|
|
1143
|
+
...INCREMENTAL_BASE,
|
|
1144
|
+
lanes: ["ci", "sign-existing"],
|
|
1145
|
+
signExisting: { macSignManifest: "build/dev-sign.json", macPayloadMetadata: "Legion.app/Contents/Resources/payload.json" },
|
|
1146
|
+
};
|
|
1147
|
+
const renderSignExisting = (manifest) => renderTemplate(
|
|
1148
|
+
fs.readFileSync(path.join(templatesDir, "profiles/rust-hybrid", LANE_FILENAMES["sign-existing"]), "utf8"),
|
|
1149
|
+
buildRenderContext(structuredClone(manifest), "/repos/legion", "sign-existing"),
|
|
1150
|
+
);
|
|
1151
|
+
|
|
1152
|
+
test("sign-existing renders a dispatch-only, minimal-permission, protected signing job that never builds", () => {
|
|
1153
|
+
const out = renderSignExisting(SIGN_EXISTING_MANIFEST);
|
|
1154
|
+
assert.match(out, /^name: legion-sign-existing$/m);
|
|
1155
|
+
assert.match(out, /on:\n workflow_dispatch:\n inputs:\n run_id:[\s\S]* artifact:[\s\S]* source_sha:[\s\S]*\npermissions:\n contents: read\n actions: read\n/);
|
|
1156
|
+
const job = out.split("\n sign-existing:\n")[1];
|
|
1157
|
+
assert.match(job, /needs: \[private-repo-guard\]\n if: \$\{\{ github\.event_name == 'workflow_dispatch' && github\.ref_name == github\.event\.repository\.default_branch \}\}\n environment: release\n runs-on: xcode-27/);
|
|
1158
|
+
assert.match(job, /permissions:\n contents: read\n actions: read\n/);
|
|
1159
|
+
assert.doesNotMatch(out, /--release|cargo |notarytool|APPLE_API_KEY|buildScript/);
|
|
1160
|
+
assert.doesNotMatch(out, /(?:contents|actions|id-token|pull-requests|packages): write/);
|
|
1161
|
+
assert.match(job, /pnpm exec right-release sign-dev-artifact --artifact "\$work" --manifest "\$GITHUB_WORKSPACE\/build\/dev-sign\.json" --metadata "\$work\/Legion\.app\/Contents\/Resources\/payload\.json" --evidence "\$RUNNER_TEMP\/dev-signed\/sign-evidence\.json"/);
|
|
1162
|
+
assert.match(job, /sign-evidence\.json\n[\s\S]*source-verification\.json\n retention-days: 7\n if-no-files-found: error/);
|
|
1163
|
+
// Inputs reach the shell only through env, never through inline expressions in run scripts.
|
|
1164
|
+
assert.match(job, /INPUT_RUN_ID: \$\{\{ inputs\.run_id \}\}[\s\S]*INPUT_ARTIFACT: \$\{\{ inputs\.artifact \}\}[\s\S]*INPUT_SOURCE_SHA: \$\{\{ inputs\.source_sha \}\}/);
|
|
1165
|
+
assert.equal(out.match(/inputs\./g).length, 3);
|
|
1166
|
+
});
|
|
1167
|
+
|
|
1168
|
+
test("sign-existing verifies repository, run, artifact and head sha before it downloads, and signs only after", () => {
|
|
1169
|
+
const job = renderSignExisting(SIGN_EXISTING_MANIFEST).split("\n sign-existing:\n")[1];
|
|
1170
|
+
const at = (needle) => { const index = job.indexOf(needle); assert.ok(index >= 0, `missing ${needle}`); return index; };
|
|
1171
|
+
assert.ok(at("id: verify") < at("actions/download-artifact@") && at("actions/download-artifact@") < at("Install Apple signing identity") && at("Install Apple signing identity") < at("sign-dev-artifact"));
|
|
1172
|
+
assert.match(job, /actions\/runs\/\$INPUT_RUN_ID"\)"/);
|
|
1173
|
+
assert.match(job, /run \$INPUT_RUN_ID belongs to \$run_repo, not \$GITHUB_REPOSITORY/);
|
|
1174
|
+
assert.match(job, /another repository or a fork/);
|
|
1175
|
+
assert.match(job, /case "\$head_sha" in "\$INPUT_SOURCE_SHA"\*\)/);
|
|
1176
|
+
assert.match(job, /\.workflow_run\.id[\s\S]*\.workflow_run\.head_sha[\s\S]*\.workflow_run\.head_repository_id/);
|
|
1177
|
+
assert.match(job, /git merge-base --is-ancestor "\$head_sha" "\$GITHUB_SHA"/);
|
|
1178
|
+
assert.match(job, /uses: actions\/download-artifact@[0-9a-f]{40} # v4\.3\.0\n with:\n name: \$\{\{ steps\.verify\.outputs\.artifact_name \}\}\n run-id: \$\{\{ steps\.verify\.outputs\.run_id \}\}\n repository: \$\{\{ github\.repository \}\}\n github-token: \$\{\{ github\.token \}\}/);
|
|
1179
|
+
assert.match(job, /uses: actions\/(?:checkout|setup-node|upload-artifact)@[0-9a-f]{40}/);
|
|
1180
|
+
assert.doesNotMatch(job, /uses: [^\n]*@v\d/, "third-party actions are pinned to a commit");
|
|
1181
|
+
});
|
|
1182
|
+
|
|
1183
|
+
test("sign-existing mirrors the dev-mac-sign secret and keychain handling and adds no new secret", () => {
|
|
1184
|
+
const sign = renderSignExisting(SIGN_EXISTING_MANIFEST);
|
|
1185
|
+
assert.deepEqual([...new Set([...sign.matchAll(/secrets\.([A-Z0-9_]+)/g)].map((match) => match[1]))].sort(), ["APPLE_CERTIFICATE_BASE64", "APPLE_CERTIFICATE_PASSWORD", "APPLE_KEYCHAIN_PASSWORD"]);
|
|
1186
|
+
const devMac = renderRustCi({ ...DEV_MANIFEST, devArtifact: PER_FILE_DEV }).split(" dev-mac-sign:")[1];
|
|
1187
|
+
const block = (text, from, to) => text.slice(text.indexOf(from), text.indexOf(to));
|
|
1188
|
+
assert.equal(block(sign, " - name: Install Apple signing identity", " - name: Developer ID sign"), block(devMac, " - name: Install Apple signing identity", " - name: Developer ID sign"));
|
|
1189
|
+
const cleanup = ' - name: Remove Apple signing material\n if: ${{ always() }}\n shell: bash\n run: |\n security delete-keychain "$RUNNER_TEMP/apple-signing.keychain-db" 2>/dev/null || true\n rm -f "$RUNNER_TEMP/apple-signing.p12"\n';
|
|
1190
|
+
assert.ok(sign.includes(cleanup) && devMac.includes(cleanup), "same keychain removal");
|
|
1191
|
+
assert.match(sign, /APPLE_DEVELOPER_ID: \$\{\{ vars\.APPLE_DEVELOPER_ID \}\}/);
|
|
1192
|
+
});
|
|
1193
|
+
|
|
1194
|
+
test("sign-existing environment defaults to the signing environment and can be set", () => {
|
|
1195
|
+
assert.match(renderSignExisting(SIGN_EXISTING_MANIFEST), /\n environment: release\n/);
|
|
1196
|
+
assert.match(renderSignExisting({ ...SIGN_EXISTING_MANIFEST, signExisting: { ...SIGN_EXISTING_MANIFEST.signExisting, environment: "legion-sign" } }), /\n environment: legion-sign\n/);
|
|
1197
|
+
});
|
|
1198
|
+
|
|
1199
|
+
test("signExisting unset leaves the ci workflow byte-identical, and the lane is not rendered unless declared", () => {
|
|
1200
|
+
assert.equal(renderRustCi(SIGN_EXISTING_MANIFEST), renderRustCi(INCREMENTAL_BASE));
|
|
1201
|
+
assert.doesNotMatch(renderRustCi(SIGN_EXISTING_MANIFEST), /sign-existing|sign-dev-artifact/);
|
|
1202
|
+
assert.equal(KNOWN_LANES.includes("sign-existing"), false, "node-profile all-lane checks keep their lane list");
|
|
1203
|
+
});
|
|
1204
|
+
|
|
1205
|
+
// signExisting.macPayloadMetadataSource: the unsigned packaging step zips the .app plus the generated payload metadata file.
|
|
1206
|
+
const KEEP_PARENT = 'ditto -c -k --keepParent "$DEV_APP_PATH" "$RUNNER_TEMP/dev-unsigned/app.zip"';
|
|
1207
|
+
const WITH_SOURCE = { macSignManifest: "build/dev-sign.json", macPayloadMetadata: "payload.json", macPayloadMetadataSource: "dist/dev-macos/payload.json" };
|
|
1208
|
+
const withSource = (devArtifact, signExisting = WITH_SOURCE) => ({ ...INCREMENTAL_BASE, lanes: ["ci", "sign-existing"], devArtifact, signExisting });
|
|
1209
|
+
|
|
1210
|
+
test("macPayloadMetadataSource unset keeps the packaging step byte-identical in every macOS leg", () => {
|
|
1211
|
+
const legs = [
|
|
1212
|
+
DEV_MANIFEST.devArtifact,
|
|
1213
|
+
{ mac: "unsigned", macAppPath: "target/release/bundle/macos/Pulse.app" },
|
|
1214
|
+
{ ...DEV_MANIFEST.devArtifact, parallel: true, buildScript: "build:dev" },
|
|
1215
|
+
];
|
|
1216
|
+
for (const devArtifact of legs) {
|
|
1217
|
+
const plain = renderRustCi({ ...INCREMENTAL_BASE, devArtifact });
|
|
1218
|
+
assert.ok(plain.includes(KEEP_PARENT), JSON.stringify(devArtifact));
|
|
1219
|
+
const unrelated = renderRustCi(withSource(devArtifact, { macSignManifest: "build/dev-sign.json", macPayloadMetadata: "payload.json" }));
|
|
1220
|
+
assert.equal(unrelated, plain, "signExisting without the key changes nothing");
|
|
1221
|
+
}
|
|
1222
|
+
});
|
|
1223
|
+
|
|
1224
|
+
test("macPayloadMetadataSource zips the .app and the payload metadata file, keeping the wrapper layout, in every macOS leg", () => {
|
|
1225
|
+
const legs = [
|
|
1226
|
+
DEV_MANIFEST.devArtifact,
|
|
1227
|
+
{ mac: "unsigned", macAppPath: "target/release/bundle/macos/Pulse.app" },
|
|
1228
|
+
{ ...DEV_MANIFEST.devArtifact, parallel: true, buildScript: "build:dev" },
|
|
1229
|
+
];
|
|
1230
|
+
for (const devArtifact of legs) {
|
|
1231
|
+
const out = renderRustCi(withSource(devArtifact));
|
|
1232
|
+
assert.ok(!out.includes(KEEP_PARENT), "the plain keepParent zip is replaced");
|
|
1233
|
+
assert.match(out, /test -f "dist\/dev-macos\/payload\.json"\n stage="\$RUNNER_TEMP\/dev-unsigned-stage"\n rm -rf "\$stage" && mkdir -p "\$stage"\n ditto "\$DEV_APP_PATH" "\$stage\/\$\(basename "\$DEV_APP_PATH"\)"\n cp "dist\/dev-macos\/payload\.json" "\$stage\/payload\.json"\n ditto -c -k "\$stage" "\$RUNNER_TEMP\/dev-unsigned\/app\.zip"\n/, JSON.stringify(devArtifact));
|
|
1234
|
+
assert.match(out, /set -euo pipefail\n test -d "\$DEV_APP_PATH"\n mkdir -p "\$RUNNER_TEMP\/dev-unsigned"\n test -f /, "the step fails on a missing file under set -e, after the app check");
|
|
1235
|
+
}
|
|
1236
|
+
});
|
|
1237
|
+
|
|
1238
|
+
test("macPayloadMetadataSource validation", () => {
|
|
1239
|
+
const check = (devArtifact, signExisting) => validateManifest({ ...withSource(devArtifact, signExisting), regenerate: undefined });
|
|
1240
|
+
const dev = { ...DEV_MANIFEST.devArtifact };
|
|
1241
|
+
assert.equal(check(dev, WITH_SOURCE).valid, true);
|
|
1242
|
+
assert.equal(check(dev, { ...WITH_SOURCE, macPayloadMetadataSource: "../payload.json" }).valid, false, "safe path");
|
|
1243
|
+
assert.equal(check(dev, { ...WITH_SOURCE, macPayloadMetadataSource: "/abs/payload.json" }).valid, false, "repository-relative");
|
|
1244
|
+
assert.equal(check(dev, { ...WITH_SOURCE, macPayloadMetadataSource: 7 }).valid, false, "a string");
|
|
1245
|
+
assert.equal(check(dev, { ...WITH_SOURCE, macPayloadMetadata: "Legion.app/Contents/Resources/payload.json" }).valid, false, "bare file name at the zip root");
|
|
1246
|
+
assert.equal(check({ windows: "unsigned", windowsGlob: "dist/*.exe" }, WITH_SOURCE).valid, false, "needs a macOS dev leg");
|
|
1247
|
+
assert.equal(check(dev, { macSignManifest: "build/dev-sign.json", macPayloadMetadata: "Legion.app/Contents/Resources/payload.json" }).valid, true, "unset keeps any metadata path");
|
|
1248
|
+
});
|
|
1249
|
+
|
|
1250
|
+
test("signExisting validation", () => {
|
|
1251
|
+
const check = (patch) => validateManifest({ ...SIGN_EXISTING_MANIFEST, regenerate: undefined, ...patch });
|
|
1252
|
+
assert.equal(check({}).valid, true);
|
|
1253
|
+
assert.equal(check({ signExisting: undefined }).valid, false, "lane needs config");
|
|
1254
|
+
assert.equal(check({ lanes: ["ci"] }).valid, false, "config needs lane");
|
|
1255
|
+
assert.equal(check({ signExisting: { macSignManifest: "build/dev-sign.json" } }).valid, false, "metadata required");
|
|
1256
|
+
assert.equal(check({ signExisting: { macPayloadMetadata: "payload.json" } }).valid, false, "sign manifest required");
|
|
1257
|
+
assert.equal(check({ signExisting: { ...SIGN_EXISTING_MANIFEST.signExisting, macSignManifest: "../x.json" } }).valid, false, "safe path");
|
|
1258
|
+
assert.equal(check({ signExisting: { ...SIGN_EXISTING_MANIFEST.signExisting, environment: "a b" } }).valid, false, "safe environment");
|
|
1259
|
+
assert.equal(check({ signExisting: { ...SIGN_EXISTING_MANIFEST.signExisting, release: true } }).valid, false, "no unknown fields, so no release mode");
|
|
1260
|
+
assert.equal(check({ matrix: { os: ["windows-2025"], node: ["26.8.1"] } }).valid, false, "needs a macOS runner");
|
|
1261
|
+
assert.equal(validateManifest({ ...SIGN_EXISTING_MANIFEST, profile: undefined, gate: undefined, ciAllOs: undefined, regenerate: undefined }).valid, false, "rust-hybrid only");
|
|
1262
|
+
});
|
|
1263
|
+
|
|
1077
1264
|
test("rendered ciIncremental + devArtifact workflows pass actionlint", (t) => {
|
|
1078
1265
|
const bin = spawnSync("actionlint", ["-version"], { encoding: "utf8" });
|
|
1079
1266
|
if (bin.error) return t.skip("actionlint not installed");
|
|
@@ -1091,7 +1278,7 @@ test("rendered ciIncremental + devArtifact workflows pass actionlint", (t) => {
|
|
|
1091
1278
|
"ci-parallel-unsigned-dispatch.yml": {
|
|
1092
1279
|
...INCREMENTAL_BASE,
|
|
1093
1280
|
rustCache: { workspaces: ["engine"], keySuffix: "v2" },
|
|
1094
|
-
concurrency: { mainPushes: "queue" },
|
|
1281
|
+
concurrency: { mainPushes: "queue", reason: "actionlint sample of the queue opt-out" },
|
|
1095
1282
|
devArtifact: { mac: "unsigned", windows: "unsigned", dispatch: true, parallel: true, buildScript: "build:dev", macAppPath: "a/B.app", windowsGlob: "dist/*.exe" },
|
|
1096
1283
|
},
|
|
1097
1284
|
};
|
|
@@ -1167,33 +1354,76 @@ test("rustCache.keySuffix: unset adds no key; set renders a lane-scoped key in e
|
|
|
1167
1354
|
assert.equal(validateManifest({ ...FULL_MANIFEST, lanes: ["ci"], rustCache: { workspaces: ["engine"], keySuffix: "v2" } }).valid, false, "rustCache stays rust-hybrid only");
|
|
1168
1355
|
});
|
|
1169
1356
|
|
|
1170
|
-
//
|
|
1171
|
-
//
|
|
1172
|
-
|
|
1357
|
+
// One CI run per repo (#338). Default: a `supersede` job cancels older default-branch runs that only just started
|
|
1358
|
+
// or are failing; an older run past the grace fraction is kept and the new run's ci job waits for it through a
|
|
1359
|
+
// job-level group with cancel-in-progress false. "queue" (with a required reason) restores the old per-ref group
|
|
1360
|
+
// and renders no supersede job. Render outputs are compared structurally here, never by baseline hash: no hashed
|
|
1361
|
+
// baseline (SW_BASELINE) renders a rust-hybrid or node ci lane, so no hash changed.
|
|
1362
|
+
const MAIN_PUSH_EXPRESSION = "${{ !(github.event_name == 'push' && github.ref_name == github.event.repository.default_branch) }}";
|
|
1363
|
+
const QUEUE_REASON = "deploy ordering needs every main commit built in turn";
|
|
1364
|
+
const renderGenericCi = (manifest) => renderTemplate(fs.readFileSync(path.join(templatesDir, "ci.yml"), "utf8"), buildRenderContext({ ...FULL_MANIFEST, lanes: ["ci"], ...manifest }, "/repos/widgets", "ci"));
|
|
1365
|
+
|
|
1366
|
+
test("default ci renders the supersede job and a job-level wait group instead of cancelling main pushes", () => {
|
|
1173
1367
|
const unset = renderRustCi(INCREMENTAL_BASE);
|
|
1174
|
-
assert.match(unset, /^concurrency:\n group: \$\{\{ github\.workflow \}\}-\$\{\{ github\.ref \}\}\n cancel-in-progress: true\n/m);
|
|
1175
1368
|
assert.equal(renderRustCi({ ...INCREMENTAL_BASE, concurrency: { mainPushes: "cancel" } }), unset);
|
|
1176
1369
|
assert.equal(renderRustCi({ ...INCREMENTAL_BASE, concurrency: {} }), unset);
|
|
1370
|
+
for (const content of [unset, renderGenericCi({})]) {
|
|
1371
|
+
assert.match(content, /^concurrency:\n group: \$\{\{ github\.workflow \}\}-\$\{\{ github\.event_name == 'push' && github\.ref_name == github\.event\.repository\.default_branch && github\.run_id \|\| github\.ref \}\}\n/m, "a main push has its own workflow group, so its supersede job always runs");
|
|
1372
|
+
assert.ok(content.includes(` cancel-in-progress: ${MAIN_PUSH_EXPRESSION}\n`), "PR runs still cancel superseded runs, main pushes are never cancelled by the workflow group");
|
|
1373
|
+
assert.match(content, /\n supersede:\n needs: \[private-repo-guard\]\n if: \$\{\{ github\.event_name == 'push' && github\.ref_name == github\.event\.repository\.default_branch \}\}\n runs-on: ubuntu-24\.04\n timeout-minutes: 5\n permissions:\n contents: read\n actions: write\n steps:\n/);
|
|
1374
|
+
assert.equal((content.match(/actions: write/g) ?? []).length, 1, "actions: write only in supersede");
|
|
1375
|
+
assert.match(content, /RIGHT_GIT_GRACE_FRACTION: "0\.7"\n RIGHT_GIT_MEDIAN_WINDOW: "10"\n/);
|
|
1376
|
+
assert.match(content, /cat > "\$RUNNER_TEMP\/supersede\.mjs" <<'RIGHT_GIT_SUPERSEDE_EOF'\n/);
|
|
1377
|
+
assert.match(content, /\n RIGHT_GIT_SUPERSEDE_EOF\n node "\$RUNNER_TEMP\/supersede\.mjs"\n/);
|
|
1378
|
+
assert.match(content, /\n concurrency:\n group: \$\{\{ github\.event_name == 'push' && github\.ref_name == github\.event\.repository\.default_branch && format\('\{0\}-main-\{1\}-\{2\}', github\.workflow, matrix\.os, matrix\.node\) \|\| format\('\{0\}-\{1\}-\{2\}-\{3\}-\{4\}', github\.workflow, github\.run_id, github\.run_attempt, matrix\.os, matrix\.node\) \}\}\n cancel-in-progress: false\n/);
|
|
1379
|
+
assert.doesNotMatch(content, /concurrency\.mainPushes queue/);
|
|
1380
|
+
}
|
|
1381
|
+
// The embedded script is the shipped file, verbatim.
|
|
1382
|
+
const script = fs.readFileSync(new URL("./supersede.mjs", import.meta.url), "utf8").replace(/\n+$/, "");
|
|
1383
|
+
assert.ok(unset.includes(script.split("\n").map((line) => (line === "" ? "" : ` ${line}`)).join("\n")));
|
|
1384
|
+
});
|
|
1177
1385
|
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
assert.
|
|
1386
|
+
test("concurrency.graceFraction and medianWindow reach the supersede job and are validated", () => {
|
|
1387
|
+
const custom = renderRustCi({ ...INCREMENTAL_BASE, concurrency: { graceFraction: 0.5, medianWindow: 5 } });
|
|
1388
|
+
assert.match(custom, /RIGHT_GIT_GRACE_FRACTION: "0\.5"\n RIGHT_GIT_MEDIAN_WINDOW: "5"\n/);
|
|
1389
|
+
for (const bad of [{ graceFraction: 0 }, { graceFraction: 1.5 }, { graceFraction: "0.7" }, { medianWindow: 0 }, { medianWindow: 101 }, { medianWindow: 2.5 }]) {
|
|
1390
|
+
assert.equal(validateManifest({ ...VALID_RUST_HYBRID, concurrency: bad }).valid, false, JSON.stringify(bad));
|
|
1391
|
+
}
|
|
1392
|
+
assert.equal(validateManifest({ ...VALID_RUST_HYBRID, concurrency: { graceFraction: 1, medianWindow: 100 } }).valid, true);
|
|
1393
|
+
assert.equal(validateManifest({ ...VALID_RUST_HYBRID, concurrency: { mainPushes: "queue", reason: QUEUE_REASON, graceFraction: 0.5 } }).valid, false, "queue renders no supersede job");
|
|
1394
|
+
});
|
|
1181
1395
|
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1396
|
+
test("concurrency.mainPushes: 'queue' with a reason keeps the per-ref group, renders no supersede job and records the reason", () => {
|
|
1397
|
+
const unset = renderRustCi(INCREMENTAL_BASE);
|
|
1398
|
+
const queue = renderRustCi({ ...INCREMENTAL_BASE, concurrency: { mainPushes: "queue", reason: QUEUE_REASON } });
|
|
1399
|
+
assert.match(queue, new RegExp(`^# concurrency\\.mainPushes queue, recorded exception to one CI run per repo: ${QUEUE_REASON}\\nconcurrency:\\n group: \\$\\{\\{ github\\.workflow \\}\\}-\\$\\{\\{ github\\.ref \\}\\}\\n`, "m"));
|
|
1400
|
+
assert.ok(queue.includes(` cancel-in-progress: ${MAIN_PUSH_EXPRESSION}\n`));
|
|
1401
|
+
assert.doesNotMatch(queue, /supersede|actions: write|\n concurrency:/);
|
|
1402
|
+
assert.notEqual(queue, unset);
|
|
1403
|
+
|
|
1404
|
+
const generic = renderGenericCi({ concurrency: { mainPushes: "queue", reason: QUEUE_REASON } });
|
|
1405
|
+
assert.match(generic, /^concurrency:\n group: \$\{\{ github\.workflow \}\}-\$\{\{ github\.ref \}\}\n/m);
|
|
1406
|
+
assert.doesNotMatch(generic, /supersede|actions: write/);
|
|
1407
|
+
assert.match(generic, /^# concurrency\.mainPushes queue, recorded exception/m);
|
|
1185
1408
|
|
|
1186
1409
|
const regenerate = renderTemplate(
|
|
1187
1410
|
fs.readFileSync(path.join(templatesDir, "profiles/rust-hybrid/regenerate.yml"), "utf8"),
|
|
1188
|
-
buildRenderContext({ ...INCREMENTAL_BASE, lanes: ["ci", "regenerate"], regenerate: { script: "regenerate" }, concurrency: { mainPushes: "queue" } }, "/repos/pulse", "regenerate"),
|
|
1411
|
+
buildRenderContext({ ...INCREMENTAL_BASE, lanes: ["ci", "regenerate"], regenerate: { script: "regenerate" }, concurrency: { mainPushes: "queue", reason: QUEUE_REASON } }, "/repos/pulse", "regenerate"),
|
|
1189
1412
|
);
|
|
1190
1413
|
assert.match(regenerate, / cancel-in-progress: false\n/, "the regenerate lane is never cancelled");
|
|
1191
1414
|
|
|
1192
|
-
assert.equal(validateManifest({ ...VALID_RUST_HYBRID, concurrency: { mainPushes: "queue" } }).valid, true);
|
|
1415
|
+
assert.equal(validateManifest({ ...VALID_RUST_HYBRID, concurrency: { mainPushes: "queue", reason: QUEUE_REASON } }).valid, true);
|
|
1416
|
+
assert.equal(validateManifest({ ...VALID_RUST_HYBRID, concurrency: { mainPushes: "queue" } }).valid, false, "queue needs a reason");
|
|
1417
|
+
assert.equal(validateManifest({ ...VALID_RUST_HYBRID, concurrency: { mainPushes: "queue", reason: "" } }).valid, false);
|
|
1418
|
+
assert.equal(validateManifest({ ...VALID_RUST_HYBRID, concurrency: { mainPushes: "queue", reason: " " } }).valid, false);
|
|
1419
|
+
assert.equal(validateManifest({ ...VALID_RUST_HYBRID, concurrency: { mainPushes: "queue", reason: 5 } }).valid, false);
|
|
1420
|
+
assert.equal(validateManifest({ ...VALID_RUST_HYBRID, concurrency: { mainPushes: "queue", reason: "two\nlines" } }).valid, false, "the reason is one YAML comment line");
|
|
1421
|
+
assert.equal(validateManifest({ ...VALID_RUST_HYBRID, concurrency: { mainPushes: "cancel", reason: QUEUE_REASON } }).valid, false, "a reason only goes with queue");
|
|
1422
|
+
assert.equal(validateManifest({ ...VALID_RUST_HYBRID, concurrency: { reason: QUEUE_REASON } }).valid, false);
|
|
1193
1423
|
assert.equal(validateManifest({ ...VALID_RUST_HYBRID, concurrency: { mainPushes: "bogus" } }).valid, false);
|
|
1194
|
-
assert.equal(validateManifest({ ...VALID_RUST_HYBRID, concurrency: { mainPushes: "queue", extra: true } }).valid, false);
|
|
1424
|
+
assert.equal(validateManifest({ ...VALID_RUST_HYBRID, concurrency: { mainPushes: "queue", reason: QUEUE_REASON, extra: true } }).valid, false);
|
|
1195
1425
|
assert.equal(validateManifest({ ...VALID_RUST_HYBRID, concurrency: "queue" }).valid, false);
|
|
1196
|
-
assert.equal(validateManifest({ ...FULL_MANIFEST, lanes: ["package-smoke"], regenerate: undefined, concurrency: { mainPushes: "queue" } }).valid, false, "concurrency needs lane ci");
|
|
1426
|
+
assert.equal(validateManifest({ ...FULL_MANIFEST, lanes: ["package-smoke"], regenerate: undefined, concurrency: { mainPushes: "queue", reason: QUEUE_REASON } }).valid, false, "concurrency needs lane ci");
|
|
1197
1427
|
});
|
|
1198
1428
|
|
|
1199
1429
|
// devArtifact.parallel: each platform builds and stages the dev app in its own job beside the gate.
|
|
@@ -1485,19 +1715,22 @@ const swRender = (manifest, lane, swift) => {
|
|
|
1485
1715
|
};
|
|
1486
1716
|
|
|
1487
1717
|
const SW_BASELINE = {
|
|
1488
|
-
|
|
1718
|
+
// 0.2.49 (#338): the three ci lanes render the supersede job and job-level concurrency (hashes from the Dell render; the other nine lanes match CI byte for byte).
|
|
1719
|
+
"node/ci": "1e44d86e2d9c46f21992ca236da797a7f8751e8622902157fbaa87e28e9b3431",
|
|
1489
1720
|
"node/qualification": "730cc94fde3400079c2a4e66effed0e8957de2b75576d13f02b9398059ccc921",
|
|
1490
1721
|
"node/package-smoke": "bc981ccb7248cc022cb8157c1fbdb7895c48f6a3fe4eeaf5a76eb5bba4206517",
|
|
1491
1722
|
"node/release-candidate": "6ff48f01cadc95e5e92cc225432aa280a7baac46017ae30e54a165e3db2d1539",
|
|
1492
1723
|
"node/regenerate": "82bfa3063ae0bc04ba52fecc14d562b418037716283648a887c206683a4e1c14",
|
|
1493
1724
|
"node/publish-npm": "50882207659dfb6e0207fc0d9b33d86b7c10a2d2e3e6c65b2db05d5261982834",
|
|
1494
1725
|
"node/publish-package-managers": "106b8d28ed76d916afe68808388cd5dc0de0ddd719b566832a6e8280410f9d7f",
|
|
1495
|
-
"rust-hybrid/ci": "
|
|
1726
|
+
"rust-hybrid/ci": "c402bac02c72fbda2cab5b8ee5968bab9ed63a8770489c5749e6d7f2ba3d27d8",
|
|
1496
1727
|
// 0.2.44/0.2.45: the 0.2.41 render with the admission and regenerate jobs on macos-15 (ownership approval does not run on Linux).
|
|
1497
|
-
"
|
|
1728
|
+
// 0.2.46 (#168): plus RIGHTKIT_DEV_SIGNING: "ci-adhoc" on the candidate job. Hash taken from CI 38978333900 (xcode and windows agree).
|
|
1729
|
+
"rust-hybrid/release-candidate": "8e108084b910f3edd35b197b920b1f5beb7da339f87a1ac90e258fda5d9ea467",
|
|
1498
1730
|
"rust-hybrid/regenerate": "88763b9254bb94d893d927e8d8b7458b57afee36f27d618df4b36e8c8ca55842",
|
|
1499
|
-
"rust-hybrid-chain/ci": "
|
|
1500
|
-
|
|
1731
|
+
"rust-hybrid-chain/ci": "db27d518a4268dfa6481e943a11457348f5f34221e860ea1172b343eb7975068",
|
|
1732
|
+
// 0.2.46 (#168): the chain candidate job also sets RIGHTKIT_DEV_SIGNING: "ci-adhoc". Hash taken from CI 38986615056 (xcode; the excerpt has no windows).
|
|
1733
|
+
"rust-hybrid-chain/release-candidate": "c118e1c555e1de603f61acfde0b4749d519b97ec3815fc53b024b22d1e5cb3b9",
|
|
1501
1734
|
};
|
|
1502
1735
|
|
|
1503
1736
|
// Each lane that builds Swift renders the shared configure and cleanup steps into exactly these jobs.
|
|
@@ -1634,7 +1867,7 @@ test("every template's triggers are safe for the swift credential: none is pull_
|
|
|
1634
1867
|
...fs.readdirSync(templatesDir).filter((f) => f.endsWith(".yml")).map((f) => path.join(templatesDir, f)),
|
|
1635
1868
|
...fs.readdirSync(path.join(templatesDir, "profiles", "rust-hybrid")).filter((f) => f.endsWith(".yml")).map((f) => path.join(templatesDir, "profiles", "rust-hybrid", f)),
|
|
1636
1869
|
];
|
|
1637
|
-
assert.equal(templates.length,
|
|
1870
|
+
assert.equal(templates.length, 12);
|
|
1638
1871
|
for (const file of templates) {
|
|
1639
1872
|
const onBlock = fs.readFileSync(file, "utf8").split("\njobs:")[0].split(/^on:/m)[1] ?? "";
|
|
1640
1873
|
assert.doesNotMatch(onBlock.split(/^permissions:/m)[0], /pull_request_target|workflow_run/, path.relative(templatesDir, file));
|
|
@@ -1740,3 +1973,105 @@ test("rust-hybrid: no job that runs the ownership step is hard-coded to a Linux
|
|
|
1740
1973
|
}
|
|
1741
1974
|
assert.deepEqual(rendered.sort(), ["ci/ci", "regenerate/regenerate", "release-candidate/admission"]);
|
|
1742
1975
|
});
|
|
1976
|
+
|
|
1977
|
+
// Orthic-Labs/rightkit#107: optional dev-qualification lane beside a QA-free candidate.
|
|
1978
|
+
const DEV_QUAL_TEMPLATE = fs.readFileSync(path.join(templatesDir, "profiles/rust-hybrid/release-candidate.yml"), "utf8");
|
|
1979
|
+
|
|
1980
|
+
function devQualManifest(devQualification) {
|
|
1981
|
+
return {
|
|
1982
|
+
...FULL_MANIFEST,
|
|
1983
|
+
lanes: ["ci", "release-candidate"],
|
|
1984
|
+
profile: "rust-hybrid",
|
|
1985
|
+
gate: { path: "scripts/gate.sh" },
|
|
1986
|
+
candidate: {
|
|
1987
|
+
buildScript: "ci:candidate",
|
|
1988
|
+
checkScript: "ci:candidate-check",
|
|
1989
|
+
admissionScript: "release:admit",
|
|
1990
|
+
stageSummaryScript: "release:stage-summary",
|
|
1991
|
+
artifactRoot: "widgets-unsigned",
|
|
1992
|
+
os: ["windows-2025", "macos-15"],
|
|
1993
|
+
targets: [
|
|
1994
|
+
{ os: "windows-2025", platform: "windows", architecture: "x86_64" },
|
|
1995
|
+
{ os: "macos-15", platform: "macos", architecture: "arm64" },
|
|
1996
|
+
],
|
|
1997
|
+
signWindows: true,
|
|
1998
|
+
signMacos: true,
|
|
1999
|
+
releaseChain: {
|
|
2000
|
+
evidenceVerificationScript: "release:verify-evidence",
|
|
2001
|
+
windowsFinalizeScript: "release:finalize-windows",
|
|
2002
|
+
macosFinalizeScript: "release:finalize-macos",
|
|
2003
|
+
installedQualificationScript: "release:qualify-installed",
|
|
2004
|
+
publishScript: "release:publish-qualified",
|
|
2005
|
+
qualificationRunnerVariable: "WIDGETS_QUALIFICATION_RUNNER",
|
|
2006
|
+
},
|
|
2007
|
+
...(devQualification ? { devQualification } : {}),
|
|
2008
|
+
},
|
|
2009
|
+
matrix: { os: ["ubuntu-24.04", "windows-2025", "macos-15"], node: ["22.23.2"] },
|
|
2010
|
+
templateVersion: "1.8.0",
|
|
2011
|
+
};
|
|
2012
|
+
}
|
|
2013
|
+
|
|
2014
|
+
function renderDevQual(manifest) {
|
|
2015
|
+
return renderTemplate(DEV_QUAL_TEMPLATE, buildRenderContext(manifest, "/repos/widgets", "release-candidate"));
|
|
2016
|
+
}
|
|
2017
|
+
|
|
2018
|
+
test("dev-qualification unset: release-candidate workflow is byte-identical to the template without the placeholder", () => {
|
|
2019
|
+
const manifest = devQualManifest();
|
|
2020
|
+
const before = renderTemplate(
|
|
2021
|
+
DEV_QUAL_TEMPLATE.replace("${DEV_QUALIFICATION_JOB}${WINDOWS_SIGNING_JOB}", "${WINDOWS_SIGNING_JOB}"),
|
|
2022
|
+
buildRenderContext(manifest, "/repos/widgets", "release-candidate"),
|
|
2023
|
+
);
|
|
2024
|
+
const content = renderDevQual(manifest);
|
|
2025
|
+
assert.equal(content, before);
|
|
2026
|
+
assert.doesNotMatch(content, /dev-qualification|devqual/);
|
|
2027
|
+
assert.match(content, /windows-sign:\n needs: \[admission, candidate\]\n/);
|
|
2028
|
+
assert.match(content, /macos-sign:\n needs: \[admission, candidate\]\n/);
|
|
2029
|
+
// Unsigned manifests (no signing jobs, no chain) stay free of the job too.
|
|
2030
|
+
const unsigned = devQualManifest();
|
|
2031
|
+
delete unsigned.candidate.releaseChain;
|
|
2032
|
+
unsigned.candidate.signWindows = false;
|
|
2033
|
+
unsigned.candidate.signMacos = false;
|
|
2034
|
+
assert.doesNotMatch(renderDevQual(unsigned), /dev-qualification/);
|
|
2035
|
+
});
|
|
2036
|
+
|
|
2037
|
+
test("dev-qualification set: job needs admission, builds the dev build, uploads devqual evidence and gates both signing jobs", () => {
|
|
2038
|
+
const manifest = devQualManifest({ buildScript: "build:dev-qualification", journeyScript: "qa:journeys" });
|
|
2039
|
+
const content = renderDevQual(manifest);
|
|
2040
|
+
const job = content.slice(content.indexOf("\n dev-qualification:\n"), content.indexOf("\n windows-sign:\n"));
|
|
2041
|
+
assert.ok(job.length > 0, "dev-qualification job renders before windows-sign");
|
|
2042
|
+
assert.match(job, /^\n {2}dev-qualification:\n {4}needs: \[admission\]\n/);
|
|
2043
|
+
assert.match(job, /matrix:\n {8}include:\n {10}- os: "windows-2025"[\s\S]*- os: "macos-15"/);
|
|
2044
|
+
assert.match(job, /ref: \$\{\{ needs\.admission\.outputs\.source_revision \}\}\n\s+fetch-depth: 0\n\s+persist-credentials: false/);
|
|
2045
|
+
assert.match(job, /run: pnpm run build:dev-qualification\n/);
|
|
2046
|
+
assert.match(job, /run: pnpm run qa:journeys\n/);
|
|
2047
|
+
assert.doesNotMatch(job, /ci:candidate|release:finalize|secrets\.|id-token|environment:/);
|
|
2048
|
+
assert.match(job, /RIGHT_GIT_STAGE_ACTION: init[\s\S]*RIGHT_GIT_STAGE: dev-qualification/);
|
|
2049
|
+
assert.match(job, /RIGHT_GIT_STAGE_ACTION: finalize[\s\S]*RIGHT_GIT_STAGE: dev-qualification/);
|
|
2050
|
+
assert.match(job, /name: widgets-\$\{\{ github\.run_id \}\}-\$\{\{ github\.run_attempt \}\}-devqual-\$\{\{ matrix\.platform \}\}-\$\{\{ matrix\.architecture \}\}-\$\{\{ needs\.admission\.outputs\.version \}\}-\$\{\{ needs\.admission\.outputs\.source_revision \}\}\$\{\{ needs\.admission\.outputs\.artifact_suffix \}\}/);
|
|
2051
|
+
assert.match(job, /widgets-unsigned-devqual\/\*\*/);
|
|
2052
|
+
// Pinned action SHAs match the candidate job's.
|
|
2053
|
+
const candidateJob = content.slice(content.indexOf("\n candidate:\n"), content.indexOf("\n dev-qualification:\n"));
|
|
2054
|
+
for (const action of ["actions/checkout", "actions/setup-node", "dtolnay/rust-toolchain", "Swatinem/rust-cache", "Mozilla-Actions/sccache-action", "actions/upload-artifact"]) {
|
|
2055
|
+
const pins = (text) => [...new Set([...text.matchAll(new RegExp(`${action.replace("/", "\\/")}@([a-f0-9]{40})`, "g"))].map((m) => m[1]))];
|
|
2056
|
+
assert.deepEqual(pins(job), pins(candidateJob), action);
|
|
2057
|
+
}
|
|
2058
|
+
// The candidate build stays the QA-free one and the candidate never runs journeys.
|
|
2059
|
+
assert.match(candidateJob, /run: pnpm run ci:candidate\n/);
|
|
2060
|
+
assert.doesNotMatch(candidateJob, /build:dev-qualification|qa:journeys/);
|
|
2061
|
+
// Both signing jobs need it; a failed dev qualification skips signing (no always()).
|
|
2062
|
+
assert.match(content, /windows-sign:\n needs: \[admission, candidate, dev-qualification\]\n if: \$\{\{ needs\.admission\.outputs\.signed_qualification == 'true' \}\}/);
|
|
2063
|
+
assert.match(content, /macos-sign:\n needs: \[admission, candidate, dev-qualification\]\n if: \$\{\{ needs\.admission\.outputs\.signed_qualification == 'true' \}\}/);
|
|
2064
|
+
// Installed qualification still reaches the signed bytes only through windows-sign.
|
|
2065
|
+
assert.match(content, /installed-qualification:\n needs: \[admission, candidate, windows-sign\]/);
|
|
2066
|
+
});
|
|
2067
|
+
|
|
2068
|
+
test("dev-qualification gates a Windows-only signing job and renders without a release chain", () => {
|
|
2069
|
+
const manifest = devQualManifest({ buildScript: "build:dev-qualification", journeyScript: "qa:journeys" });
|
|
2070
|
+
delete manifest.candidate.releaseChain;
|
|
2071
|
+
delete manifest.candidate.signMacos;
|
|
2072
|
+
manifest.candidate.os = ["windows-2025"];
|
|
2073
|
+
manifest.candidate.targets = [{ os: "windows-2025", platform: "windows", architecture: "x86_64" }];
|
|
2074
|
+
const content = renderDevQual(manifest);
|
|
2075
|
+
assert.match(content, /windows-sign:\n needs: \[admission, candidate, dev-qualification\]\n/);
|
|
2076
|
+
assert.doesNotMatch(content, /macos-sign:/);
|
|
2077
|
+
});
|
package/supersede.mjs
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
// One CI run in progress per repository, without cancelling work that is nearly done.
|
|
2
|
+
//
|
|
3
|
+
// Rendered into the managed ci workflow's `supersede` job (see manifest.mjs
|
|
4
|
+
// supersedeJob) and run there with Node. The file is self-contained: no imports
|
|
5
|
+
// beyond the Node standard library, no placeholder-shaped text, and no
|
|
6
|
+
// GitHub expression syntax, because the renderer embeds it verbatim.
|
|
7
|
+
//
|
|
8
|
+
// A newer push to the default branch cancels an older run of the same workflow
|
|
9
|
+
// when that run has only just started, has not started at all, or already has a
|
|
10
|
+
// failed job. A run that is past the grace fraction of the median successful
|
|
11
|
+
// duration is left to finish; the new run's `ci` job waits for it through a
|
|
12
|
+
// job-level concurrency group with cancel-in-progress false.
|
|
13
|
+
|
|
14
|
+
import { pathToFileURL } from "node:url";
|
|
15
|
+
|
|
16
|
+
export const DEFAULT_GRACE_FRACTION = 0.7;
|
|
17
|
+
export const DEFAULT_MEDIAN_WINDOW = 10;
|
|
18
|
+
// Fewer successful runs than this gives no trustworthy median, so nothing is
|
|
19
|
+
// cancelled for being young; only unstarted runs and failing runs are.
|
|
20
|
+
export const MIN_HISTORY = 3;
|
|
21
|
+
|
|
22
|
+
const FAILED_JOB_CONCLUSIONS = new Set(["failure", "timed_out"]);
|
|
23
|
+
|
|
24
|
+
export function median(values) {
|
|
25
|
+
const sorted = values.filter((value) => Number.isFinite(value) && value >= 0).sort((a, b) => a - b);
|
|
26
|
+
if (sorted.length === 0) return null;
|
|
27
|
+
const middle = Math.floor(sorted.length / 2);
|
|
28
|
+
return sorted.length % 2 === 1 ? sorted[middle] : (sorted[middle - 1] + sorted[middle]) / 2;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Duration in milliseconds of a finished run, or null when the timestamps are unusable. */
|
|
32
|
+
export function runDurationMs(run) {
|
|
33
|
+
const start = Date.parse(run?.run_started_at ?? run?.created_at ?? "");
|
|
34
|
+
const end = Date.parse(run?.updated_at ?? "");
|
|
35
|
+
if (!Number.isFinite(start) || !Number.isFinite(end) || end < start) return null;
|
|
36
|
+
return end - start;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Pure decision for one older run.
|
|
41
|
+
* run: { status, run_started_at | created_at }
|
|
42
|
+
* jobs: [{ conclusion }]
|
|
43
|
+
* medianMs: median duration of recent successful runs, or null when unknown
|
|
44
|
+
* Returns { cancel: boolean, reason: string }.
|
|
45
|
+
*/
|
|
46
|
+
export function decideSupersede({ run, jobs = [], medianMs = null, nowMs, graceFraction = DEFAULT_GRACE_FRACTION }) {
|
|
47
|
+
if (run.status !== "in_progress") return { cancel: true, reason: "not started (" + run.status + ")" };
|
|
48
|
+
if (jobs.some((job) => FAILED_JOB_CONCLUSIONS.has(job.conclusion))) return { cancel: true, reason: "a job already failed" };
|
|
49
|
+
if (medianMs === null || !(medianMs > 0)) return { cancel: false, reason: "no median duration to compare with" };
|
|
50
|
+
const startedMs = Date.parse(run.run_started_at ?? run.created_at ?? "");
|
|
51
|
+
if (!Number.isFinite(startedMs)) return { cancel: false, reason: "start time unknown" };
|
|
52
|
+
const elapsedMs = Math.max(0, nowMs - startedMs);
|
|
53
|
+
const limitMs = graceFraction * medianMs;
|
|
54
|
+
if (elapsedMs < limitMs) {
|
|
55
|
+
return { cancel: true, reason: "elapsed " + Math.round(elapsedMs / 1000) + "s is under " + Math.round(limitMs / 1000) + "s" };
|
|
56
|
+
}
|
|
57
|
+
return { cancel: false, reason: "elapsed " + Math.round(elapsedMs / 1000) + "s is past " + Math.round(limitMs / 1000) + "s; left to finish" };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Older runs of the same workflow: lower run number, never the current run. */
|
|
61
|
+
export function olderRuns(runs, current) {
|
|
62
|
+
return runs
|
|
63
|
+
.filter((run) => run.id !== current.id && run.run_number < current.run_number)
|
|
64
|
+
.sort((a, b) => a.run_number - b.run_number);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function parseSettings(env) {
|
|
68
|
+
const fraction = env.RIGHT_GIT_GRACE_FRACTION === undefined || env.RIGHT_GIT_GRACE_FRACTION === ""
|
|
69
|
+
? DEFAULT_GRACE_FRACTION
|
|
70
|
+
: Number(env.RIGHT_GIT_GRACE_FRACTION);
|
|
71
|
+
const window = env.RIGHT_GIT_MEDIAN_WINDOW === undefined || env.RIGHT_GIT_MEDIAN_WINDOW === ""
|
|
72
|
+
? DEFAULT_MEDIAN_WINDOW
|
|
73
|
+
: Number(env.RIGHT_GIT_MEDIAN_WINDOW);
|
|
74
|
+
if (!(fraction > 0 && fraction <= 1)) throw new Error("RIGHT_GIT_GRACE_FRACTION must be above 0 and at most 1");
|
|
75
|
+
if (!Number.isInteger(window) || window < 1 || window > 100) throw new Error("RIGHT_GIT_MEDIAN_WINDOW must be an integer from 1 to 100");
|
|
76
|
+
return { graceFraction: fraction, medianWindow: window };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async function api(env, method, path) {
|
|
80
|
+
const response = await fetch((env.GITHUB_API_URL ?? "https://api.github.com") + path, {
|
|
81
|
+
method,
|
|
82
|
+
headers: {
|
|
83
|
+
accept: "application/vnd.github+json",
|
|
84
|
+
authorization: "Bearer " + env.GH_TOKEN,
|
|
85
|
+
"x-github-api-version": "2022-11-28",
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
if (response.status === 409) return { conflict: true };
|
|
89
|
+
if (!response.ok) throw new Error(method + " " + path + " failed: " + response.status);
|
|
90
|
+
return response.status === 202 || response.status === 204 ? {} : response.json();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export async function main(env = process.env, now = () => Date.now()) {
|
|
94
|
+
const settings = parseSettings(env);
|
|
95
|
+
const repo = env.GITHUB_REPOSITORY;
|
|
96
|
+
const branch = env.GITHUB_REF_NAME;
|
|
97
|
+
const current = await api(env, "GET", "/repos/" + repo + "/actions/runs/" + env.GITHUB_RUN_ID);
|
|
98
|
+
const base = "/repos/" + repo + "/actions/workflows/" + current.workflow_id + "/runs?branch=" + encodeURIComponent(branch) + "&event=push&per_page=100";
|
|
99
|
+
const inProgress = (await api(env, "GET", base + "&status=in_progress")).workflow_runs ?? [];
|
|
100
|
+
const queued = (await api(env, "GET", base + "&status=queued")).workflow_runs ?? [];
|
|
101
|
+
const older = olderRuns([...inProgress, ...queued], current);
|
|
102
|
+
if (older.length === 0) {
|
|
103
|
+
console.log("No older run of this workflow is in progress.");
|
|
104
|
+
return [];
|
|
105
|
+
}
|
|
106
|
+
const finished = (await api(env, "GET", base.replace("per_page=100", "per_page=" + settings.medianWindow) + "&status=success")).workflow_runs ?? [];
|
|
107
|
+
const durations = finished.map(runDurationMs).filter((value) => value !== null);
|
|
108
|
+
const medianMs = durations.length >= MIN_HISTORY ? median(durations) : null;
|
|
109
|
+
const decisions = [];
|
|
110
|
+
for (const run of older) {
|
|
111
|
+
const jobs = run.status === "in_progress"
|
|
112
|
+
? (await api(env, "GET", "/repos/" + repo + "/actions/runs/" + run.id + "/jobs?filter=latest&per_page=100")).jobs ?? []
|
|
113
|
+
: [];
|
|
114
|
+
const decision = decideSupersede({ run, jobs, medianMs, nowMs: now(), graceFraction: settings.graceFraction });
|
|
115
|
+
decisions.push({ id: run.id, ...decision });
|
|
116
|
+
console.log("Run " + run.id + " (#" + run.run_number + "): " + (decision.cancel ? "cancel" : "keep") + ", " + decision.reason);
|
|
117
|
+
if (decision.cancel) await api(env, "POST", "/repos/" + repo + "/actions/runs/" + run.id + "/cancel");
|
|
118
|
+
}
|
|
119
|
+
return decisions;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
123
|
+
main().catch((error) => {
|
|
124
|
+
// Cancelling is an optimization: a failure here must not fail the gate.
|
|
125
|
+
console.log("::warning::supersede check skipped: " + error.message);
|
|
126
|
+
});
|
|
127
|
+
}
|