@rightkit/ci 0.3.0 → 0.3.1

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` and `quick` (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`. `ci-summary` still reports `ci` and `quick`; a failed check leaves both skipped, which it reports as failed.
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,33 @@ 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
+ ## Parallel gate shards (rust-hybrid)
85
+
86
+ A gate that runs everything in one step on each runner is as slow as the sum of its parts. `gate.shards` splits it. The repository compiles locally for a warm cache; this is about running GitHub qualification in parallel.
87
+
88
+ ```json
89
+ {
90
+ "profile": "rust-hybrid",
91
+ "ciAllOs": true,
92
+ "gate": {
93
+ "path": "scripts/gate.sh",
94
+ "quick": true,
95
+ "shards": [{ "id": "workspace" }, { "id": "linters" }, { "id": "rust-tools" }]
96
+ }
97
+ }
98
+ ```
99
+
100
+ - **Shards.** Each shard is one more `matrix.shard` value, so the gate runs once per shard per runner as `bash <path> --group <id>`. `fail-fast: false` still applies, and all legs share one Rust cache key, so one leg's build warms the others.
101
+ - **Per-leg state.** Each leg keeps its own last-green marker and its own QA evidence artifact (the shard id is in both names). On a default-branch push each leg is its own concurrency slot.
102
+ - **`quick: true`.** Adds a `quick` job (`bash <path> --quick`, on `ubuntu-24.04`, after the check job) for the fast deterministic checks. Every leg needs it, so a formatting or record error stops the run before any shard starts.
103
+ - **`ci-summary`.** Passes only when every leg passed (and `quick`, when set). Use it as the one required status check: matrix job names change with the shard list.
104
+ - **Validation.**
105
+ - 2 to 16 shards.
106
+ - Ids are lowercase letters, digits and `-`, at most 32 characters, and unique.
107
+ - `quick` needs `shards`.
108
+ - A `devArtifact` must use `parallel: true`, because a dev artifact staged inside the ci job would be built once per shard.
109
+ - **Without `shards`.** The rendered `ci.yml` is byte-identical.
110
+
71
111
  ## Incremental CI and dev artifacts (rust-hybrid)
72
112
 
73
113
  Both keys are opt-in; unset, the rendered `ci.yml` is byte-identical.
@@ -97,7 +137,7 @@ Both keys are opt-in; unset, the rendered `ci.yml` is byte-identical.
97
137
  - 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
138
  - Install a mac dev build with `right-release install-app --dev --zip <file>` (Developer ID-signed, not notarized).
99
139
  - `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.
140
+ - `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
141
  - 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
142
 
103
143
  ## 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,42 @@ 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
+ const GATE_KEYS = new Set(["path", "shards", "quick"]);
96
+ const GATE_SHARD_ID_RE = /^[a-z0-9][a-z0-9-]{0,31}$/;
97
+ const GATE_MAX_SHARDS = 16;
98
+
99
+ // gate.shards (rust-hybrid ci only): the gate runs once per shard per matrix.os runner, as
100
+ // `bash <gate.path> --group <id>`, on one shared Rust cache key, and a ci-summary job passes only when every
101
+ // leg passed. gate.quick: true adds a `quick` job (`bash <gate.path> --quick`) that every leg needs, for the
102
+ // fast deterministic checks. Steps that run inside the ci job once per runner (a non-parallel devArtifact)
103
+ // would run once per shard, so shards require devArtifact.parallel.
104
+ function validateGateShards(manifest, errors) {
105
+ const { shards, quick } = manifest.gate;
106
+ if (quick !== undefined && quick !== true) errors.push("gate.quick must be true when set");
107
+ if (shards === undefined) {
108
+ if (quick === true) errors.push("gate.quick requires gate.shards");
109
+ return;
110
+ }
111
+ if (!Array.isArray(shards) || shards.length < 2 || shards.length > GATE_MAX_SHARDS) {
112
+ errors.push(`gate.shards must list 2 to ${GATE_MAX_SHARDS} shards`);
113
+ return;
114
+ }
115
+ const seen = new Set();
116
+ for (const [index, shard] of shards.entries()) {
117
+ if (shard === null || typeof shard !== "object" || Array.isArray(shard) || Object.keys(shard).some((key) => key !== "id") || typeof shard.id !== "string" || !GATE_SHARD_ID_RE.test(shard.id)) {
118
+ errors.push(`gate.shards[${index}] must be { id } with a lowercase id of letters, digits and '-' (at most 32)`);
119
+ } else if (seen.has(shard.id)) {
120
+ errors.push(`gate.shards[${index}].id '${shard.id}' is listed twice`);
121
+ } else {
122
+ seen.add(shard.id);
123
+ }
124
+ }
125
+ if (manifest.devArtifact !== undefined && manifest.devArtifact?.parallel !== true) {
126
+ errors.push("gate.shards requires devArtifact.parallel: true (a dev artifact built inside the ci job would be built once per shard)");
127
+ }
128
+ }
129
+
130
+ const gateShardIds = (manifest) => (Array.isArray(manifest.gate?.shards) ? manifest.gate.shards.map((shard) => shard.id) : []);
95
131
  const RUST_WORKSPACE_PATH_RE = /^(?:\.|(?!.*\.\.)(?!.*\s)[A-Za-z0-9][A-Za-z0-9._/-]*)$/;
