@rightkit/ci 0.3.0 → 0.3.2

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 CHANGED
@@ -21,6 +21,19 @@ Public-repository-only GitHub Actions workflow layer for Right Suite products. T
21
21
 
22
22
  `install` and `sync` refuse private, internal and unconfirmed-visibility repositories. There is no override flag.
23
23
 
24
+ ## RightKit check job (ci, qualification, package-smoke, release-candidate, swift-check, publish-npm)
25
+
26
+ Each lane that compiles or tests renders a `check` job right after `private-repo-guard`, and every other job of that workflow needs it, directly or through a job that does. Nothing builds or qualifies a tree the check refused (pipeline invariant P1, rightkit#833).
27
+
28
+ - **What it runs.** `actions/checkout` at depth 1 (`persist-credentials: false`), `setup-node` (first `matrix.node`), the package manager, a frozen install without lifecycle scripts (`pnpm install --frozen-lockfile --ignore-scripts`; `npm ci --ignore-scripts`; `yarn install --frozen-lockfile --ignore-scripts`), then `pnpm exec rightkit-gate check --commit HEAD`. Committed files only: no network after the install, no compile, no broker, no secret. The job runs where the workflow's guard runs, times out after 15 minutes and pins its actions like the other jobs of the same file (tags in the node lane files, commits in `swift-check` and the rust-hybrid files).
29
+ - **Dependencies.** It needs only `private-repo-guard`. `test` (node `ci`), `ci` (rust-hybrid), `qualification`, `clean-tarball`, `candidate`, `swift-check`, `publish-npm`, the release chain's `admission` and the parallel `dev-artifact-*` jobs list it in `needs`.
30
+ - **The repository must depend on `@rightkit/release` 0.6.5 or later**, the first release with `rightkit-gate check`. Sync the new render only after the app has bumped it, or every run fails at the last step. `right-git sync` and `right-git install` read the pin from `package.json` (`devDependencies`, else `dependencies`) whenever a lane that renders the check job is declared: an exact pin below 0.6.5 is refused at stage `dependency` and nothing is written; a range, a non-registry spec or no `@rightkit/release` dependency prints a `warn:` line to stderr and the sync goes on, because the install may still resolve a new enough version. (`candidate.releaseChain` keeps its own, stricter rule: a direct devDependency pinned to an exact published version.) The install is not filtered to `@rightkit/release`: `pnpm install --filter` selects workspace projects, and in a consumer `@rightkit/release` is a registry dependency, so the filter matches no project, installs nothing and exits 0. npm and yarn call `./node_modules/.bin/rightkit-gate` by path, because `npm exec` fetches an unknown name from the registry in CI.
31
+ - **A release-candidate checks the revision it builds** (`inputs.source_revision`, or the pushed commit in the node lane's tag push). Its checkout is the one shallow checkout among the jobs of an admitted revision: the check only reads the committed files of HEAD and never runs `right-release`, so it has no reachability to prove.
32
+ - **publish-npm checks the release tag it publishes.** The lane checks out `github.event.release.tag_name`, installs, rebuilds the tarball from source (`build-candidate.mjs`), runs `check-release.mjs` and publishes with `id-token: write`, so it builds and tests like the other lanes. Its `check` job checks out the same tag, has no permission beyond the workflow's `contents: read`, no environment and no secret, and the publish job needs it: a tag whose committed files the check refuses never reaches the OIDC token or the registry.
33
+ - **Stale lockfile.** The `ci` lane's check job prints the same lockfile patch as the ci job after a failed frozen install; with the check first, the ci job no longer runs when the lockfile is stale.
34
+ - **Lanes without it.** `regenerate` repairs derived files and lockfiles, which the check flags, so a red check must not block it. `sign-existing`, the `supersede` job and `regenerate` are admitted by `@rightkit/release` (`right-git-ci-only`) only in their exact rendered shape, `needs: [private-repo-guard]`. `publish-package-managers` builds and tests nothing: it installs, syntax-checks the committed Homebrew formula and opens a tap pull request, or submits a WinGet manifest, for a version that is already released. Workflows under the manifest's `workflows` block are unchanged.
35
+ - **Breaking render change.** Every `ci`, `qualification`, `package-smoke`, `release-candidate`, `swift-check` and `publish-npm` render changes (a new job and a `check` entry in `needs`); there is no manifest flag. `right-git drift` on a synced repository shows exactly that job, and the `needs` lines. The hash-pinned renders in `render.test.mjs` were taken again, and each is also kept against its previous hash with the job removed.
36
+
24
37
  ## Default branch
25
38
 
26
39
  `"defaultBranch": "master"` renders the `push` trigger of the `ci`, `qualification` and `package-smoke` lanes, and the rust-hybrid `release-candidate` admission check (`refs/heads/<branch>`), for a repository whose default branch is not `main`. Unset, it is `main` and output is byte-identical.
@@ -68,6 +81,10 @@ Set `"ciAllOs": true` to run the rust-hybrid `ci` gate on every `matrix.os` runn
68
81
 
69
82
  Omit the key, or set it to `false`, and the rendered `ci.yml` keeps one runner, preferring the first `windows-*` entry. `ciAllOs: true` is rejected for other profiles.
70
83
 
84
+ ## One door (rust-hybrid)
85
+
86
+ The `ci` job (and the `regenerate` lane's re-check) runs exactly one build step: `rightkit-gate --to compile` from the installed `@rightkit/release`. The gate runs class A first, then every compile, lint and test scan, on the runner's plain cargo (a CI runner has no broker). `gate.path` only names a file whose change counts as a Rust change; the repository's own script never runs. `gate.shards` and `gate.quick` are gone and are refused.
87
+
71
88
  ## Incremental CI and dev artifacts (rust-hybrid)
72
89
 
73
90
  Both keys are opt-in; unset, the rendered `ci.yml` is byte-identical.
@@ -97,7 +114,7 @@ Both keys are opt-in; unset, the rendered `ci.yml` is byte-identical.
97
114
  - The `dev-mac-sign` job uses the `release` environment, so that environment's protection rules (required reviewers, branch policy) apply. The job only exists for pushes to the default branch.
98
115
  - Install a mac dev build with `right-release install-app --dev --zip <file>` (Developer ID-signed, not notarized).
99
116
  - `devArtifact.macSignManifest` (with `macPayloadMetadata`) replaces `codesign --deep` on the `.app` with `right-release sign-dev-artifact`: each file in the repository-relative sign manifest (`{ "schema": 1, "entries": [{ "file": "Legion.app/Contents/MacOS/legion", "identifier": "com.example.legion" }] }`, paths relative to the extracted archive, nested code before its bundle) is signed with its fixed identifier, the archive's payload metadata (`macPayloadMetadata`, relative to the archive root) is verified before and refreshed after signing, and `sign-evidence.json` is uploaded beside the zip. The job then also checks out the repo and installs dependencies, so `@rightkit/release` 0.2.172 or later must be a dependency. Requires `mac: "sign"`; not combinable with `macEntitlements` (put per-file entitlements in the manifest) or `mac: "notarize"`. Unset keeps the `--deep` lane.
100
- - `devArtifact.parallel: true` moves each platform's build into its own job, `dev-artifact-mac` or `dev-artifact-windows`. Each runs beside the QA gate job instead of after it, needs only the private-repo guard, and compiles the dev app with `devArtifact.buildScript` (a package script name; required with `parallel`, rejected without it) before staging it. Parallel jobs run on their own platform runners, so they do not need `ciAllOs`. `mac: "sign"` still waits for the gate: `dev-mac-sign` needs `ci` and `dev-artifact-mac`. The trade-off: unsigned uploads no longer wait for the gate, so a failing gate can still leave `dev-windows-<sha>` or `dev-mac-unsigned-<sha>` behind. Unset or `false` keeps the staging inside the gate job.
117
+ - `devArtifact.parallel: true` moves each platform's build into its own job, `dev-artifact-mac` or `dev-artifact-windows`. Each runs beside the QA gate job instead of after it, needs only the private-repo guard and the check job, and compiles the dev app with `devArtifact.buildScript` (a package script name; required with `parallel`, rejected without it) before staging it. Parallel jobs run on their own platform runners, so they do not need `ciAllOs`. `mac: "sign"` still waits for the gate: `dev-mac-sign` needs `ci` and `dev-artifact-mac`. The trade-off: unsigned uploads no longer wait for the gate, so a failing gate can still leave `dev-windows-<sha>` or `dev-mac-unsigned-<sha>` behind. Unset or `false` keeps the staging inside the gate job.
101
118
  - The `~/Library/Developer/Xcode/DerivedData` cache helps only builds that use Xcode's default derived data location. A gate that passes its own `-derivedDataPath` writes outside that directory and gets nothing from the cache; use the default location, or cache the custom path in the gate.
102
119
 
103
120
  ## Sign an existing artifact (rust-hybrid, `sign-existing` lane)
package/cli/right-git.mjs CHANGED
@@ -32,20 +32,28 @@ const BOOLEAN_ONLY_FLAGS = new Set(["all"]);
32
32
  const args = process.argv.slice(2);
33
33
  const first = args[0];
34
34
 
35
+ // process.exit() ends the process with whatever stdout and stderr still have queued: on a pipe that had not been read yet (`right-git sync
36
+ // --dry-run | tee log`, a CI log collector) the end of the diff and the result line were lost. A write of nothing completes only after
37
+ // everything written before it, so waiting for both streams puts all output out before the exit code is returned.
38
+ function exitAfterFlush(code) {
39
+ const flushed = (stream) => new Promise((resolve) => stream.write("", resolve));
40
+ return Promise.all([flushed(process.stdout), flushed(process.stderr)]).then(() => process.exit(code));
41
+ }
42
+
35
43
  if (!first || first === "-h" || first === "--help") {
36
44
  printHelp();
37
- process.exit(first ? 0 : 1);
45
+ await exitAfterFlush(first ? 0 : 1);
38
46
  } else if (first === "--version" || first === "-v") {
39
47
  const pkg = JSON.parse(fs.readFileSync(new URL("../package.json", import.meta.url), "utf8"));
40
48
  console.log(pkg.version);
41
- process.exit(0);
49
+ await exitAfterFlush(0);
42
50
  } else if (commands.has(first)) {
43
51
  const exitCode = await commands.get(first)(args.slice(1));
44
- process.exit(exitCode);
52
+ await exitAfterFlush(exitCode);
45
53
  } else {
46
54
  console.error(`right-git: unknown command: ${first}\n`);
47
55
  printHelp();
48
- process.exit(2);
56
+ await exitAfterFlush(2);
49
57
  }
50
58
 
51
59
  /** Split argv into positional args and --flag / --flag=value pairs. */
@@ -77,6 +85,12 @@ function printErrors(errors) {
77
85
  for (const error of errors || []) console.error(` ${error}`);
78
86
  }
79
87
 
88
+ // A sync or install warning (a @rightkit/release pin the rendered check job cannot be proved to have) is printed beside the result,
89
+ // to stderr like an error, and never changes the exit code.
90
+ function printWarnings(warnings) {
91
+ for (const warning of warnings || []) console.error(` warn: ${warning}`);
92
+ }
93
+
80
94
  // Advisory lines never change drift's exit code: warnings are settings to fix,
81
95
  // notes are checks that could not run here.
82
96
  function printAdvisories(result) {
@@ -104,8 +118,10 @@ async function runInstall(argv) {
104
118
  if (!result.ok) {
105
119
  console.error(`right-git install: failed at stage '${result.stage}'`);
106
120
  printErrors(result.errors);
121
+ printWarnings(result.plan?.warnings);
107
122
  return 1;
108
123
  }
124
+ printWarnings(result.plan.warnings);
109
125
  console.log(`right-git install: wrote ${result.manifestPath} and synced ${result.plan.changes.length} workflow file(s).`);
110
126
  return 0;
111
127
  }
@@ -121,8 +137,10 @@ async function runSync(argv) {
121
137
  if (!result.ok) {
122
138
  console.error(`right-git sync: failed at stage '${result.stage}'`);
123
139
  printErrors(result.errors);
140
+ printWarnings(result.warnings);
124
141
  return 1;
125
142
  }
143
+ printWarnings(result.warnings);
126
144
  const changed = result.changes.filter((c) => c.action !== "unchanged");
127
145
  console.log(changed.length === 0 ? "right-git sync: already up to date." : `right-git sync: ${changed.length} file(s) ${flags["dry-run"] ? "would change" : "changed"}.`);
128
146
  return 0;
package/install.mjs CHANGED
@@ -12,7 +12,7 @@ import { MANIFEST_FILENAME, validateManifest } from "./manifest.mjs";
12
12
  import { applyPlan, planSync } from "./sync.mjs";
13
13
 
14
14
  export const DEFAULT_MATRIX = { os: ["ubuntu-latest", "macos-latest", "windows-latest"], node: ["22.13", "24"] };
15
- export const DEFAULT_PACKAGE_MANAGER = "pnpm@11.24.0";
15
+ export const DEFAULT_PACKAGE_MANAGER = "pnpm@11.25.0";
16
16
  export const DEFAULT_TEMPLATE_VERSION = "1.8.0";
17
17
 
18
18
  /**
package/manifest.mjs CHANGED
@@ -92,6 +92,10 @@ const QA_EVIDENCE_MAX_RETENTION_DAYS = 90;
92
92
  // Pinned to the same upload-artifact release the rust-hybrid release-candidate template uses.
93
93
  export const UPLOAD_ARTIFACT_PIN = "actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4";
94
94
  const GATE_PATH_RE = /^(?!.*\.\.)(?!.*\s)[A-Za-z0-9][A-Za-z0-9._/-]*$/;
95
+ // gate.path is the paths filter of the Rust-change detector only. The ci job runs the one door, `rightkit-gate --to compile`
96
+ // (class A, then every compile, lint and test scan), never the repository's own script; there are no shards or quick legs.
97
+ const GATE_KEYS = new Set(["path"]);
98
+ const gateShardIds = () => [];
95
99
  const RUST_WORKSPACE_PATH_RE = /^(?:\.|(?!.*\.\.)(?!.*\s)[A-Za-z0-9][A-Za-z0-9._/-]*)$/;
96
100
  const PACKAGE_SCRIPT_RE = /^[A-Za-z0-9][A-Za-z0-9:_-]*$/;
97
101
  const QA_SURFACE_SCRIPT_RE = /qa-native|qa-control|dev-native|dev-inspect|test-mode/i;
@@ -186,12 +190,12 @@ export function validateManifest(manifest) {
186
190
  if (lanes.some((lane) => lane !== "ci" && lane !== "release-candidate" && lane !== "regenerate" && lane !== "sign-existing") || !lanes.includes("ci")) {
187
191
  errors.push("profile 'rust-hybrid' requires lane 'ci' and supports optional lanes 'release-candidate', 'regenerate' and 'sign-existing'");
188
192
  }
189
- 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)) {
190
- errors.push("profile 'rust-hybrid' requires gate.path with a safe relative path");
193
+ if (!manifest.gate || typeof manifest.gate !== "object" || Array.isArray(manifest.gate) || Object.keys(manifest.gate).some((key) => !GATE_KEYS.has(key)) || typeof manifest.gate.path !== "string" || !GATE_PATH_RE.test(manifest.gate.path)) {
194
+ errors.push("profile 'rust-hybrid' requires gate.path with a safe relative path (gate keys: path; gate.shards and gate.quick are gone: the ci job runs the one door, rightkit-gate --to compile)");
191
195
  }
192
196
  } else {
193
197
  if (manifest.gate !== undefined) errors.push("gate is only valid for profile 'rust-hybrid'");
194
- if (lanes.some((lane) => RUST_HYBRID_ONLY_LANES.includes(lane))) errors.push("lane 'sign-existing' is only valid for profile 'rust-hybrid'");
198
+ if (lanes.some((lane) => RUST_HYBRID_ONLY_LANES.includes(lane))) errors.push(`lanes ${RUST_HYBRID_ONLY_LANES.map((lane) => `'${lane}'`).join(" and ")} are only valid for profile 'rust-hybrid'`);
195
199
  }
196
200
 
197
201
  validateCheckout(manifest.checkout, errors);
@@ -848,7 +852,16 @@ const SUPERSEDE_HEREDOC_END = "RIGHT_GIT_SUPERSEDE_EOF";
848
852
  * `supersede` chose to keep: never two runs in progress. Every other event gets a group unique to the
849
853
  * run, so pull requests are not serialised against main.
850
854
  */
851
- function ciJobConcurrency() {
855
+ function ciJobConcurrency(manifest = {}) {
856
+ // With gate.shards every leg is its own concurrency slot (the shard id joins os and node).
857
+ if (gateShardIds(manifest).length > 0) {
858
+ return [
859
+ " concurrency:",
860
+ " group: ${{ github.event_name == 'push' && github.ref_name == github.event.repository.default_branch && format('{0}-main-{1}-{2}-{3}', github.workflow, matrix.os, matrix.node, matrix.shard) || format('{0}-{1}-{2}-{3}-{4}-{5}', github.workflow, github.run_id, github.run_attempt, matrix.os, matrix.node, matrix.shard) }}",
861
+ " cancel-in-progress: false",
862
+ "",
863
+ ].join("\n");
864
+ }
852
865
  return [
853
866
  " concurrency:",
854
867
  " 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) }}",
@@ -1178,7 +1191,7 @@ function devPlatformJob({ manifest, id, label, runner, condition, lane, artifact
1178
1191
  swiftConfigure.length > 0
1179
1192
  ? " # QA gate job, not after it, and reaches only the private Swift package secret."
1180
1193
  : " # QA gate job, not after it, and never reaches a secret.",
1181
- " needs: [private-repo-guard]",
1194
+ " needs: [private-repo-guard, check]",
1182
1195
  ` if: \${{ ${condition} }}`,
1183
1196
  ` runs-on: ${runner}`,
1184
1197
  " permissions:",
@@ -2152,6 +2165,106 @@ export function lockfilePatchStep(manifest) {
2152
2165
  ].join("\n");
2153
2166
  }
2154
2167
 
2168
+ // Action pins of the check job follow the template it is rendered into, so one workflow never mixes two pin styles:
2169
+ // the node-profile lane templates pin by tag, swift-check and the rust-hybrid templates by commit.
2170
+ const CHECK_SETUP_NODE_SHA_PIN = "actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0";
2171
+ const CHECK_ACTION_PINS = Object.freeze({
2172
+ tag: Object.freeze({ checkout: "actions/checkout@v5", setupNode: "actions/setup-node@v5" }),
2173
+ swift: Object.freeze({ checkout: "actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2", setupNode: CHECK_SETUP_NODE_SHA_PIN }),
2174
+ sha: Object.freeze({ checkout: "actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1", setupNode: CHECK_SETUP_NODE_SHA_PIN }),
2175
+ });
2176
+ // Lanes whose jobs compile or test the repository and therefore sit behind the check job (rightkit#833, pipeline invariant P1).
2177
+ // `publish-npm` is one of them: it checks out the release tag, installs, rebuilds the tarball from source (build-candidate.mjs),
2178
+ // runs check-release.mjs and only then publishes, so the check runs on the tag's commit before any of that. The others render
2179
+ // without it: `regenerate` exists to repair what the check flags (derived files, lockfiles), `sign-existing` and `supersede`
2180
+ // are admitted by @rightkit/release only in their exact rendered shape (`needs: [private-repo-guard]`), and
2181
+ // `publish-package-managers` builds and tests nothing (it installs, syntax-checks the committed formula and opens a tap pull
2182
+ // request, or submits a WinGet manifest, for a version that is already released).
2183
+ // Class A's scan tools, the same pins RightKit's own CI uses: the check is class A in full (cargo-deny, cargo-audit, actionlint),
2184
+ // and a missing tool fails the check rather than skipping the scan.
2185
+ const CLASS_A_TOOL_STEPS = Object.freeze([
2186
+ " - name: Install the pinned class A scan tools",
2187
+ " uses: taiki-e/install-action@8cca0918f8471c33515202b73f56ab27f2bed283 # v2.87.29",
2188
+ " with:",
2189
+ " tool: cargo-deny@0.20.2,cargo-audit@0.22.2,shellcheck@0.11.0",
2190
+ " - name: Install the pinned workflow linter",
2191
+ " shell: bash",
2192
+ " env:",
2193
+ " ACTIONLINT_VERSION: \"1.7.12\"",
2194
+ " run: |",
2195
+ " set -euo pipefail",
2196
+ " case \"$RUNNER_OS-$RUNNER_ARCH\" in",
2197
+ " Linux-X64) asset=linux_amd64.tar.gz; sum=8aca8db96f1b94770f1b0d72b6dddcb1ebb8123cb3712530b08cc387b349a3d8 ;;",
2198
+ " macOS-ARM64) asset=darwin_arm64.tar.gz; sum=aba9ced2dee8d27fecca3dc7feb1a7f9a52caefa1eb46f3271ea66b6e0e6953f ;;",
2199
+ " macOS-X64) asset=darwin_amd64.tar.gz; sum=5b44c3bc2255115c9b69e30efc0fecdf498fdb63c5d58e17084fd5f16324c644 ;;",
2200
+ " Windows-X64) asset=windows_amd64.zip; sum=6e7241b51e6817ea6a047693d8e6fed13b31819c9a0dd6c5a726e1592d22f6e9 ;;",
2201
+ " *) echo \"::error::no pinned actionlint for $RUNNER_OS-$RUNNER_ARCH\"; exit 1 ;;",
2202
+ " esac",
2203
+ " archive=\"$RUNNER_TEMP/actionlint-$asset\"",
2204
+ " curl --fail --silent --show-error --location --output \"$archive\" \"https://github.com/rhysd/actionlint/releases/download/v$ACTIONLINT_VERSION/actionlint_\"\"$ACTIONLINT_VERSION\"\"_$asset\"",
2205
+ " actual=\"$( (sha256sum \"$archive\" 2>/dev/null || shasum -a 256 \"$archive\") | cut -d' ' -f1)\"",
2206
+ " [ \"$actual\" = \"$sum\" ] || { echo \"::error::actionlint archive checksum mismatch\"; exit 1; }",
2207
+ " mkdir -p \"$RUNNER_TEMP/actionlint-bin\"",
2208
+ " case \"$asset\" in *.zip) unzip -o -q \"$archive\" actionlint.exe -d \"$RUNNER_TEMP/actionlint-bin\" ;; *) tar -xzf \"$archive\" -C \"$RUNNER_TEMP/actionlint-bin\" actionlint ;; esac",
2209
+ " echo \"$RUNNER_TEMP/actionlint-bin\" >> \"$GITHUB_PATH\"",
2210
+ ]);
2211
+
2212
+ export const CHECK_JOB_LANES = Object.freeze(["ci", "qualification", "package-smoke", "release-candidate", "swift-check", "publish-npm"]);
2213
+
2214
+ /**
2215
+ * The RightKit check job: the first job of every lane that compiles or tests, so nothing builds or qualifies a tree the
2216
+ * check refused. It needs only the private-repo guard; every other job of the workflow needs it (directly in `needs`, or
2217
+ * through a job that does). It installs the repository's own dependencies without running their scripts, then runs
2218
+ * `rightkit-gate check --commit HEAD` from the installed @rightkit/release (committed files only: no network, compile or
2219
+ * broker), so the repository must depend on a @rightkit/release that has the command. The install is not filtered to
2220
+ * @rightkit/release: `pnpm install --filter` selects workspace projects, and in a consumer @rightkit/release is a registry
2221
+ * dependency, so the filter matches nothing, installs nothing and exits 0. npm and yarn call the bin by its path because
2222
+ * `npm exec` fetches an unknown name from the registry in CI. A release-candidate checks the revision it builds, and
2223
+ * publish-npm checks the release tag it builds and publishes. Returns "" for lanes outside CHECK_JOB_LANES; otherwise the
2224
+ * job text, ending with a newline.
2225
+ */
2226
+ export function checkJob(manifest, lane = "ci") {
2227
+ if (!CHECK_JOB_LANES.includes(lane)) return "";
2228
+ const pm = parsePackageManager(manifest.packageManager);
2229
+ const rustHybrid = manifest.profile === "rust-hybrid";
2230
+ const pins = rustHybrid ? CHECK_ACTION_PINS.sha : lane === "swift-check" ? CHECK_ACTION_PINS.swift : CHECK_ACTION_PINS.tag;
2231
+ // The runner of the template's own guard job: the check reads files and needs no platform.
2232
+ const runner = rustHybrid || lane === "swift-check" ? "ubuntu-24.04" : "ubuntu-latest";
2233
+ // The revision the lane builds: a release-candidate's dispatched (or pushed) commit, the release tag publish-npm publishes.
2234
+ const ref = lane === "publish-npm" ? "${{ github.event.release.tag_name }}"
2235
+ : lane !== "release-candidate" ? null
2236
+ : rustHybrid ? "${{ inputs.source_revision }}" : "${{ inputs.source_revision || github.sha }}";
2237
+ // The same frozen install every other job runs (pm.installCommand), without lifecycle scripts; `--ignore-scripts` is a flag of
2238
+ // `pnpm install`, `npm ci` and `yarn install` alike. Only the gate invocation differs per manager.
2239
+ const install = `${pm.installCommand} --ignore-scripts`;
2240
+ const gate = { pnpm: "pnpm exec rightkit-gate", npm: "./node_modules/.bin/rightkit-gate", yarn: "./node_modules/.bin/rightkit-gate" }[pm.name];
2241
+ // The ci job prints the stale-lockfile patch after a failed frozen install; with check first it would never run, so check prints it.
2242
+ const lockfilePatch = lane === "ci" ? lockfilePatchStep(manifest) : "";
2243
+ return [
2244
+ " check:",
2245
+ " # RightKit check: class A over committed files only, no compile; every finding in one run. Every other job needs it.",
2246
+ " needs: [private-repo-guard]",
2247
+ ` runs-on: ${runner}`,
2248
+ " timeout-minutes: 15",
2249
+ " steps:",
2250
+ ` - uses: ${pins.checkout}`,
2251
+ " with:",
2252
+ ...(ref ? [` ref: ${ref}`] : []),
2253
+ " fetch-depth: 1",
2254
+ " persist-credentials: false",
2255
+ ` - uses: ${pins.setupNode}`,
2256
+ " with:",
2257
+ ` node-version: ${JSON.stringify(String(manifest.matrix.node[0]))}`,
2258
+ " package-manager-cache: false",
2259
+ ...(pm.setup ? [pm.setup] : []),
2260
+ ` - run: ${install}`,
2261
+ ...(lockfilePatch ? lockfilePatch.slice(1).split("\n") : []),
2262
+ ...CLASS_A_TOOL_STEPS,
2263
+ ` - run: ${gate} check --commit HEAD`,
2264
+ "",
2265
+ ].join("\n");
2266
+ }
2267
+
2155
2268
  /**
2156
2269
  * swift.privatePackages: configure step, placed directly before the first step
2157
2270
  * in each opted-in job that builds or tests project code (the ci job, the
@@ -2217,6 +2330,12 @@ export function swiftPrivatePackagesCleanupStep(manifest) {
2217
2330
  ].join("\n");
2218
2331
  }
2219
2332
 
2333
+ /** The ci job's needs and its one door step (rightkit-gate --to compile), run by the repository's package manager. */
2334
+ function gateShardContext(manifest, pm) {
2335
+ const door = { pnpm: "pnpm exec rightkit-gate", npm: "./node_modules/.bin/rightkit-gate", yarn: "./node_modules/.bin/rightkit-gate" }[pm.name];
2336
+ return { CI_NEEDS: "[private-repo-guard, check]", CI_SHARD_KEY: "", GATE_DOOR: `${door} --to compile`, CI_QUICK_JOB: "", CI_SUMMARY_JOB: "" };
2337
+ }
2338
+
2220
2339
  /**
2221
2340
  * Optional QA evidence upload, rendered after the rust-hybrid gate step.
2222
2341
  * Returns "" when qaEvidencePath is unset, so the rendered workflow stays
@@ -2230,7 +2349,7 @@ export function qaEvidenceStep(manifest) {
2230
2349
  " if: always()",
2231
2350
  ` uses: ${UPLOAD_ARTIFACT_PIN}`,
2232
2351
  " with:",
2233
- " name: qa-evidence-${{ matrix.os || runner.os }}-${{ github.run_attempt }}",
2352
+ ` name: qa-evidence-\${{ matrix.os || runner.os }}${gateShardIds(manifest).length > 0 ? "-${{ matrix.shard }}" : ""}-\${{ github.run_attempt }}`,
2234
2353
  ` path: \${{ runner.temp }}/${manifest.qaEvidencePath}`,
2235
2354
  ` retention-days: ${retentionDays}`,
2236
2355
  " if-no-files-found: ignore",
@@ -2256,6 +2375,8 @@ export function buildRenderContext(manifest, repoPath, lane = "ci") {
2256
2375
  ` os: ${yamlFlowStringList([ciOs])}`,
2257
2376
  ];
2258
2377
 
2378
+ const shardIds = gateShardIds(manifest);
2379
+ if (shardIds.length > 0) ciMatrixOs.push(` shard: ${yamlFlowStringList(shardIds)}`);
2259
2380
  const cacheKeyLine = rustCacheKeyLine(manifest, lane);
2260
2381
  const context = {
2261
2382
  OS_MATRIX: yamlFlowStringList(manifest.matrix.os),
@@ -2297,8 +2418,12 @@ export function buildRenderContext(manifest, repoPath, lane = "ci") {
2297
2418
  ? `# concurrency.mainPushes queue, recorded exception to one CI run per repo: ${manifest.concurrency.reason.trim()}\n`
2298
2419
  : "",
2299
2420
  CI_CONCURRENCY_GROUP: manifest.concurrency?.mainPushes === "queue" ? CI_GROUP_PER_REF : CI_GROUP_SUPERSEDE,
2421
+ CHECK_JOB: checkJob(manifest, lane),
2422
+ // The door's compile stage runs class A first on the job's own runner, so that runner needs class A's pinned tools too.
2423
+ CLASS_A_TOOLS_STEP: `\n${CLASS_A_TOOL_STEPS.join("\n")}`,
2300
2424
  CI_SUPERSEDE_JOB: manifest.concurrency?.mainPushes === "queue" ? "" : supersedeJob(manifest),
2301
- CI_JOB_CONCURRENCY: manifest.concurrency?.mainPushes === "queue" ? "" : ciJobConcurrency(),
2425
+ CI_JOB_CONCURRENCY: manifest.concurrency?.mainPushes === "queue" ? "" : ciJobConcurrency(manifest),
2426
+ ...gateShardContext(manifest, pm),
2302
2427
  RUST_CACHE_KEY: cacheKeyLine ? `${cacheKeyLine}\n` : "",
2303
2428
  };
2304
2429
 
@@ -248,7 +248,9 @@
248
248
  },
249
249
  "gate": {
250
250
  "type": "object", "required": ["path"], "additionalProperties": false,
251
- "properties": { "path": { "type": "string", "pattern": "^(?!.*\\.\\.)(?!.*\\s)[A-Za-z0-9][A-Za-z0-9._/-]*$" } }
251
+ "properties": {
252
+ "path": { "type": "string", "pattern": "^(?!.*\\.\\.)(?!.*\\s)[A-Za-z0-9][A-Za-z0-9._/-]*$" }
253
+ }
252
254
  },
253
255
  "qaEvidencePath": {
254
256
  "type": "string",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rightkit/ci",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "Public-repo-only GitHub Actions workflow layer: templates, visibility gate, sync/drift/adopt/uninstall for right-git.",
5
5
  "license": "MIT OR Apache-2.0",
6
6
  "type": "module",
@@ -21,7 +21,9 @@
21
21
  "policy",
22
22
  "templates",
23
23
  "*.mjs",
24
- "*.json"
24
+ "*.json",
25
+ "!*.test.mjs",
26
+ "!test-support.mjs"
25
27
  ],
26
28
  "sideEffects": false,
27
29
  "publishConfig": {
package/sync.mjs CHANGED
@@ -6,7 +6,7 @@ import fs from "node:fs";
6
6
  import path from "node:path";
7
7
  import { fileURLToPath } from "node:url";
8
8
  import { assertPublic } from "./policy/visibility-gate.mjs";
9
- import { loadManifest, LANE_FILENAMES, buildRenderContext } from "./manifest.mjs";
9
+ import { loadManifest, LANE_FILENAMES, buildRenderContext, CHECK_JOB_LANES } from "./manifest.mjs";
10
10
  import { applyCheckoutOptions } from "./checkout.mjs";
11
11
  import { renderWorkflows } from "./workflows.mjs";
12
12
  import { renderTemplate, MANAGED_MARKER } from "./render.mjs";
@@ -31,6 +31,44 @@ function releaseChainDependencyError(repoPath, manifest) {
31
31
  return null;
32
32
  }
33
33
 
34
+ // The first @rightkit/release that ships `rightkit-gate check`, the command the check job of every CHECK_JOB_LANES lane runs.
35
+ const GATE_CHECK_FIRST_VERSION = "0.6.5";
36
+ const versionParts = (version) => version.split(".").map(Number);
37
+ const versionBelow = (version, floor) => {
38
+ const [a, b] = [versionParts(version), versionParts(floor)];
39
+ for (let i = 0; i < 3; i += 1) if (a[i] !== b[i]) return a[i] < b[i];
40
+ return false;
41
+ };
42
+
43
+ /**
44
+ * What the repository's @rightkit/release means for the check job the manifest's lanes render: `{ error, warnings }`. The job runs
45
+ * `rightkit-gate check` from the installed package, so an exact pin below the version that ships it is refused (the rendered
46
+ * workflow would fail on its first job); a range, a non-registry spec or no dependency at all cannot be proved either way and only
47
+ * warns, since the install may still resolve a new enough version. No lane that renders a check job: nothing to say.
48
+ */
49
+ function checkJobDependency(repoPath, manifest) {
50
+ const lanes = (manifest.lanes ?? []).filter((lane) => CHECK_JOB_LANES.includes(lane));
51
+ if (lanes.length === 0) return { error: null, warnings: [] };
52
+ const rendered = `${lanes.length === 1 ? "lane" : "lanes"} ${lanes.join(", ")} ${lanes.length === 1 ? "renders" : "render"} the RightKit check job, which runs rightkit-gate check from the repository's @rightkit/release (${GATE_CHECK_FIRST_VERSION} is the first version that ships it)`;
53
+ let pkg;
54
+ try {
55
+ pkg = JSON.parse(fs.readFileSync(path.join(repoPath, "package.json"), "utf8"));
56
+ } catch {
57
+ return { error: null, warnings: [`${rendered}; package.json is not readable here, so the pin cannot be checked`] };
58
+ }
59
+ const spec = pkg.devDependencies?.["@rightkit/release"] ?? pkg.dependencies?.["@rightkit/release"];
60
+ if (typeof spec !== "string") {
61
+ return { error: null, warnings: [`${rendered}; package.json declares no @rightkit/release dependency, so the job has no gate to run`] };
62
+ }
63
+ if (!PUBLISHED_NPM_VERSION.test(spec)) {
64
+ return { error: null, warnings: [`${rendered}; @rightkit/release is ${JSON.stringify(spec)}, not an exact version, so it cannot be checked to be ${GATE_CHECK_FIRST_VERSION} or later (pin an exact version)`] };
65
+ }
66
+ if (versionBelow(spec, GATE_CHECK_FIRST_VERSION)) {
67
+ return { error: `${rendered}; @rightkit/release is pinned to ${spec}, which has no rightkit-gate check (pin ${GATE_CHECK_FIRST_VERSION} or later)`, warnings: [] };
68
+ }
69
+ return { error: null, warnings: [] };
70
+ }
71
+
34
72
  /** Render every lane declared in the manifest. Returns { lane, filename, content }[]. */
35
73
  export function renderLanes(manifest, repoPath) {
36
74
  const laneFiles = manifest.lanes.map((lane) => {
@@ -107,6 +145,12 @@ export async function planSync(repoPath, deps = {}, manifestOverride = null) {
107
145
  return { ok: false, stage: "dependency", errors: [dependencyError], changes: [] };
108
146
  }
109
147
 
148
+ const checkDependency = checkJobDependency(repoPath, loaded.manifest);
149
+ if (checkDependency.error) {
150
+ return { ok: false, stage: "dependency", errors: [checkDependency.error], warnings: [], changes: [] };
151
+ }
152
+ const warnings = checkDependency.warnings;
153
+
110
154
  const rendered = renderLanes(loaded.manifest, repoPath);
111
155
  const wantedFilenames = new Set(rendered.map((r) => r.filename));
112
156
  const changes = [];
@@ -136,8 +180,8 @@ export async function planSync(repoPath, deps = {}, manifestOverride = null) {
136
180
 
137
181
  const conflicts = changes.filter((change) => change.action === "managed-conflict");
138
182
  return conflicts.length
139
- ? { ok: false, stage: "managed-conflict", errors: conflicts.map((change) => `${change.filename} is unmanaged`), changes }
140
- : { ok: true, stage: "planned", errors: [], changes };
183
+ ? { ok: false, stage: "managed-conflict", errors: conflicts.map((change) => `${change.filename} is unmanaged`), warnings, changes }
184
+ : { ok: true, stage: "planned", errors: [], warnings, changes };
141
185
  }
142
186
 
143
187
  /** Apply a plan produced by planSync: write/update/remove files on disk. */
package/templates/ci.yml CHANGED
@@ -27,8 +27,8 @@ jobs:
27
27
  run: |
28
28
  echo "::error::right-git: repository is private; managed public-only workflows must not run here."
29
29
  exit 1
30
- ${CI_SUPERSEDE_JOB} test:
31
- needs: [private-repo-guard]
30
+ ${CHECK_JOB}${CI_SUPERSEDE_JOB} test:
31
+ needs: [private-repo-guard, check]
32
32
  strategy:
33
33
  fail-fast: false
34
34
  matrix:
@@ -19,8 +19,8 @@ jobs:
19
19
  run: |
20
20
  echo "::error::right-git: repository is private; managed public-only workflows must not run here."
21
21
  exit 1
22
- clean-tarball:
23
- needs: [private-repo-guard]
22
+ ${CHECK_JOB} clean-tarball:
23
+ needs: [private-repo-guard, check]
24
24
  strategy:
25
25
  fail-fast: false
26
26
  matrix:
@@ -17,8 +17,8 @@ jobs:
17
17
  - name: Refuse private repository
18
18
  if: ${{ github.event.repository.private }}
19
19
  run: exit 1
20
- ${CI_SUPERSEDE_JOB} ci:
21
- needs: [private-repo-guard]
20
+ ${CHECK_JOB}${CI_SUPERSEDE_JOB}${CI_QUICK_JOB} ci:
21
+ needs: ${CI_NEEDS}
22
22
  strategy:
23
23
  fail-fast: false
24
24
  matrix:
@@ -34,9 +34,9 @@ ${CI_JOB_CONCURRENCY} steps:
34
34
  uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
35
35
  with:
36
36
  path: ~/.right-git-last-green
37
- key: ${ARTIFACT_PREFIX}-last-green-${{ matrix.os }}-${{ matrix.node }}-${{ github.ref_name }}-${{ github.sha }}
37
+ key: ${ARTIFACT_PREFIX}-last-green-${{ matrix.os }}-${{ matrix.node }}${CI_SHARD_KEY}-${{ github.ref_name }}-${{ github.sha }}
38
38
  restore-keys: |
39
- ${ARTIFACT_PREFIX}-last-green-${{ matrix.os }}-${{ matrix.node }}-${{ github.ref_name }}-
39
+ ${ARTIFACT_PREFIX}-last-green-${{ matrix.os }}-${{ matrix.node }}${CI_SHARD_KEY}-${{ github.ref_name }}-
40
40
  - name: Detect Rust-affecting changes
41
41
  id: rust-changes
42
42
  shell: bash
@@ -101,8 +101,8 @@ ${RUST_CACHE_KEY} cache-workspace-crates: ${CI_CACHE_WORKSPACE_CRATES}
101
101
  - uses: Mozilla-Actions/sccache-action@fc920bf0ec8de6ee65d409111f7ec508035751ba # v0.0.11
102
102
  if: steps.rust-changes.outputs.required == 'true'
103
103
  with:
104
- version: "v0.16.0"${SWIFT_PRIVATE_CONFIGURE_STEP}
105
- - run: bash ./${GATE_PATH}
104
+ version: "v0.16.0"${CLASS_A_TOOLS_STEP}${SWIFT_PRIVATE_CONFIGURE_STEP}
105
+ - run: ${GATE_DOOR}
106
106
  env:
107
107
  RIGHT_GIT_RUST_CHANGED: ${{ steps.rust-changes.outputs.changed }}
108
108
  RIGHT_GIT_RUST_REQUIRED: ${{ steps.rust-changes.outputs.required }}
@@ -123,5 +123,5 @@ ${RUST_CACHE_KEY} cache-workspace-crates: ${CI_CACHE_WORKSPACE_CRATES}
123
123
  uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
124
124
  with:
125
125
  path: ~/.right-git-last-green
126
- key: ${ARTIFACT_PREFIX}-last-green-${{ matrix.os }}-${{ matrix.node }}-${{ github.ref_name }}-${{ github.sha }}-${{ github.run_id }}-${{ github.run_attempt }}
127
- ${QA_EVIDENCE_STEP}
126
+ key: ${ARTIFACT_PREFIX}-last-green-${{ matrix.os }}-${{ matrix.node }}${CI_SHARD_KEY}-${{ github.ref_name }}-${{ github.sha }}-${{ github.run_id }}-${{ github.run_attempt }}
127
+ ${QA_EVIDENCE_STEP}${CI_SUMMARY_JOB}
@@ -67,9 +67,19 @@ ${RUST_CACHE_KEY} cache-workspace-crates: ${CI_CACHE_WORKSPACE_CRATES}
67
67
  else
68
68
  printf 'changed=true\n' >> "$GITHUB_OUTPUT"
69
69
  fi
70
+ - name: Commit the regenerated tree locally (the door works on a commit)
71
+ if: steps.changes.outputs.changed == 'true'
72
+ shell: bash
73
+ run: |
74
+ set -euo pipefail
75
+ git config user.name "github-actions[bot]"
76
+ git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
77
+ git checkout -b "right-git/regenerate-${{ github.run_id }}-${{ github.run_attempt }}"
78
+ git add -A
79
+ git commit -m "Regenerate derived artifacts"${CLASS_A_TOOLS_STEP}
70
80
  - name: Gate the regenerated tree
71
81
  if: steps.changes.outputs.changed == 'true'
72
- run: bash ./${GATE_PATH}
82
+ run: ${GATE_DOOR}
73
83
  env:
74
84
  RIGHT_GIT_RUST_CHANGED: "true"
75
85
  RIGHT_GIT_RUST_REQUIRED: "true"
@@ -86,11 +96,6 @@ ${RUST_CACHE_KEY} cache-workspace-crates: ${CI_CACHE_WORKSPACE_CRATES}
86
96
  run: |
87
97
  set -euo pipefail
88
98
  branch="right-git/regenerate-${{ github.run_id }}-${{ github.run_attempt }}"
89
- git config user.name "github-actions[bot]"
90
- git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
91
- git checkout -b "$branch"
92
- git add -A
93
- git commit -m "Regenerate derived artifacts"
94
99
  git push origin "HEAD:refs/heads/$branch"
95
100
  gh pr create --base "$RIGHT_GIT_DEFAULT_BRANCH" --head "$branch" \
96
101
  --title "Regenerate derived artifacts" \
@@ -40,8 +40,8 @@ jobs:
40
40
  - name: Refuse private repository
41
41
  if: ${{ github.event.repository.private }}
42
42
  run: exit 1
43
- admission:
44
- needs: [private-repo-guard]
43
+ ${CHECK_JOB} admission:
44
+ needs: [private-repo-guard, check]
45
45
  # Ownership approval supports only macOS and Windows; Linux fails "unsupported platform: linux".
46
46
  runs-on: macos-15
47
47
  permissions:
@@ -22,8 +22,8 @@ jobs:
22
22
  run: |
23
23
  echo "::error::right-git: repository is private; managed public-only workflows must not run here."
24
24
  exit 1
25
- publish-npm:
26
- needs: [private-repo-guard]
25
+ ${CHECK_JOB} publish-npm:
26
+ needs: [private-repo-guard, check]
27
27
  runs-on: ubuntu-latest
28
28
  environment: release
29
29
  permissions:
@@ -18,8 +18,8 @@ jobs:
18
18
  run: |
19
19
  echo "::error::right-git: repository is private; managed public-only workflows must not run here."
20
20
  exit 1
21
- qualification:
22
- needs: [private-repo-guard]
21
+ ${CHECK_JOB} qualification:
22
+ needs: [private-repo-guard, check]
23
23
  runs-on: ubuntu-latest
24
24
  steps:
25
25
  - uses: actions/checkout@v5
@@ -25,8 +25,8 @@ jobs:
25
25
  run: |
26
26
  echo "::error::right-git: repository is private; managed public-only workflows must not run here."
27
27
  exit 1
28
- candidate:
29
- needs: [private-repo-guard]
28
+ ${CHECK_JOB} candidate:
29
+ needs: [private-repo-guard, check]
30
30
  strategy:
31
31
  fail-fast: false
32
32
  matrix:
@@ -19,8 +19,8 @@ jobs:
19
19
  run: |
20
20
  echo "::error::right-git: repository is private; managed public-only workflows must not run here."
21
21
  exit 1
22
- swift-check:
23
- needs: [private-repo-guard]
22
+ ${CHECK_JOB} swift-check:
23
+ needs: [private-repo-guard, check]
24
24
  runs-on: ${SWIFT_CHECK_RUNNER}
25
25
  timeout-minutes: 45
26
26
  env: