@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/manifest.mjs CHANGED
@@ -10,6 +10,7 @@ export const MANIFEST_FILENAME = ".rightgit.json";
10
10
 
11
11
  export const KNOWN_LANES = Object.freeze([
12
12
  "ci",
13
+ "swift-check",
13
14
  "qualification",
14
15
  "package-smoke",
15
16
  "release-candidate",
@@ -18,9 +19,15 @@ export const KNOWN_LANES = Object.freeze([
18
19
  "regenerate",
19
20
  ]);
20
21
 
22
+ // Lanes only the rust-hybrid profile has a template for. They are kept out of KNOWN_LANES so the node
23
+ // profile's per-lane template checks do not look for a template it does not have.
24
+ export const RUST_HYBRID_ONLY_LANES = Object.freeze(["sign-existing"]);
25
+
21
26
  // Rendered filename for each lane, installed under <repo>/.github/workflows/.
22
27
  export const LANE_FILENAMES = Object.freeze({
28
+ "sign-existing": "sign-existing.yml",
23
29
  ci: "ci.yml",
30
+ "swift-check": "swift-check.yml",
24
31
  qualification: "qualification.yml",
25
32
  "package-smoke": "package-smoke.yml",
26
33
  "release-candidate": "release-candidate.yml",
@@ -74,6 +81,7 @@ const TOP_LEVEL_KEYS = new Set([
74
81
  "swift",
75
82
  "checkout",
76
83
  "defaultBranch",
84
+ "signExisting",
77
85
  ]);
78
86
  // Optional QA evidence upload (rust-hybrid ci only). qaEvidencePath is a safe
79
87
  // relative path under $RUNNER_TEMP; it renders as `${{ runner.temp }}/<path>`.
@@ -84,6 +92,7 @@ const UPLOAD_ARTIFACT_PIN = "actions/upload-artifact@ea165f8d65b6e75b540449e92b4
84
92
  const GATE_PATH_RE = /^(?!.*\.\.)(?!.*\s)[A-Za-z0-9][A-Za-z0-9._/-]*$/;
85
93
  const RUST_WORKSPACE_PATH_RE = /^(?:\.|(?!.*\.\.)(?!.*\s)[A-Za-z0-9][A-Za-z0-9._/-]*)$/;
86
94
  const PACKAGE_SCRIPT_RE = /^[A-Za-z0-9][A-Za-z0-9:_-]*$/;
95
+ const QA_SURFACE_SCRIPT_RE = /qa-native|qa-control|dev-native|dev-inspect|test-mode/i;
87
96
  const GITHUB_VARIABLE_RE = /^[A-Z][A-Z0-9_]*$/;
88
97
  const RELEASE_PLATFORMS = new Set(["windows", "macos", "linux"]);
89
98
  const RELEASE_ARCHITECTURES = new Set(["x86_64", "arm64"]);
@@ -135,7 +144,7 @@ export function validateManifest(manifest) {
135
144
  lanes = manifest.lanes;
136
145
  const seen = new Set();
137
146
  for (const lane of lanes) {
138
- if (typeof lane !== "string" || !KNOWN_LANES.includes(lane)) {
147
+ if (typeof lane !== "string" || !(KNOWN_LANES.includes(lane) || RUST_HYBRID_ONLY_LANES.includes(lane))) {
139
148
  errors.push(`unknown lane: ${JSON.stringify(lane)}`);
140
149
  } else if (seen.has(lane)) {
141
150
  errors.push(`duplicate lane: ${lane}`);
@@ -172,14 +181,15 @@ export function validateManifest(manifest) {
172
181
  const profile = manifest.profile === undefined ? "node" : manifest.profile;
173
182
  if (profile !== "node" && profile !== "rust-hybrid") errors.push("profile must be 'node' or 'rust-hybrid'");
174
183
  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'");
184
+ if (lanes.some((lane) => lane !== "ci" && lane !== "release-candidate" && lane !== "regenerate" && lane !== "sign-existing") || !lanes.includes("ci")) {
185
+ errors.push("profile 'rust-hybrid' requires lane 'ci' and supports optional lanes 'release-candidate', 'regenerate' and 'sign-existing'");
177
186
  }
178
187
  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
188
  errors.push("profile 'rust-hybrid' requires gate.path with a safe relative path");
180
189
  }
181
- } else if (manifest.gate !== undefined) {
182
- errors.push("gate is only valid for profile 'rust-hybrid'");
190
+ } else {
191
+ if (manifest.gate !== undefined) errors.push("gate is only valid for profile 'rust-hybrid'");
192
+ if (lanes.some((lane) => RUST_HYBRID_ONLY_LANES.includes(lane))) errors.push("lane 'sign-existing' is only valid for profile 'rust-hybrid'");
183
193
  }
184
194
 
185
195
  validateCheckout(manifest.checkout, errors);
@@ -226,6 +236,7 @@ export function validateManifest(manifest) {
226
236
  if (manifest.concurrency !== undefined) validateConcurrency(manifest, lanes, errors);
227
237
  validateDevArtifact(manifest, profile, errors);
228
238
  validateRegenerate(manifest, lanes, errors);
239
+ validateSignExisting(manifest, lanes, errors);
229
240
 
230
241
  const rustCache = manifest.rustCache;
231
242
  if (rustCache !== undefined) {
@@ -259,7 +270,34 @@ export function validateManifest(manifest) {
259
270
  errors.push("candidate must be an object");
260
271
  } else {
261
272
  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}`);
273
+ if (!["buildScript", "checkScript", "admissionScript", "stageSummaryScript", "artifactRoot", "os", "targets", "signWindows", "signMacos", "releaseChain", "devQualification"].includes(key)) errors.push(`unknown candidate field: ${key}`);
274
+ }
275
+ // The sealed, signed candidate must be QA-free (@rightkit/release refuses
276
+ // these surfaces in any release tier). The manifest only carries script
277
+ // names, not the build command's features, so this can only catch a
278
+ // script NAMED after a QA surface; the real check stays in @rightkit/release.
279
+ for (const key of ["buildScript", "checkScript"]) {
280
+ if (typeof candidate[key] === "string" && QA_SURFACE_SCRIPT_RE.test(candidate[key])) {
281
+ errors.push(`candidate.${key} '${candidate[key]}' names a QA surface (qa-native, qa-control, dev-native, dev-inspect or test-mode); the signed candidate must be QA-free. Run in-app journeys against the dev build with candidate.devQualification (see Orthic-Labs/rightkit#107)`);
282
+ }
283
+ }
284
+ if (candidate.devQualification !== undefined) {
285
+ const dev = candidate.devQualification;
286
+ if (dev === null || typeof dev !== "object" || Array.isArray(dev)) {
287
+ errors.push("candidate.devQualification must be an object { buildScript, journeyScript }");
288
+ } else {
289
+ for (const key of Object.keys(dev)) {
290
+ if (!["buildScript", "journeyScript"].includes(key)) errors.push(`unknown candidate.devQualification field: ${key}`);
291
+ }
292
+ for (const key of ["buildScript", "journeyScript"]) {
293
+ if (typeof dev[key] !== "string" || !PACKAGE_SCRIPT_RE.test(dev[key])) {
294
+ errors.push(`candidate.devQualification.${key} must be one safe package script name`);
295
+ }
296
+ }
297
+ if (typeof dev.buildScript === "string" && dev.buildScript === candidate.buildScript) {
298
+ errors.push("candidate.devQualification.buildScript must differ from candidate.buildScript: the dev build (QA surface on) is never the sealed candidate build (Orthic-Labs/rightkit#107)");
299
+ }
300
+ }
263
301
  }
264
302
  // admissionScript & stageSummaryScript are required for EVERY release-candidate
265
303
  // lane, not just signed/full-releaseChain ones: the tag-last workflow's
@@ -395,6 +433,7 @@ export function validateManifest(manifest) {
395
433
  }
396
434
  }
397
435
  if (manifest.swift !== undefined) validateSwift(manifest, lanes, errors);
436
+ if (lanes.includes("swift-check") && manifest.swift?.check === undefined) errors.push("lane 'swift-check' requires swift.check");
398
437
  if (profile !== "rust-hybrid" && candidate !== undefined) {
399
438
  errors.push("candidate is only valid for profile 'rust-hybrid'");
400
439
  }
@@ -607,6 +646,36 @@ function validateRegenerate(manifest, lanes, errors) {
607
646
  }
608
647
  }
609
648
 
649
+ // The sign-existing lane (rust-hybrid, Orthic-Labs/rightkit#257) is manual-only: it verifies an already-qualified
650
+ // artifact of another run of this repository and signs it per file with right-release sign-dev-artifact. It never builds.
651
+ const SIGN_EXISTING_ENVIRONMENT_RE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,99}$/;
652
+
653
+ function validateSignExisting(manifest, lanes, errors) {
654
+ const sign = manifest.signExisting;
655
+ const hasLane = Array.isArray(lanes) && lanes.includes("sign-existing");
656
+ if (sign === undefined) {
657
+ if (hasLane) errors.push("lane 'sign-existing' requires signExisting { macSignManifest, macPayloadMetadata }");
658
+ return;
659
+ }
660
+ if (sign === null || typeof sign !== "object" || Array.isArray(sign)) {
661
+ errors.push("signExisting must be an object");
662
+ return;
663
+ }
664
+ if (!hasLane) errors.push("signExisting requires lane 'sign-existing'");
665
+ for (const key of Object.keys(sign)) {
666
+ if (!["macSignManifest", "macPayloadMetadata", "macPayloadMetadataSource", "environment"].includes(key)) errors.push(`unknown signExisting field: ${key}`);
667
+ }
668
+ if (sign.macPayloadMetadataSource !== undefined) {
669
+ if (typeof sign.macPayloadMetadataSource !== "string" || !GATE_PATH_RE.test(sign.macPayloadMetadataSource)) errors.push("signExisting.macPayloadMetadataSource must be a safe repository-relative path to the generated payload metadata file");
670
+ if (typeof sign.macPayloadMetadata === "string" && sign.macPayloadMetadata.includes("/")) errors.push("signExisting.macPayloadMetadataSource places the file at the inner-zip root, so signExisting.macPayloadMetadata must be a bare file name");
671
+ if (!["sign", "notarize", "unsigned"].includes(manifest.devArtifact?.mac)) errors.push("signExisting.macPayloadMetadataSource needs devArtifact.mac 'sign', 'notarize' or 'unsigned' (the unsigned packaging step zips it)");
672
+ }
673
+ if (typeof sign.macSignManifest !== "string" || !GATE_PATH_RE.test(sign.macSignManifest)) errors.push("signExisting.macSignManifest must be a safe repository-relative path to a sign manifest JSON");
674
+ if (typeof sign.macPayloadMetadata !== "string" || !DEV_MAC_PATH_RE.test(sign.macPayloadMetadata)) errors.push("signExisting.macPayloadMetadata must be a safe path inside the artifact archive");
675
+ if (sign.environment !== undefined && (typeof sign.environment !== "string" || !SIGN_EXISTING_ENVIRONMENT_RE.test(sign.environment))) errors.push("signExisting.environment must be one safe environment name (letters, digits, '.', '_', '-')");
676
+ if (!Array.isArray(manifest.matrix?.os) || !manifest.matrix.os.some((runner) => typeof runner === "string" && MACOS_RUNNER_RE.test(runner))) errors.push("signExisting needs a macOS runner (macos-* or xcode-*) in matrix.os");
677
+ }
678
+
610
679
  // swift.privatePackages (ci, qualification, release-candidate and regenerate lanes;
611
680
  // the parallel dev-artifact-mac job): read access to private Swift package
612
681
  // mirrors from a public repository's CI. The secret is a GitHub Actions secret
@@ -614,13 +683,34 @@ function validateRegenerate(manifest, lanes, errors) {
614
683
  const SWIFT_PRIVATE_MAX_ENTRIES = 4;
615
684
  // Lanes whose workflows carry the configure and cleanup steps. package-smoke,
616
685
  // publish-npm and publish-package-managers never do (clean-room or credentialed jobs).
617
- const SWIFT_PRIVATE_LANES = ["ci", "qualification", "release-candidate", "regenerate"];
686
+ const SWIFT_PRIVATE_LANES = ["ci", "qualification", "release-candidate", "regenerate", "swift-check"];
618
687
  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
688
 
620
689
  function isSwiftPrivateSecretName(value) {
621
690
  return typeof value === "string" && /^[A-Za-z_][A-Za-z0-9_]{0,99}$/.test(value) && !/^github_/i.test(value);
622
691
  }
623
692
 
693
+ // All fields reach shell/YAML literally: reject expressions, whitespace, traversal and option syntax.
694
+ function validateSwiftCheck(check, lanes, errors) {
695
+ if (check === null || typeof check !== "object" || Array.isArray(check)) {
696
+ errors.push("swift.check must be an object");
697
+ return;
698
+ }
699
+ const fields = ["runner", "xcodeVersion", "projectDirectory", "spec", "project", "scheme", "xcodegenVersion"];
700
+ for (const key of Object.keys(check)) if (!fields.includes(key)) errors.push(`unknown swift.check field: ${key}`);
701
+ if (!lanes.includes("swift-check")) errors.push("swift.check requires lane 'swift-check'");
702
+ if (!["macos-15", "macos-15-intel", "macos-26"].includes(check.runner)) errors.push("swift.check.runner must be a pinned GitHub-hosted macOS runner: macos-15, macos-15-intel or macos-26");
703
+ for (const key of ["xcodeVersion", "xcodegenVersion"]) {
704
+ const pattern = key === "xcodegenVersion" ? /^\d+\.\d+\.\d+$/ : /^\d+\.\d+(?:\.\d+)?$/;
705
+ if (typeof check[key] !== "string" || !pattern.test(check[key])) errors.push(`swift.check.${key} must be an exact numeric version`);
706
+ }
707
+ if (typeof check.projectDirectory !== "string" || !RUST_WORKSPACE_PATH_RE.test(check.projectDirectory)) errors.push("swift.check.projectDirectory must be a safe relative directory or '.'");
708
+ for (const [key, extension] of [["spec", /\.ya?ml$/], ["project", /\.xcodeproj$/]]) {
709
+ if (typeof check[key] !== "string" || !GATE_PATH_RE.test(check[key]) || !extension.test(check[key])) errors.push(`swift.check.${key} must be a safe relative ${key === "spec" ? "YAML spec" : "xcodeproj"} path`);
710
+ }
711
+ if (typeof check.scheme !== "string" || !/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(check.scheme)) errors.push("swift.check.scheme must be one safe scheme name");
712
+ }
713
+
624
714
  function validateSwift(manifest, lanes, errors) {
625
715
  const swift = manifest.swift;
626
716
  if (swift === null || typeof swift !== "object" || Array.isArray(swift)) {
@@ -628,8 +718,10 @@ function validateSwift(manifest, lanes, errors) {
628
718
  return;
629
719
  }
630
720
  for (const key of Object.keys(swift)) {
631
- if (key !== "privatePackages") errors.push(`unknown swift field: ${key}`);
721
+ if (key !== "privatePackages" && key !== "check") errors.push(`unknown swift field: ${key}`);
632
722
  }
723
+ if (swift.check !== undefined) validateSwiftCheck(swift.check, lanes, errors);
724
+ if (swift.privatePackages === undefined && swift.check !== undefined) return;
633
725
  const entries = swift.privatePackages;
634
726
  if (!Array.isArray(entries) || entries.length === 0 || entries.length > SWIFT_PRIVATE_MAX_ENTRIES) {
635
727
  errors.push(`swift.privatePackages must be an array of 1 to ${SWIFT_PRIVATE_MAX_ENTRIES} { host, secret } entries`);
@@ -673,7 +765,7 @@ function validateDevArtifact(manifest, profile, errors) {
673
765
  return;
674
766
  }
675
767
  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}`);
768
+ if (!["mac", "windows", "retentionDays", "macAppPath", "macEntitlements", "macSignManifest", "macPayloadMetadata", "windowsGlob", "dispatch", "parallel", "buildScript"].includes(key)) errors.push(`unknown devArtifact field: ${key}`);
677
769
  }
678
770
  if (dev.mac !== undefined && !["sign", "notarize", "unsigned", "none"].includes(dev.mac)) errors.push("devArtifact.mac must be 'sign', 'notarize', 'unsigned' or 'none'");
679
771
  if (dev.windows !== undefined && dev.windows !== "unsigned" && dev.windows !== "none") errors.push("devArtifact.windows must be 'unsigned' or 'none'");
@@ -704,13 +796,21 @@ function validateDevArtifact(manifest, profile, errors) {
704
796
  } else if (dev.macEntitlements !== undefined && (typeof dev.macEntitlements !== "string" || !GATE_PATH_RE.test(dev.macEntitlements))) {
705
797
  errors.push("devArtifact.macEntitlements must be a safe repository-relative path");
706
798
  }
799
+ if (dev.macSignManifest !== undefined) {
800
+ if (dev.mac !== "sign") errors.push("devArtifact.macSignManifest requires mac 'sign' (the per-file lane never notarizes)");
801
+ if (typeof dev.macSignManifest !== "string" || !GATE_PATH_RE.test(dev.macSignManifest)) errors.push("devArtifact.macSignManifest must be a safe repository-relative path to a sign manifest JSON");
802
+ if (dev.macEntitlements !== undefined) errors.push("devArtifact.macSignManifest and macEntitlements cannot be combined; per-file entitlements go in the sign manifest");
803
+ if (typeof dev.macPayloadMetadata !== "string" || !DEV_MAC_PATH_RE.test(dev.macPayloadMetadata)) errors.push("devArtifact.macPayloadMetadata (a safe path inside the staged archive) is required with macSignManifest");
804
+ } else if (dev.macPayloadMetadata !== undefined) {
805
+ errors.push("devArtifact.macPayloadMetadata requires macSignManifest");
806
+ }
707
807
  if (!runners.some((runner) => MACOS_RUNNER_RE.test(runner))) {
708
808
  errors.push(dev.parallel === true
709
809
  ? `devArtifact.mac '${dev.mac}' needs a macOS runner (macos-* or xcode-*) in matrix.os`
710
810
  : `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
811
  }
712
- } else if (dev.macAppPath !== undefined || dev.macEntitlements !== undefined) {
713
- errors.push("devArtifact.macAppPath and macEntitlements require mac 'sign', 'notarize' or 'unsigned'");
812
+ } else if (dev.macAppPath !== undefined || dev.macEntitlements !== undefined || dev.macSignManifest !== undefined || dev.macPayloadMetadata !== undefined) {
813
+ errors.push("devArtifact.macAppPath, macEntitlements, macSignManifest and macPayloadMetadata require mac 'sign', 'notarize' or 'unsigned'");
714
814
  }
715
815
  if (dev.windows === "unsigned") {
716
816
  if (typeof dev.windowsGlob !== "string" || !DEV_WINDOWS_GLOB_RE.test(dev.windowsGlob)) {
@@ -732,6 +832,63 @@ const DEV_PUSH_CONDITION = "github.event_name == 'push' && github.ref_name == gi
732
832
  // PR runs keep cancel-in-progress true, so superseded PR runs still cancel.
733
833
  const CONCURRENCY_MAIN_PUSHES = ["cancel", "queue"];
734
834
  const CI_CANCEL_MAIN_QUEUE_EXPRESSION = "${{ !(github.event_name == 'push' && github.ref_name == github.event.repository.default_branch) }}";
835
+ const CI_GROUP_PER_REF = "${{ github.workflow }}-${{ github.ref }}";
836
+ // A default-branch push gets a group of its own (never queued or cancelled at workflow level, so its
837
+ // `supersede` job always runs); every other event keeps one group per ref.
838
+ const CI_GROUP_SUPERSEDE = "${{ github.workflow }}-${{ github.event_name == 'push' && github.ref_name == github.event.repository.default_branch && github.run_id || github.ref }}";
839
+ const SUPERSEDE_SCRIPT_PATH = new URL("./supersede.mjs", import.meta.url);
840
+ const SUPERSEDE_HEREDOC_END = "RIGHT_GIT_SUPERSEDE_EOF";
841
+
842
+ /**
843
+ * The `ci` (rust-hybrid) / `test` (node) job's own concurrency group. Default-branch pushes share one
844
+ * group per matrix leg with cancel-in-progress false, so a newer run waits for an older run that
845
+ * `supersede` chose to keep: never two runs in progress. Every other event gets a group unique to the
846
+ * run, so pull requests are not serialised against main.
847
+ */
848
+ function ciJobConcurrency() {
849
+ return [
850
+ " concurrency:",
851
+ " 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) }}",
852
+ " cancel-in-progress: false",
853
+ "",
854
+ ].join("\n");
855
+ }
856
+
857
+ /**
858
+ * The `supersede` job: the only job in a managed workflow with `actions: write`. It runs the shipped
859
+ * supersede.mjs (embedded verbatim; pure decision function tested in supersede.test.mjs) and cancels
860
+ * older runs of this workflow on the default branch that only just started or are already failing.
861
+ * `right-git-ci-only` in @rightkit/release accepts `actions: write` only in this exact job shape.
862
+ */
863
+ function supersedeJob(manifest) {
864
+ const concurrency = manifest.concurrency ?? {};
865
+ const script = fs.readFileSync(SUPERSEDE_SCRIPT_PATH, "utf8").replace(/\r\n?/g, "\n").replace(/\n+$/, "");
866
+ const indent = (text) => text.split("\n").map((line) => (line === "" ? "" : ` ${line}`)).join("\n");
867
+ return [
868
+ " supersede:",
869
+ " needs: [private-repo-guard]",
870
+ " if: ${{ github.event_name == 'push' && github.ref_name == github.event.repository.default_branch }}",
871
+ " runs-on: ubuntu-24.04",
872
+ " timeout-minutes: 5",
873
+ " permissions:",
874
+ " contents: read",
875
+ " actions: write",
876
+ " steps:",
877
+ " - name: Cancel superseded runs that only just started or are failing",
878
+ " shell: bash",
879
+ " env:",
880
+ " GH_TOKEN: ${{ github.token }}",
881
+ ` RIGHT_GIT_GRACE_FRACTION: "${concurrency.graceFraction ?? 0.7}"`,
882
+ ` RIGHT_GIT_MEDIAN_WINDOW: "${concurrency.medianWindow ?? 10}"`,
883
+ " run: |",
884
+ " set -euo pipefail",
885
+ ` cat > "$RUNNER_TEMP/supersede.mjs" <<'${SUPERSEDE_HEREDOC_END}'`,
886
+ indent(script),
887
+ ` ${SUPERSEDE_HEREDOC_END}`,
888
+ ' node "$RUNNER_TEMP/supersede.mjs"',
889
+ "",
890
+ ].join("\n");
891
+ }
735
892
  // rustCache.keySuffix: charset-checked before it reaches the rendered `key` input.
736
893
  const RUST_CACHE_KEY_SUFFIX_RE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
737
894
 
@@ -742,11 +899,31 @@ function validateConcurrency(manifest, lanes, errors) {
742
899
  return;
743
900
  }
744
901
  for (const key of Object.keys(concurrency)) {
745
- if (key !== "mainPushes") errors.push(`unknown concurrency field: ${key}`);
902
+ if (!["mainPushes", "reason", "graceFraction", "medianWindow"].includes(key)) errors.push(`unknown concurrency field: ${key}`);
903
+ }
904
+ if (concurrency.graceFraction !== undefined
905
+ && !(typeof concurrency.graceFraction === "number" && concurrency.graceFraction > 0 && concurrency.graceFraction <= 1)) {
906
+ errors.push("concurrency.graceFraction must be a number above 0 and at most 1");
907
+ }
908
+ if (concurrency.medianWindow !== undefined
909
+ && !(Number.isInteger(concurrency.medianWindow) && concurrency.medianWindow >= 1 && concurrency.medianWindow <= 100)) {
910
+ errors.push("concurrency.medianWindow must be an integer from 1 to 100");
911
+ }
912
+ if (concurrency.mainPushes === "queue" && (concurrency.graceFraction !== undefined || concurrency.medianWindow !== undefined)) {
913
+ errors.push("concurrency.graceFraction and concurrency.medianWindow apply only to the default supersede rule, not mainPushes 'queue'");
746
914
  }
747
915
  if (concurrency.mainPushes !== undefined && !CONCURRENCY_MAIN_PUSHES.includes(concurrency.mainPushes)) {
748
916
  errors.push("concurrency.mainPushes must be 'cancel' or 'queue'");
749
917
  }
918
+ if (concurrency.mainPushes === "queue") {
919
+ if (typeof concurrency.reason !== "string" || concurrency.reason.trim() === "") {
920
+ errors.push("concurrency.mainPushes 'queue' requires a non-empty concurrency.reason");
921
+ } else if (/[\r\n\u0085\u2028\u2029]/.test(concurrency.reason)) {
922
+ errors.push("concurrency.reason must be a single line");
923
+ }
924
+ } else if (concurrency.reason !== undefined) {
925
+ errors.push("concurrency.reason is only allowed with concurrency.mainPushes 'queue'");
926
+ }
750
927
  if (!Array.isArray(lanes) || !lanes.includes("ci")) {
751
928
  errors.push("concurrency requires lane 'ci' (it sets the ci workflow's concurrency)");
752
929
  }
@@ -827,7 +1004,7 @@ export function devArtifactCi(manifest, options = {}) {
827
1004
  " set -euo pipefail",
828
1005
  " test -d \"$DEV_APP_PATH\"",
829
1006
  " mkdir -p \"$RUNNER_TEMP/dev-unsigned\"",
830
- " ditto -c -k --keepParent \"$DEV_APP_PATH\" \"$RUNNER_TEMP/dev-unsigned/app.zip\"",
1007
+ ...devMacZipLines(manifest),
831
1008
  " - name: Upload unsigned dev app for signing (macOS)",
832
1009
  ` if: \${{ ${DEV_PUSH_CONDITION} && runner.os == 'macOS' }}`,
833
1010
  ` uses: ${UPLOAD_ARTIFACT_PIN}`,
@@ -850,7 +1027,7 @@ export function devArtifactCi(manifest, options = {}) {
850
1027
  " set -euo pipefail",
851
1028
  " test -d \"$DEV_APP_PATH\"",
852
1029
  " mkdir -p \"$RUNNER_TEMP/dev-unsigned\"",
853
- " ditto -c -k --keepParent \"$DEV_APP_PATH\" \"$RUNNER_TEMP/dev-unsigned/app.zip\"",
1030
+ ...devMacZipLines(manifest),
854
1031
  " - name: Upload unsigned dev app (macOS)",
855
1032
  ` if: \${{ ${unsignedCondition} && runner.os == 'macOS' }}`,
856
1033
  ` uses: ${UPLOAD_ARTIFACT_PIN}`,
@@ -891,6 +1068,23 @@ function firstMatchingRunner(manifest, pattern, platform) {
891
1068
  return runner;
892
1069
  }
893
1070
 
1071
+ // The line that zips the built .app into the inner zip. With `signExisting.macPayloadMetadataSource` set, the .app (wrapper layout
1072
+ // preserved, ditto) and the generated payload metadata file are staged together and zipped so the file sits at the inner-zip root
1073
+ // under the basename of `macPayloadMetadata`; a missing file fails the step. Unset, the single original line renders, byte-identical.
1074
+ function devMacZipLines(manifest) {
1075
+ const source = manifest.signExisting?.macPayloadMetadataSource;
1076
+ if (typeof source !== "string") return [' ditto -c -k --keepParent "$DEV_APP_PATH" "$RUNNER_TEMP/dev-unsigned/app.zip"'];
1077
+ const name = path.posix.basename(manifest.signExisting.macPayloadMetadata);
1078
+ return [
1079
+ ` test -f ${JSON.stringify(source)}`,
1080
+ ' stage="$RUNNER_TEMP/dev-unsigned-stage"',
1081
+ ' rm -rf "$stage" && mkdir -p "$stage"',
1082
+ ' ditto "$DEV_APP_PATH" "$stage/$(basename "$DEV_APP_PATH")"',
1083
+ ` cp ${JSON.stringify(source)} "$stage/${name}"`,
1084
+ ' ditto -c -k "$stage" "$RUNNER_TEMP/dev-unsigned/app.zip"',
1085
+ ];
1086
+ }
1087
+
894
1088
  function devMacArtifactJob({ manifest, lane, artifactPrefix, retention }) {
895
1089
  const dev = manifest.devArtifact;
896
1090
  const signed = dev.mac === "sign" || dev.mac === "notarize";
@@ -903,7 +1097,7 @@ function devMacArtifactJob({ manifest, lane, artifactPrefix, retention }) {
903
1097
  " set -euo pipefail",
904
1098
  " test -d \"$DEV_APP_PATH\"",
905
1099
  " mkdir -p \"$RUNNER_TEMP/dev-unsigned\"",
906
- " ditto -c -k --keepParent \"$DEV_APP_PATH\" \"$RUNNER_TEMP/dev-unsigned/app.zip\"",
1100
+ ...devMacZipLines(manifest),
907
1101
  ...(signed
908
1102
  ? [
909
1103
  " - name: Upload unsigned dev app for signing (macOS)",
@@ -1020,13 +1214,35 @@ function devMacSigningJob(manifest, dev, retention) {
1020
1214
  const parallel = dev.parallel === true;
1021
1215
  const runner = (parallel ? manifest.matrix.os : effectiveCiRunners(manifest)).find((os) => MACOS_RUNNER_RE.test(os));
1022
1216
  const entitlements = dev.macEntitlements ? ` --entitlements "$GITHUB_WORKSPACE/${dev.macEntitlements}"` : "";
1023
- const checkout = dev.macEntitlements
1217
+ // `macSignManifest`: sign each file with its fixed identifier through `right-release sign-dev-artifact`
1218
+ // (Orthic-Labs/rightkit#257) instead of `codesign --deep` on the .app. It needs the repo (the manifest) and the
1219
+ // installed right-release; unset, none of this renders and the --deep lane is byte-identical.
1220
+ const perFile = typeof dev.macSignManifest === "string";
1221
+ const pm = perFile ? parsePackageManager(manifest.packageManager) : null;
1222
+ const exec = pm ? { pnpm: "pnpm exec", npm: "npm exec --", yarn: "yarn exec" }[pm.name] : "";
1223
+ const checkout = dev.macEntitlements || perFile
1024
1224
  ? ` - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
1025
1225
  with:
1026
1226
  ref: \${{ github.sha }}
1027
1227
  persist-credentials: false
1028
- `
1228
+ ${perFile ? ` - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
1229
+ with:
1230
+ node-version: ${String(manifest.matrix.node[0])}
1231
+ package-manager-cache: false
1232
+ ${pm.setup ? `${pm.setup}\n` : ""} - run: ${pm.installCommand}
1233
+ ` : ""}`
1029
1234
  : "";
1235
+ const signLines = perFile
1236
+ ? ` mkdir -p "$RUNNER_TEMP/dev-signed"
1237
+ ${exec} right-release sign-dev-artifact --artifact "$work" --manifest "$GITHUB_WORKSPACE/${dev.macSignManifest}" --metadata "$work/${dev.macPayloadMetadata}" --evidence "$RUNNER_TEMP/dev-signed/sign-evidence.json"`
1238
+ : ` codesign --force --deep --strict --options runtime --timestamp${entitlements} --sign "$APPLE_DEVELOPER_ID" "$app"
1239
+ codesign --verify --deep --strict "$app"
1240
+ mkdir -p "$RUNNER_TEMP/dev-signed"`;
1241
+ const uploadPath = perFile
1242
+ ? `|
1243
+ \${{ runner.temp }}/dev-signed/*.zip
1244
+ \${{ runner.temp }}/dev-signed/sign-evidence.json`
1245
+ : "${{ runner.temp }}/dev-signed/*.zip";
1030
1246
  // `mac: "notarize"` also submits the signed app to the notary service and
1031
1247
  // staples the ticket, so app extensions (Finder Sync, Share, ...) register on
1032
1248
  // current macOS, which refuses them from unnotarized Developer ID apps.
@@ -1096,15 +1312,13 @@ ${checkout} - name: Download unsigned dev app
1096
1312
  ditto -x -k "$RUNNER_TEMP/dev-unsigned/app.zip" "$work"
1097
1313
  app="$(find "$work" -maxdepth 1 -name '*.app' -print -quit)"
1098
1314
  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"
1315
+ ${signLines}
1102
1316
  ditto -c -k --keepParent "$app" "$RUNNER_TEMP/dev-signed/$(basename "$app").zip"
1103
1317
  ${notarizeStep} - name: ${uploadLabel}
1104
1318
  uses: ${UPLOAD_ARTIFACT_PIN}
1105
1319
  with:
1106
1320
  name: dev-mac-\${{ github.sha }}
1107
- path: \${{ runner.temp }}/dev-signed/*.zip
1321
+ path: ${uploadPath}
1108
1322
  retention-days: ${retention}
1109
1323
  if-no-files-found: error
1110
1324
  - name: Remove Apple signing material
@@ -1116,6 +1330,268 @@ ${notarizeStep} - name: ${uploadLabel}
1116
1330
  `;
1117
1331
  }
1118
1332
 
1333
+ // sign-existing lane job (Orthic-Labs/rightkit#257). Signs an already-qualified artifact of ANOTHER run; it never builds,
1334
+ // never passes --release, never notarizes. Run id, artifact and source sha arrive as workflow_dispatch inputs and reach the
1335
+ // shell only through env vars, after a format check. The keychain install and removal steps mirror devMacSigningJob exactly
1336
+ // (same secrets, same temporary keychain); keep the two in step. Bash here avoids a braced upper-case variable, which the
1337
+ // template engine would read as a placeholder.
1338
+ function signExistingJob(manifest) {
1339
+ const sign = manifest.signExisting;
1340
+ const runner = manifest.matrix.os.find((os) => MACOS_RUNNER_RE.test(os));
1341
+ const pm = parsePackageManager(manifest.packageManager);
1342
+ const exec = { pnpm: "pnpm exec", npm: "npm exec --", yarn: "yarn exec" }[pm.name];
1343
+ const environment = sign.environment ?? releaseEnvironment(manifest, "signing");
1344
+ return `
1345
+ sign-existing:
1346
+ # Default branch only: the signing code and sign manifest come from this revision, and the protected
1347
+ # environment's rules (required reviewers, branch policy) apply. Nothing here compiles the app.
1348
+ needs: [private-repo-guard]
1349
+ if: \${{ github.event_name == 'workflow_dispatch' && github.ref_name == github.event.repository.default_branch }}
1350
+ environment: ${environment}
1351
+ runs-on: ${runner}
1352
+ timeout-minutes: 30
1353
+ permissions:
1354
+ contents: read
1355
+ actions: read
1356
+ steps:
1357
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
1358
+ with:
1359
+ ref: \${{ github.sha }}
1360
+ fetch-depth: 0
1361
+ persist-credentials: false
1362
+ - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
1363
+ with:
1364
+ node-version: ${String(manifest.matrix.node[0])}
1365
+ package-manager-cache: false
1366
+ ${pm.setup ? `${pm.setup}\n` : ""} - run: ${pm.installCommand}${ownershipStep(manifest, "sign-existing")}
1367
+ - name: Verify the existing artifact belongs to this repository, run and source commit
1368
+ id: verify
1369
+ shell: bash
1370
+ env:
1371
+ GH_TOKEN: \${{ github.token }}
1372
+ INPUT_RUN_ID: \${{ inputs.run_id }}
1373
+ INPUT_ARTIFACT: \${{ inputs.artifact }}
1374
+ INPUT_SOURCE_SHA: \${{ inputs.source_sha }}
1375
+ run: |
1376
+ set -euo pipefail
1377
+ fail() { echo "sign-existing refused: $*" >&2; exit 1; }
1378
+ command -v jq >/dev/null || fail "jq is not available on this runner"
1379
+ [[ "$INPUT_RUN_ID" =~ ^[1-9][0-9]{0,19}$ ]] || fail "run_id must be a numeric workflow run id"
1380
+ [[ "$INPUT_ARTIFACT" =~ ^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$ ]] || fail "artifact must be a numeric artifact id or a plain artifact name"
1381
+ [[ "$INPUT_SOURCE_SHA" =~ ^[0-9a-f]{7,40}$ ]] || fail "source_sha must be 7 to 40 lowercase hexadecimal characters"
1382
+ run_json="$(gh api "repos/$GITHUB_REPOSITORY/actions/runs/$INPUT_RUN_ID")"
1383
+ run_id="$(jq -r '.id' <<<"$run_json")"
1384
+ run_repo="$(jq -r '.repository.full_name' <<<"$run_json")"
1385
+ run_repo_id="$(jq -r '.repository.id' <<<"$run_json")"
1386
+ head_repo="$(jq -r '.head_repository.full_name // empty' <<<"$run_json")"
1387
+ head_repo_id="$(jq -r '.head_repository.id // empty' <<<"$run_json")"
1388
+ head_sha="$(jq -r '.head_sha' <<<"$run_json")"
1389
+ status="$(jq -r '.status' <<<"$run_json")"
1390
+ conclusion="$(jq -r '.conclusion // empty' <<<"$run_json")"
1391
+ [ "$run_id" = "$INPUT_RUN_ID" ] || fail "run id mismatch"
1392
+ [ "$run_repo" = "$GITHUB_REPOSITORY" ] || fail "run $INPUT_RUN_ID belongs to $run_repo, not $GITHUB_REPOSITORY"
1393
+ [ "$head_repo" = "$GITHUB_REPOSITORY" ] && [ "$head_repo_id" = "$run_repo_id" ] || fail "run $INPUT_RUN_ID was built from another repository or a fork"
1394
+ [ "$status" = completed ] && [ "$conclusion" = success ] || fail "run $INPUT_RUN_ID is $status/$conclusion, not a successful completed run"
1395
+ [[ "$head_sha" =~ ^[0-9a-f]{40}$ ]] || fail "run head sha is not a full commit sha"
1396
+ case "$head_sha" in "$INPUT_SOURCE_SHA"*) ;; *) fail "run $INPUT_RUN_ID head sha $head_sha does not start with source_sha $INPUT_SOURCE_SHA" ;; esac
1397
+ artifacts_json="$(gh api --paginate "repos/$GITHUB_REPOSITORY/actions/runs/$INPUT_RUN_ID/artifacts?per_page=100" | jq -s '[.[].artifacts[]]')"
1398
+ if [[ "$INPUT_ARTIFACT" =~ ^[0-9]+$ ]]; then
1399
+ picked="$(jq -c --argjson id "$INPUT_ARTIFACT" '[.[] | select(.id == $id)]' <<<"$artifacts_json")"
1400
+ else
1401
+ picked="$(jq -c --arg name "$INPUT_ARTIFACT" '[.[] | select(.name == $name)]' <<<"$artifacts_json")"
1402
+ fi
1403
+ [ "$(jq 'length' <<<"$picked")" = 1 ] || fail "artifact $INPUT_ARTIFACT is not exactly one artifact of run $INPUT_RUN_ID"
1404
+ artifact_id="$(jq -r '.[0].id' <<<"$picked")"
1405
+ artifact_name="$(jq -r '.[0].name' <<<"$picked")"
1406
+ [ "$(jq -r '.[0].expired' <<<"$picked")" = false ] || fail "artifact $artifact_name has expired"
1407
+ [ "$(jq -r '.[0].workflow_run.id' <<<"$picked")" = "$INPUT_RUN_ID" ] || fail "artifact $artifact_name belongs to another run"
1408
+ [ "$(jq -r '.[0].workflow_run.head_sha' <<<"$picked")" = "$head_sha" ] || fail "artifact $artifact_name was built from another commit"
1409
+ [ "$(jq -r '.[0].workflow_run.head_repository_id' <<<"$picked")" = "$run_repo_id" ] || fail "artifact $artifact_name was built from another repository"
1410
+ [[ "$artifact_name" =~ ^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$ ]] || fail "artifact name is not a plain name"
1411
+ git cat-file -e "$head_sha^{commit}" 2>/dev/null || fail "source commit $head_sha is not in this repository's history"
1412
+ git merge-base --is-ancestor "$head_sha" "$GITHUB_SHA" || fail "source commit $head_sha is not an ancestor of the signing revision $GITHUB_SHA"
1413
+ mkdir -p "$RUNNER_TEMP/dev-signed"
1414
+ jq -n --arg repo "$GITHUB_REPOSITORY" --arg run "$run_id" --argjson artifactId "$artifact_id" --arg artifactName "$artifact_name" --arg sourceSha "$head_sha" --arg requested "$INPUT_SOURCE_SHA" --arg signingRevision "$GITHUB_SHA" '{schema: 1, repository: $repo, runId: $run, artifactId: $artifactId, artifactName: $artifactName, sourceSha: $sourceSha, requestedSourceSha: $requested, signingRevision: $signingRevision}' > "$RUNNER_TEMP/dev-signed/source-verification.json"
1415
+ {
1416
+ printf 'run_id=%s\\n' "$run_id"
1417
+ printf 'artifact_id=%s\\n' "$artifact_id"
1418
+ printf 'artifact_name=%s\\n' "$artifact_name"
1419
+ printf 'head_sha=%s\\n' "$head_sha"
1420
+ } >> "$GITHUB_OUTPUT"
1421
+ - name: Download the verified artifact
1422
+ uses: actions/download-artifact@${DOWNLOAD_ARTIFACT_SHA} # v4.3.0
1423
+ with:
1424
+ name: \${{ steps.verify.outputs.artifact_name }}
1425
+ run-id: \${{ steps.verify.outputs.run_id }}
1426
+ repository: \${{ github.repository }}
1427
+ github-token: \${{ github.token }}
1428
+ path: \${{ runner.temp }}/existing-artifact
1429
+ - name: Install Apple signing identity in temporary keychain
1430
+ shell: bash
1431
+ env:
1432
+ APPLE_CERTIFICATE_BASE64: \${{ secrets.APPLE_CERTIFICATE_BASE64 }}
1433
+ APPLE_CERTIFICATE_PASSWORD: \${{ secrets.APPLE_CERTIFICATE_PASSWORD }}
1434
+ APPLE_KEYCHAIN_PASSWORD: \${{ secrets.APPLE_KEYCHAIN_PASSWORD }}
1435
+ run: |
1436
+ set -euo pipefail
1437
+ certificate_path="$RUNNER_TEMP/apple-signing.p12"
1438
+ keychain_path="$RUNNER_TEMP/apple-signing.keychain-db"
1439
+ printf '%s' "$APPLE_CERTIFICATE_BASE64" | base64 --decode > "$certificate_path"
1440
+ security create-keychain -p "$APPLE_KEYCHAIN_PASSWORD" "$keychain_path"
1441
+ security set-keychain-settings -lut 21600 "$keychain_path"
1442
+ security unlock-keychain -p "$APPLE_KEYCHAIN_PASSWORD" "$keychain_path"
1443
+ security import "$certificate_path" -P "$APPLE_CERTIFICATE_PASSWORD" -A -t cert -f pkcs12 -k "$keychain_path"
1444
+ security set-key-partition-list -S apple-tool:,apple: -k "$APPLE_KEYCHAIN_PASSWORD" "$keychain_path"
1445
+ security list-keychain -d user -s "$keychain_path"
1446
+ - name: Developer ID sign existing artifact (no rebuild, no notarization)
1447
+ shell: bash
1448
+ env:
1449
+ APPLE_DEVELOPER_ID: \${{ vars.APPLE_DEVELOPER_ID }}
1450
+ run: |
1451
+ set -euo pipefail
1452
+ downloaded="$RUNNER_TEMP/existing-artifact"
1453
+ work="$RUNNER_TEMP/dev-sign"
1454
+ rm -rf "$work" && mkdir -p "$work" "$RUNNER_TEMP/dev-signed"
1455
+ zips=()
1456
+ while IFS= read -r -d '' file; do zips+=("$file"); done < <(find "$downloaded" -type f -name '*.zip' -print0)
1457
+ if [ "\${#zips[@]}" -eq 1 ]; then
1458
+ ditto -x -k "\${zips[0]}" "$work"
1459
+ out="$(basename "\${zips[0]}")"
1460
+ elif [ "\${#zips[@]}" -eq 0 ]; then
1461
+ ditto "$downloaded" "$work"
1462
+ out="signed-artifact.zip"
1463
+ else
1464
+ echo "sign-existing refused: the artifact holds more than one zip" >&2
1465
+ exit 1
1466
+ fi
1467
+ ${exec} right-release sign-dev-artifact --artifact "$work" --manifest "$GITHUB_WORKSPACE/${sign.macSignManifest}" --metadata "$work/${sign.macPayloadMetadata}" --evidence "$RUNNER_TEMP/dev-signed/sign-evidence.json"
1468
+ ditto -c -k "$work" "$RUNNER_TEMP/dev-signed/$out"
1469
+ - name: Upload signed existing artifact
1470
+ uses: ${UPLOAD_ARTIFACT_PIN}
1471
+ with:
1472
+ name: signed-\${{ steps.verify.outputs.artifact_name }}-\${{ steps.verify.outputs.head_sha }}
1473
+ path: |
1474
+ \${{ runner.temp }}/dev-signed/*.zip
1475
+ \${{ runner.temp }}/dev-signed/sign-evidence.json
1476
+ \${{ runner.temp }}/dev-signed/source-verification.json
1477
+ retention-days: ${DEV_ARTIFACT_DEFAULT_RETENTION_DAYS}
1478
+ if-no-files-found: error
1479
+ - name: Remove Apple signing material
1480
+ if: \${{ always() }}
1481
+ shell: bash
1482
+ run: |
1483
+ security delete-keychain "$RUNNER_TEMP/apple-signing.keychain-db" 2>/dev/null || true
1484
+ rm -f "$RUNNER_TEMP/apple-signing.p12"
1485
+ `;
1486
+ }
1487
+
1488
+ // A configured dev-qualification job gates both signing jobs: a failed or
1489
+ // skipped dev qualification leaves signing skipped (neither signing job uses
1490
+ // always()). Unconfigured, the list is byte-identical to the original.
1491
+ function signingNeeds(manifest) {
1492
+ return manifest.candidate?.devQualification ? "[admission, candidate, dev-qualification]" : "[admission, candidate]";
1493
+ }
1494
+
1495
+ // Optional lane (Orthic-Labs/rightkit#107): builds the DEV build (QA surface on)
1496
+ // from the same admitted source_revision and runs the app's in-app journeys
1497
+ // against it. Never touches candidate or signed bytes; the signed candidate stays
1498
+ // QA-free and is qualified from outside by installed-qualification.
1499
+ function devQualificationJob(manifest, pm, artifactPrefix, cacheKeyLine) {
1500
+ const dev = manifest.candidate?.devQualification;
1501
+ if (!dev) return "";
1502
+ const root = `\${{ runner.temp }}/${manifest.candidate.artifactRoot}-devqual`;
1503
+ const identity = `\${{ needs.admission.outputs.version }}-\${{ needs.admission.outputs.source_revision }}\${{ needs.admission.outputs.artifact_suffix }}`;
1504
+ const stageEnv = (action, extra = "") => ` RIGHT_GIT_STAGE_ACTION: ${action}
1505
+ RIGHT_GIT_STAGE_ROOT: \${{ runner.temp }}/right-git-stage-summary
1506
+ RIGHT_GIT_STAGE_EVIDENCE_ROOT: ${root}
1507
+ RIGHT_GIT_STAGE: dev-qualification
1508
+ RIGHT_GIT_STAGE_PRODUCER: dev-qualification-\${{ matrix.platform }}-\${{ matrix.architecture }}${extra}
1509
+ RIGHT_GIT_RELEASE_VERSION: \${{ needs.admission.outputs.version }}
1510
+ RIGHT_GIT_SOURCE_REVISION: \${{ needs.admission.outputs.source_revision }}
1511
+ RIGHT_GIT_RELEASE_PLATFORM: \${{ matrix.platform }}
1512
+ RIGHT_GIT_RELEASE_ARCHITECTURE: \${{ matrix.architecture }}
1513
+ RIGHT_GIT_RUN_ID: \${{ github.run_id }}
1514
+ RIGHT_GIT_RUN_ATTEMPT: \${{ github.run_attempt }}`;
1515
+ const stepEnv = ` RIGHT_GIT_ARTIFACT_ROOT: ${root}
1516
+ RIGHT_GIT_RELEASE_PLATFORM: \${{ matrix.platform }}
1517
+ RIGHT_GIT_RELEASE_ARCHITECTURE: \${{ matrix.architecture }}
1518
+ RIGHT_GIT_SOURCE_REVISION: \${{ needs.admission.outputs.source_revision }}`;
1519
+ return `
1520
+ dev-qualification:
1521
+ needs: [admission]
1522
+ env:
1523
+ SCCACHE_GHA_ENABLED: "true"
1524
+ RUSTC_WRAPPER: "sccache"
1525
+ RIGHTKIT_DEV_SIGNING: "ci-adhoc"
1526
+ strategy:
1527
+ fail-fast: false
1528
+ matrix:
1529
+ ${candidateMatrix(manifest)}
1530
+ runs-on: \${{ matrix.os }}
1531
+ steps:
1532
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
1533
+ with:
1534
+ ref: \${{ needs.admission.outputs.source_revision }}
1535
+ fetch-depth: 0
1536
+ persist-credentials: false
1537
+ - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
1538
+ with:
1539
+ node-version: \${{ matrix.node }}
1540
+ package-manager-cache: false
1541
+ ${pm.setup}
1542
+ - uses: dtolnay/rust-toolchain@f8be11a05b1d4f3fcebe6410cc16743212b999b0
1543
+ with:
1544
+ components: rustfmt, clippy
1545
+ targets: \${{ matrix.targetTriple }}
1546
+ - uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2
1547
+ with:
1548
+ workspaces: |
1549
+ ${(manifest.rustCache?.workspaces ?? ["engine"]).map((workspace) => ` ${workspace} -> target`).join("\n")}
1550
+ shared-key: ${artifactPrefix}-rust
1551
+ add-job-id-key: false
1552
+ ${cacheKeyLine ? `${cacheKeyLine}\n` : ""} cache-workspace-crates: false
1553
+ cache-on-failure: true
1554
+ save-if: true
1555
+ - uses: Mozilla-Actions/sccache-action@fc920bf0ec8de6ee65d409111f7ec508035751ba # v0.0.11
1556
+ with:
1557
+ version: "v0.16.0"
1558
+ - run: ${pm.installCommand}
1559
+ - name: Initialize dev-qualification stage summary
1560
+ run: ${pm.runPrefix} ${manifest.candidate.stageSummaryScript}
1561
+ env:
1562
+ ${stageEnv("init")}${swiftPrivatePackagesConfigureStep(manifest)}
1563
+ - name: Build dev build (QA surface on, never signed)
1564
+ run: ${pm.runPrefix} ${dev.buildScript}
1565
+ env:
1566
+ ${stepEnv}
1567
+ - name: Run in-app journeys against the dev build
1568
+ run: ${pm.runPrefix} ${dev.journeyScript}
1569
+ env:
1570
+ ${stepEnv}${swiftPrivatePackagesCleanupStep(manifest)}
1571
+ - name: Finalize dev-qualification stage summary
1572
+ if: \${{ always() }}
1573
+ run: ${pm.runPrefix} ${manifest.candidate.stageSummaryScript}
1574
+ env:
1575
+ ${stageEnv("finalize", `
1576
+ RIGHT_GIT_STAGE_STATUS: \${{ job.status == 'success' && 'SUCCEEDED' || 'FAILED' }}
1577
+ RIGHT_GIT_STAGE_EXIT_CODE: \${{ job.status == 'success' && '0' || '1' }}`)}
1578
+ - name: Upload dev-qualification evidence
1579
+ if: \${{ always() }}
1580
+ uses: actions/upload-artifact@${UPLOAD_ARTIFACT_SHA} # v4
1581
+ with:
1582
+ name: ${artifactPrefix}-\${{ github.run_id }}-\${{ github.run_attempt }}-devqual-\${{ matrix.platform }}-\${{ matrix.architecture }}-${identity}
1583
+ path: ${root}/**
1584
+ if-no-files-found: error
1585
+ - name: Upload dev-qualification stage summary
1586
+ if: \${{ always() }}
1587
+ uses: actions/upload-artifact@${UPLOAD_ARTIFACT_SHA} # v4
1588
+ with:
1589
+ name: ${artifactPrefix}-\${{ github.run_id }}-\${{ github.run_attempt }}-summary-dev-qualification-\${{ matrix.platform }}-\${{ matrix.architecture }}-${identity}
1590
+ path: \${{ runner.temp }}/right-git-stage-summary/stage-summary.json
1591
+ if-no-files-found: error
1592
+ `;
1593
+ }
1594
+
1119
1595
  function windowsSigningJob(manifest, pm, artifactPrefix) {
1120
1596
  if (manifest.candidate?.signWindows !== true) return "";
1121
1597
  const nodeVersion = String(manifest.matrix.node[0]);
@@ -1130,12 +1606,15 @@ function windowsSigningJob(manifest, pm, artifactPrefix) {
1130
1606
  : ` LEGION_UNSIGNED_CANDIDATE_ROOT: \${{ runner.temp }}/unsigned-windows-candidate
1131
1607
  RIGHT_GIT_SOURCE_REVISION: \${{ needs.admission.outputs.source_revision }}
1132
1608
  LEGION_SOURCE_REVISION: \${{ needs.admission.outputs.source_revision }}`;
1609
+ // Orthic-Labs/rightkit#183: a source QA receipt carried in the candidate handoff (`qa/source.receipt.json`, written by
1610
+ // `right-release qa --stage source --carry-to <artifact root>/qa`) is read by `right-release build`. Absent file: no effect.
1611
+ const qaReceiptEnvironment = `\n RIGHT_RELEASE_QA_RECEIPT: \${{ runner.temp }}/unsigned-windows-candidate/qa`;
1133
1612
  const uploadPath = releaseChain
1134
1613
  ? " ${{ runner.temp }}/finalized-windows/**"
1135
1614
  : " dist/releases/windows/**\n .right-release/receipts/windows-*.json";
1136
1615
  return `
1137
1616
  windows-sign:
1138
- needs: [admission, candidate]
1617
+ needs: ${signingNeeds(manifest)}
1139
1618
  if: \${{ needs.admission.outputs.signed_qualification == 'true' }}
1140
1619
  environment: ${releaseEnvironment(manifest, "signing")}
1141
1620
  strategy:
@@ -1205,7 +1684,7 @@ ${pm.setup}
1205
1684
  - name: Sign & finalize Windows candidate
1206
1685
  run: ${finalizeCommand}
1207
1686
  env:
1208
- ${finalizeEnvironment}
1687
+ ${finalizeEnvironment}${qaReceiptEnvironment}
1209
1688
  RIGHT_GIT_RELEASE_PLATFORM: \${{ matrix.platform }}
1210
1689
  RIGHT_GIT_RELEASE_ARCHITECTURE: \${{ matrix.architecture }}
1211
1690
  AZURE_ARTIFACT_SIGNING_ENDPOINT: \${{ vars.AZURE_ARTIFACT_SIGNING_ENDPOINT }}
@@ -1260,12 +1739,13 @@ function macosSigningJob(manifest, pm, artifactPrefix) {
1260
1739
  : ` LEGION_UNSIGNED_CANDIDATE_ROOT: \${{ runner.temp }}/unsigned-macos-candidate
1261
1740
  RIGHT_GIT_SOURCE_REVISION: \${{ needs.admission.outputs.source_revision }}
1262
1741
  LEGION_SOURCE_REVISION: \${{ needs.admission.outputs.source_revision }}`;
1742
+ const qaReceiptEnvironment = `\n RIGHT_RELEASE_QA_RECEIPT: \${{ runner.temp }}/unsigned-macos-candidate/qa`;
1263
1743
  const uploadPath = releaseChain
1264
1744
  ? " ${{ runner.temp }}/finalized-macos/**"
1265
1745
  : " dist/releases/mac/**\n .right-release/receipts/macos-*.json";
1266
1746
  return `
1267
1747
  macos-sign:
1268
- needs: [admission, candidate]
1748
+ needs: ${signingNeeds(manifest)}
1269
1749
  if: \${{ needs.admission.outputs.signed_qualification == 'true' }}
1270
1750
  environment: ${releaseEnvironment(manifest, "signing")}
1271
1751
  strategy:
@@ -1333,7 +1813,7 @@ ${pm.setup}
1333
1813
  - name: Sign, notarize & finalize macOS candidate
1334
1814
  run: ${finalizeCommand}
1335
1815
  env:
1336
- ${finalizeEnvironment}
1816
+ ${finalizeEnvironment}${qaReceiptEnvironment}
1337
1817
  RIGHT_GIT_RELEASE_PLATFORM: \${{ matrix.platform }}
1338
1818
  RIGHT_GIT_RELEASE_ARCHITECTURE: \${{ matrix.architecture }}
1339
1819
  APPLE_DEVELOPER_ID: \${{ vars.APPLE_DEVELOPER_ID }}
@@ -1629,7 +2109,13 @@ export function ownershipStep(manifest, lane = "ci") {
1629
2109
  : manifest.profile === "rust-hybrid"
1630
2110
  ? "\${{ inputs.source_revision }}"
1631
2111
  : "\${{ 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}`;
2112
+ // Ownership approval supports only macOS and Windows (Orthic-Labs/rightkit#245). A rust-hybrid ci
2113
+ // job that runs every matrix.os runner (ciAllOs) and declares a Linux runner skips the step there.
2114
+ // Manifests with no Linux runner in that matrix render the step unchanged.
2115
+ const skipOnLinux = lane === "ci" && manifest.profile === "rust-hybrid" && manifest.ciAllOs === true
2116
+ && manifest.matrix.os.some((runner) => /^(ubuntu|linux)/i.test(runner));
2117
+ const linuxGuard = skipOnLinux ? " if: ${{ runner.os != 'Linux' }}\n" : "";
2118
+ return `\n - name: RightKit ownership (protected registry roots)\n${linuxGuard} shell: bash\n run: test "$(git rev-parse HEAD)" = "${sourceRevision}" && ${ownershipCommand}`;
1633
2119
  }
1634
2120
 
1635
2121
  /**
@@ -1784,6 +2270,7 @@ export function buildRenderContext(manifest, repoPath, lane = "ci") {
1784
2270
  TEMPLATE_VERSION: manifest.templateVersion,
1785
2271
  RUST_CACHE_WORKSPACES: rustWorkspaces.map((workspace) => ` ${workspace} -> target`).join("\n"),
1786
2272
  RUST_REQUIRED_FOR_GATE: manifest.rustCache?.requiredForGate === true ? "true" : "false",
2273
+ DEV_QUALIFICATION_JOB: devQualificationJob(manifest, pm, artifactPrefix, cacheKeyLine),
1787
2274
  WINDOWS_SIGNING_JOB: windowsSigningJob(manifest, pm, artifactPrefix),
1788
2275
  MACOS_SIGNING_JOB: macosSigningJob(manifest, pm, artifactPrefix),
1789
2276
  RELEASE_CHAIN_JOBS: releaseChainJobs(manifest, pm, artifactPrefix),
@@ -1798,7 +2285,17 @@ export function buildRenderContext(manifest, repoPath, lane = "ci") {
1798
2285
  // sccache refuses CARGO_INCREMENTAL=1; incremental CI relies on the rust-cache target dir instead.
1799
2286
  CI_RUSTC_WRAPPER: manifest.ciIncremental === true ? '""' : "${{ steps.rust-changes.outputs.required == 'true' && 'sccache' || '' }}",
1800
2287
  CI_DERIVED_DATA_STEP: derivedDataStep(manifest),
1801
- CI_CANCEL_IN_PROGRESS: manifest.concurrency?.mainPushes === "queue" ? CI_CANCEL_MAIN_QUEUE_EXPRESSION : "true",
2288
+ // Default-branch pushes are never cancelled by the workflow-level group: the `supersede` job decides
2289
+ // (queue mode: nobody cancels them). PR and dispatch runs keep cancelling superseded runs.
2290
+ CI_CANCEL_IN_PROGRESS: CI_CANCEL_MAIN_QUEUE_EXPRESSION,
2291
+ // swift-check has no supersede job: it keeps cancelling superseded runs unless queue mode is set.
2292
+ CI_SWIFT_CANCEL_IN_PROGRESS: manifest.concurrency?.mainPushes === "queue" ? CI_CANCEL_MAIN_QUEUE_EXPRESSION : "true",
2293
+ CI_CONCURRENCY_COMMENT: manifest.concurrency?.mainPushes === "queue"
2294
+ ? `# concurrency.mainPushes queue, recorded exception to one CI run per repo: ${manifest.concurrency.reason.trim()}\n`
2295
+ : "",
2296
+ CI_CONCURRENCY_GROUP: manifest.concurrency?.mainPushes === "queue" ? CI_GROUP_PER_REF : CI_GROUP_SUPERSEDE,
2297
+ CI_SUPERSEDE_JOB: manifest.concurrency?.mainPushes === "queue" ? "" : supersedeJob(manifest),
2298
+ CI_JOB_CONCURRENCY: manifest.concurrency?.mainPushes === "queue" ? "" : ciJobConcurrency(),
1802
2299
  RUST_CACHE_KEY: cacheKeyLine ? `${cacheKeyLine}\n` : "",
1803
2300
  };
1804
2301
 
@@ -1810,12 +2307,27 @@ export function buildRenderContext(manifest, repoPath, lane = "ci") {
1810
2307
  // simply ABSENT from the context rather than present-with-undefined, so
1811
2308
  // render.mjs's own `Object.hasOwn` check does the right thing if a
1812
2309
  // template ever references a token this manifest didn't opt into.
2310
+ if (manifest.swift?.check) {
2311
+ const check = manifest.swift.check;
2312
+ Object.assign(context, {
2313
+ SWIFT_CHECK_RUNNER: check.runner,
2314
+ SWIFT_CHECK_XCODE_VERSION: check.xcodeVersion,
2315
+ SWIFT_CHECK_DIRECTORY: check.projectDirectory,
2316
+ SWIFT_CHECK_SPEC: check.spec,
2317
+ SWIFT_CHECK_PROJECT: check.project,
2318
+ SWIFT_CHECK_SCHEME: check.scheme,
2319
+ SWIFT_CHECK_XCODEGEN_VERSION: check.xcodegenVersion,
2320
+ });
2321
+ }
1813
2322
  if (manifest.gate) {
1814
2323
  context.GATE_PATH = manifest.gate.path;
1815
2324
  }
1816
2325
  if (manifest.regenerate) {
1817
2326
  context.REGENERATE_SCRIPT = manifest.regenerate.script;
1818
2327
  }
2328
+ if (manifest.signExisting && lane === "sign-existing") {
2329
+ context.SIGN_EXISTING_JOB = signExistingJob(manifest);
2330
+ }
1819
2331
  if (manifest.candidate) {
1820
2332
  context.CANDIDATE_BUILD_SCRIPT = manifest.candidate.buildScript;
1821
2333
  context.CANDIDATE_CHECK_SCRIPT = manifest.candidate.checkScript;