96
132
  const PACKAGE_SCRIPT_RE = /^[A-Za-z0-9][A-Za-z0-9:_-]*$/;
97
133
  const QA_SURFACE_SCRIPT_RE = /qa-native|qa-control|dev-native|dev-inspect|test-mode/i;
@@ -186,8 +222,10 @@ export function validateManifest(manifest) {
186
222
  if (lanes.some((lane) => lane !== "ci" && lane !== "release-candidate" && lane !== "regenerate" && lane !== "sign-existing") || !lanes.includes("ci")) {
187
223
  errors.push("profile 'rust-hybrid' requires lane 'ci' and supports optional lanes 'release-candidate', 'regenerate' and 'sign-existing'");
188
224
  }
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");
225
+ 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)) {
226
+ errors.push("profile 'rust-hybrid' requires gate.path with a safe relative path (gate keys: path, shards, quick)");
227
+ } else {
228
+ validateGateShards(manifest, errors);
191
229
  }
192
230
  } else {
193
231
  if (manifest.gate !== undefined) errors.push("gate is only valid for profile 'rust-hybrid'");
@@ -848,7 +886,16 @@ const SUPERSEDE_HEREDOC_END = "RIGHT_GIT_SUPERSEDE_EOF";
848
886
  * `supersede` chose to keep: never two runs in progress. Every other event gets a group unique to the
849
887
  * run, so pull requests are not serialised against main.
850
888
  */
851
- function ciJobConcurrency() {
889
+ function ciJobConcurrency(manifest = {}) {
890
+ // With gate.shards every leg is its own concurrency slot (the shard id joins os and node).
891
+ if (gateShardIds(manifest).length > 0) {
892
+ return [
893
+ " concurrency:",
894
+ " 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) }}",
895
+ " cancel-in-progress: false",
896
+ "",
897
+ ].join("\n");
898
+ }
852
899
  return [
853
900
  " concurrency:",
854
901
  " 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 +1225,7 @@ function devPlatformJob({ manifest, id, label, runner, condition, lane, artifact
1178
1225
  swiftConfigure.length > 0
1179
1226
  ? " # QA gate job, not after it, and reaches only the private Swift package secret."
1180
1227
  : " # QA gate job, not after it, and never reaches a secret.",
1181
- " needs: [private-repo-guard]",
1228
+ " needs: [private-repo-guard, check]",
1182
1229
  ` if: \${{ ${condition} }}`,
1183
1230
  ` runs-on: ${runner}`,
1184
1231
  " permissions:",
@@ -2152,6 +2199,76 @@ export function lockfilePatchStep(manifest) {
2152
2199
  ].join("\n");
2153
2200
  }
2154
2201
 
2202
+ // Action pins of the check job follow the template it is rendered into, so one workflow never mixes two pin styles:
2203
+ // the node-profile lane templates pin by tag, swift-check and the rust-hybrid templates by commit.
2204
+ const CHECK_SETUP_NODE_SHA_PIN = "actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0";
2205
+ const CHECK_ACTION_PINS = Object.freeze({
2206
+ tag: Object.freeze({ checkout: "actions/checkout@v5", setupNode: "actions/setup-node@v5" }),
2207
+ swift: Object.freeze({ checkout: "actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2", setupNode: CHECK_SETUP_NODE_SHA_PIN }),
2208
+ sha: Object.freeze({ checkout: "actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1", setupNode: CHECK_SETUP_NODE_SHA_PIN }),
2209
+ });
2210
+ // Lanes whose jobs compile or test the repository and therefore sit behind the check job (rightkit#833, pipeline invariant P1).
2211
+ // `publish-npm` is one of them: it checks out the release tag, installs, rebuilds the tarball from source (build-candidate.mjs),
2212
+ // runs check-release.mjs and only then publishes, so the check runs on the tag's commit before any of that. The others render
2213
+ // without it: `regenerate` exists to repair what the check flags (derived files, lockfiles), `sign-existing` and `supersede`
2214
+ // are admitted by @rightkit/release only in their exact rendered shape (`needs: [private-repo-guard]`), and
2215
+ // `publish-package-managers` builds and tests nothing (it installs, syntax-checks the committed formula and opens a tap pull
2216
+ // request, or submits a WinGet manifest, for a version that is already released).
2217
+ export const CHECK_JOB_LANES = Object.freeze(["ci", "qualification", "package-smoke", "release-candidate", "swift-check", "publish-npm"]);
2218
+
2219
+ /**
2220
+ * The RightKit check job: the first job of every lane that compiles or tests, so nothing builds or qualifies a tree the
2221
+ * check refused. It needs only the private-repo guard; every other job of the workflow needs it (directly in `needs`, or
2222
+ * through a job that does). It installs the repository's own dependencies without running their scripts, then runs
2223
+ * `rightkit-gate check --commit HEAD` from the installed @rightkit/release (committed files only: no network, compile or
2224
+ * broker), so the repository must depend on a @rightkit/release that has the command. The install is not filtered to
2225
+ * @rightkit/release: `pnpm install --filter` selects workspace projects, and in a consumer @rightkit/release is a registry
2226
+ * dependency, so the filter matches nothing, installs nothing and exits 0. npm and yarn call the bin by its path because
2227
+ * `npm exec` fetches an unknown name from the registry in CI. A release-candidate checks the revision it builds, and
2228
+ * publish-npm checks the release tag it builds and publishes. Returns "" for lanes outside CHECK_JOB_LANES; otherwise the
2229
+ * job text, ending with a newline.
2230
+ */
2231
+ export function checkJob(manifest, lane = "ci") {
2232
+ if (!CHECK_JOB_LANES.includes(lane)) return "";
2233
+ const pm = parsePackageManager(manifest.packageManager);
2234
+ const rustHybrid = manifest.profile === "rust-hybrid";
2235
+ const pins = rustHybrid ? CHECK_ACTION_PINS.sha : lane === "swift-check" ? CHECK_ACTION_PINS.swift : CHECK_ACTION_PINS.tag;
2236
+ // The runner of the template's own guard job: the check reads files and needs no platform.
2237
+ const runner = rustHybrid || lane === "swift-check" ? "ubuntu-24.04" : "ubuntu-latest";
2238
+ // The revision the lane builds: a release-candidate's dispatched (or pushed) commit, the release tag publish-npm publishes.
2239
+ const ref = lane === "publish-npm" ? "${{ github.event.release.tag_name }}"
2240
+ : lane !== "release-candidate" ? null
2241
+ : rustHybrid ? "${{ inputs.source_revision }}" : "${{ inputs.source_revision || github.sha }}";
2242
+ // The same frozen install every other job runs (pm.installCommand), without lifecycle scripts; `--ignore-scripts` is a flag of
2243
+ // `pnpm install`, `npm ci` and `yarn install` alike. Only the gate invocation differs per manager.
2244
+ const install = `${pm.installCommand} --ignore-scripts`;
2245
+ const gate = { pnpm: "pnpm exec rightkit-gate", npm: "./node_modules/.bin/rightkit-gate", yarn: "./node_modules/.bin/rightkit-gate" }[pm.name];
2246
+ // The ci job prints the stale-lockfile patch after a failed frozen install; with check first it would never run, so check prints it.
2247
+ const lockfilePatch = lane === "ci" ? lockfilePatchStep(manifest) : "";
2248
+ return [
2249
+ " check:",
2250
+ " # RightKit check: committed files only, no compile; every finding in one run. Every other job needs it.",
2251
+ " needs: [private-repo-guard]",
2252
+ ` runs-on: ${runner}`,
2253
+ " timeout-minutes: 15",
2254
+ " steps:",
2255
+ ` - uses: ${pins.checkout}`,
2256
+ " with:",
2257
+ ...(ref ? [` ref: ${ref}`] : []),
2258
+ " fetch-depth: 1",
2259
+ " persist-credentials: false",
2260
+ ` - uses: ${pins.setupNode}`,
2261
+ " with:",
2262
+ ` node-version: ${JSON.stringify(String(manifest.matrix.node[0]))}`,
2263
+ " package-manager-cache: false",
2264
+ ...(pm.setup ? [pm.setup] : []),
2265
+ ` - run: ${install}`,
2266
+ ...(lockfilePatch ? lockfilePatch.slice(1).split("\n") : []),
2267
+ ` - run: ${gate} check --commit HEAD`,
2268
+ "",
2269
+ ].join("\n");
2270
+ }
2271
+
2155
2272
  /**
2156
2273
  * swift.privatePackages: configure step, placed directly before the first step
2157
2274
  * in each opted-in job that builds or tests project code (the ci job, the
@@ -2217,6 +2334,69 @@ export function swiftPrivatePackagesCleanupStep(manifest) {
2217
2334
  ].join("\n");
2218
2335
  }
2219
2336
 
2337
+ /**
2338
+ * gate.shards / gate.quick render values. Without shards the values are the text the template held before the
2339
+ * placeholders existed, plus the `check` job every ci-lane job now needs (see checkJob).
2340
+ */
2341
+ function gateShardContext(manifest, pm, lane) {
2342
+ const shardIds = gateShardIds(manifest);
2343
+ if (lane !== "ci" || shardIds.length === 0) {
2344
+ return { CI_NEEDS: "[private-repo-guard, check]", CI_SHARD_KEY: "", GATE_ARGS: "", CI_QUICK_JOB: "", CI_SUMMARY_JOB: "" };
2345
+ }
2346
+ const quick = manifest.gate.quick === true;
2347
+ const quickJob = quick ? [
2348
+ " quick:",
2349
+ " # gate.quick: the fast deterministic checks, before any gate shard starts.",
2350
+ " needs: [private-repo-guard, check]",
2351
+ " runs-on: ubuntu-24.04",
2352
+ " timeout-minutes: 20",
2353
+ " steps:",
2354
+ " - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1",
2355
+ " with:",
2356
+ " fetch-depth: 0",
2357
+ " - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0",
2358
+ " with:",
2359
+ ` node-version: ${JSON.stringify(String(manifest.matrix.node[0]))}`,
2360
+ " package-manager-cache: false",
2361
+ ...(pm.setup ? [pm.setup] : []),
2362
+ ` - run: ${pm.installCommand}`,
2363
+ " - uses: dtolnay/rust-toolchain@f8be11a05b1d4f3fcebe6410cc16743212b999b0",
2364
+ " with:",
2365
+ " components: rustfmt, clippy",
2366
+ ` - run: bash ./${manifest.gate.path} --quick`,
2367
+ " env:",
2368
+ " RIGHT_GIT_GATE_QUICK: \"true\"",
2369
+ "",
2370
+ ].join("\n") : "";
2371
+ const needs = quick ? "[ci, quick]" : "[ci]";
2372
+ const summaryJob = [
2373
+ "",
2374
+ " ci-summary:",
2375
+ " # gate.shards: passes only when every shard passed on every runner" + (quick ? " and the quick checks passed." : "."),
2376
+ ` needs: ${needs}`,
2377
+ " if: ${{ always() }}",
2378
+ " runs-on: ubuntu-24.04",
2379
+ " timeout-minutes: 5",
2380
+ " steps:",
2381
+ " - name: Every gate shard passed on every runner",
2382
+ " env:",
2383
+ " CI_RESULT: ${{ needs.ci.result }}",
2384
+ ...(quick ? [" QUICK_RESULT: ${{ needs.quick.result }}"] : []),
2385
+ " run: |",
2386
+ " set -euo pipefail",
2387
+ " test \"$CI_RESULT\" = success",
2388
+ ...(quick ? [" test \"$QUICK_RESULT\" = success"] : []),
2389
+ "",
2390
+ ].join("\n");
2391
+ return {
2392
+ CI_NEEDS: quick ? "[private-repo-guard, check, quick]" : "[private-repo-guard, check]",
2393
+ CI_SHARD_KEY: "-${{ matrix.shard }}",
2394
+ GATE_ARGS: " --group ${{ matrix.shard }}",
2395
+ CI_QUICK_JOB: quickJob,
2396
+ CI_SUMMARY_JOB: summaryJob,
2397
+ };
2398
+ }
2399
+
2220
2400
  /**
2221
2401
  * Optional QA evidence upload, rendered after the rust-hybrid gate step.
2222
2402
  * Returns "" when qaEvidencePath is unset, so the rendered workflow stays
@@ -2230,7 +2410,7 @@ export function qaEvidenceStep(manifest) {
2230
2410
  " if: always()",
2231
2411
  ` uses: ${UPLOAD_ARTIFACT_PIN}`,
2232
2412
  " with:",
2233
- " name: qa-evidence-${{ matrix.os || runner.os }}-${{ github.run_attempt }}",
2413
+ ` name: qa-evidence-\${{ matrix.os || runner.os }}${gateShardIds(manifest).length > 0 ? "-${{ matrix.shard }}" : ""}-\${{ github.run_attempt }}`,
2234
2414
  ` path: \${{ runner.temp }}/${manifest.qaEvidencePath}`,
2235
2415
  ` retention-days: ${retentionDays}`,
2236
2416
  " if-no-files-found: ignore",
@@ -2256,6 +2436,8 @@ export function buildRenderContext(manifest, repoPath, lane = "ci") {
2256
2436
  ` os: ${yamlFlowStringList([ciOs])}`,
2257
2437
  ];
2258
2438
 
2439
+ const shardIds = gateShardIds(manifest);
2440
+ if (shardIds.length > 0) ciMatrixOs.push(` shard: ${yamlFlowStringList(shardIds)}`);
2259
2441
  const cacheKeyLine = rustCacheKeyLine(manifest, lane);
2260
2442
  const context = {
2261
2443
  OS_MATRIX: yamlFlowStringList(manifest.matrix.os),
@@ -2297,8 +2479,10 @@ export function buildRenderContext(manifest, repoPath, lane = "ci") {
2297
2479
  ? `# concurrency.mainPushes queue, recorded exception to one CI run per repo: ${manifest.concurrency.reason.trim()}\n`
2298
2480
  : "",
2299
2481
  CI_CONCURRENCY_GROUP: manifest.concurrency?.mainPushes === "queue" ? CI_GROUP_PER_REF : CI_GROUP_SUPERSEDE,
2482
+ CHECK_JOB: checkJob(manifest, lane),
2300
2483
  CI_SUPERSEDE_JOB: manifest.concurrency?.mainPushes === "queue" ? "" : supersedeJob(manifest),
2301
- CI_JOB_CONCURRENCY: manifest.concurrency?.mainPushes === "queue" ? "" : ciJobConcurrency(),
2484
+ CI_JOB_CONCURRENCY: manifest.concurrency?.mainPushes === "queue" ? "" : ciJobConcurrency(manifest),
2485
+ ...gateShardContext(manifest, pm, lane),
2302
2486
  RUST_CACHE_KEY: cacheKeyLine ? `${cacheKeyLine}\n` : "",
2303
2487
  };
2304
2488
 
@@ -248,7 +248,15 @@
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
+ "shards": {
254
+ "type": "array", "minItems": 2, "maxItems": 16,
255
+ "description": "rust-hybrid ci only. The gate runs once per shard per matrix.os runner as `bash <path> --group <id>` on one shared Rust cache; a ci-summary job passes only when every leg passed. Requires devArtifact.parallel when devArtifact is set.",
256
+ "items": { "type": "object", "required": ["id"], "additionalProperties": false, "properties": { "id": { "type": "string", "pattern": "^[a-z0-9][a-z0-9-]{0,31}$" } } }
257
+ },
258
+ "quick": { "const": true, "description": "Needs shards. A `quick` job runs `bash <path> --quick` (the fast deterministic checks) before any shard starts." }
259
+ }
252
260
  },
253
261
  "qaEvidencePath": {
254
262
  "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.1",
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
@@ -102,7 +102,7 @@ ${RUST_CACHE_KEY} cache-workspace-crates: ${CI_CACHE_WORKSPACE_CRATES}
102
102
  if: steps.rust-changes.outputs.required == 'true'
103
103
  with:
104
104
  version: "v0.16.0"${SWIFT_PRIVATE_CONFIGURE_STEP}
105
- - run: bash ./${GATE_PATH}
105
+ - run: bash ./${GATE_PATH}${GATE_ARGS}
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}
@@ -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: