@rightkit/ci 0.2.49 → 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/manifest.mjs CHANGED
@@ -5,6 +5,7 @@
5
5
  import fs from "node:fs";
6
6
  import path from "node:path";
7
7
  import { validateCheckout } from "./checkout.mjs";
8
+ import { validateWorkflows } from "./workflows.mjs";
8
9
 
9
10
  export const MANIFEST_FILENAME = ".rightgit.json";
10
11
 
@@ -82,14 +83,51 @@ const TOP_LEVEL_KEYS = new Set([
82
83
  "checkout",
83
84
  "defaultBranch",
84
85
  "signExisting",
86
+ "workflows",
85
87
  ]);
86
88
  // Optional QA evidence upload (rust-hybrid ci only). qaEvidencePath is a safe
87
89
  // relative path under $RUNNER_TEMP; it renders as `${{ runner.temp }}/<path>`.
88
90
  const QA_EVIDENCE_DEFAULT_RETENTION_DAYS = 7;
89
91
  const QA_EVIDENCE_MAX_RETENTION_DAYS = 90;
90
92
  // Pinned to the same upload-artifact release the rust-hybrid release-candidate template uses.
91
- const UPLOAD_ARTIFACT_PIN = "actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4";
93
+ export const UPLOAD_ARTIFACT_PIN = "actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4";
92
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) : []);
93
131
  const RUST_WORKSPACE_PATH_RE = /^(?:\.|(?!.*\.\.)(?!.*\s)[A-Za-z0-9][A-Za-z0-9._/-]*)$/;
94
132
  const PACKAGE_SCRIPT_RE = /^[A-Za-z0-9][A-Za-z0-9:_-]*$/;
95
133
  const QA_SURFACE_SCRIPT_RE = /qa-native|qa-control|dev-native|dev-inspect|test-mode/i;
@@ -184,8 +222,10 @@ export function validateManifest(manifest) {
184
222
  if (lanes.some((lane) => lane !== "ci" && lane !== "release-candidate" && lane !== "regenerate" && lane !== "sign-existing") || !lanes.includes("ci")) {
185
223
  errors.push("profile 'rust-hybrid' requires lane 'ci' and supports optional lanes 'release-candidate', 'regenerate' and 'sign-existing'");
186
224
  }
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)) {
188
- 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);
189
229
  }
190
230
  } else {
191
231
  if (manifest.gate !== undefined) errors.push("gate is only valid for profile 'rust-hybrid'");
@@ -235,6 +275,7 @@ export function validateManifest(manifest) {
235
275
 
236
276
  if (manifest.concurrency !== undefined) validateConcurrency(manifest, lanes, errors);
237
277
  validateDevArtifact(manifest, profile, errors);
278
+ validateWorkflows(manifest, errors);
238
279
  validateRegenerate(manifest, lanes, errors);
239
280
  validateSignExisting(manifest, lanes, errors);
240
281
 
@@ -529,7 +570,7 @@ export function loadManifest(repoPath) {
529
570
  return { ok: true, manifest, errors: [], path: manifestPath };
530
571
  }
531
572
 
532
- function parsePackageManager(spec) {
573
+ export function parsePackageManager(spec) {
533
574
  const match = /^(pnpm|npm|yarn)@(\d+\.\d+\.\d+)$/.exec(spec);
534
575
  if (!match) throw new Error(`invalid packageManager spec: ${spec}`);
535
576
  const [, name, version] = match;
@@ -593,7 +634,7 @@ function signingMatrix(manifest, platform) {
593
634
  }
594
635
 
595
636
  const AZURE_LOGIN_SHA = "7ddb5af1ef8758cf1353cf3b42f940aee27ba21c"; // v3
596
- const DOWNLOAD_ARTIFACT_SHA = "d3f86a106a0bac45b974a628896c90dbdf5c8093"; // v4.3.0
637
+ export const DOWNLOAD_ARTIFACT_SHA = "d3f86a106a0bac45b974a628896c90dbdf5c8093"; // v4.3.0
597
638
  const UPLOAD_ARTIFACT_SHA = "ea165f8d65b6e75b540449e92b4886f43607fa02"; // v4
598
639
  const ARTIFACT_SIGNING_CLIENT_VERSION = "1.0.128";
599
640
  const ARTIFACT_SIGNING_CLIENT_SHA256 = "74BD7D27E6CE1051409C38D9B46BC8DF0400ECD643D51FFBF2AC00869061E40B";
@@ -845,7 +886,16 @@ const SUPERSEDE_HEREDOC_END = "RIGHT_GIT_SUPERSEDE_EOF";
845
886
  * `supersede` chose to keep: never two runs in progress. Every other event gets a group unique to the
846
887
  * run, so pull requests are not serialised against main.
847
888
  */
848
- 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
+ }
849
899
  return [
850
900
  " concurrency:",
851
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) }}",
@@ -1175,7 +1225,7 @@ function devPlatformJob({ manifest, id, label, runner, condition, lane, artifact
1175
1225
  swiftConfigure.length > 0
1176
1226
  ? " # QA gate job, not after it, and reaches only the private Swift package secret."
1177
1227
  : " # QA gate job, not after it, and never reaches a secret.",
1178
- " needs: [private-repo-guard]",
1228
+ " needs: [private-repo-guard, check]",
1179
1229
  ` if: \${{ ${condition} }}`,
1180
1230
  ` runs-on: ${runner}`,
1181
1231
  " permissions:",
@@ -2149,6 +2199,76 @@ export function lockfilePatchStep(manifest) {
2149
2199
  ].join("\n");
2150
2200
  }
2151
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
+
2152
2272
  /**
2153
2273
  * swift.privatePackages: configure step, placed directly before the first step
2154
2274
  * in each opted-in job that builds or tests project code (the ci job, the
@@ -2214,6 +2334,69 @@ export function swiftPrivatePackagesCleanupStep(manifest) {
2214
2334
  ].join("\n");
2215
2335
  }
2216
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
+
2217
2400
  /**
2218
2401
  * Optional QA evidence upload, rendered after the rust-hybrid gate step.
2219
2402
  * Returns "" when qaEvidencePath is unset, so the rendered workflow stays
@@ -2227,7 +2410,7 @@ export function qaEvidenceStep(manifest) {
2227
2410
  " if: always()",
2228
2411
  ` uses: ${UPLOAD_ARTIFACT_PIN}`,
2229
2412
  " with:",
2230
- " 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 }}`,
2231
2414
  ` path: \${{ runner.temp }}/${manifest.qaEvidencePath}`,
2232
2415
  ` retention-days: ${retentionDays}`,
2233
2416
  " if-no-files-found: ignore",
@@ -2253,6 +2436,8 @@ export function buildRenderContext(manifest, repoPath, lane = "ci") {
2253
2436
  ` os: ${yamlFlowStringList([ciOs])}`,
2254
2437
  ];
2255
2438
 
2439
+ const shardIds = gateShardIds(manifest);
2440
+ if (shardIds.length > 0) ciMatrixOs.push(` shard: ${yamlFlowStringList(shardIds)}`);
2256
2441
  const cacheKeyLine = rustCacheKeyLine(manifest, lane);
2257
2442
  const context = {
2258
2443
  OS_MATRIX: yamlFlowStringList(manifest.matrix.os),
@@ -2294,8 +2479,10 @@ export function buildRenderContext(manifest, repoPath, lane = "ci") {
2294
2479
  ? `# concurrency.mainPushes queue, recorded exception to one CI run per repo: ${manifest.concurrency.reason.trim()}\n`
2295
2480
  : "",
2296
2481
  CI_CONCURRENCY_GROUP: manifest.concurrency?.mainPushes === "queue" ? CI_GROUP_PER_REF : CI_GROUP_SUPERSEDE,
2482
+ CHECK_JOB: checkJob(manifest, lane),
2297
2483
  CI_SUPERSEDE_JOB: manifest.concurrency?.mainPushes === "queue" ? "" : supersedeJob(manifest),
2298
- CI_JOB_CONCURRENCY: manifest.concurrency?.mainPushes === "queue" ? "" : ciJobConcurrency(),
2484
+ CI_JOB_CONCURRENCY: manifest.concurrency?.mainPushes === "queue" ? "" : ciJobConcurrency(manifest),
2485
+ ...gateShardContext(manifest, pm, lane),
2299
2486
  RUST_CACHE_KEY: cacheKeyLine ? `${cacheKeyLine}\n` : "",
2300
2487
  };
2301
2488
 
@@ -121,6 +121,43 @@
121
121
  }
122
122
  }
123
123
  }
124
+ ,"workflows": {
125
+ "type": "object",
126
+ "minProperties": 1,
127
+ "maxProperties": 8,
128
+ "propertyNames": { "pattern": "^[a-z][a-z0-9-]{0,40}$" },
129
+ "description": "Named workflows rendered by code. kind custom: one build job with triggers (push/pull_request with paths, workflow_dispatch), steps, toolchain pins, a named artifact, per-workflow sparse checkout and concurrency. kind swift-host: swift test on Windows and macOS hosts for chosen packages. kind dispatch-matrix: workflow_dispatch inputs, a plan job emitting a matrix, per-item jobs and a collect job. Every action is pinned to a commit SHA, permissions are contents: read, and no step may read secrets. Validated in full by validateManifest (workflows.mjs).",
130
+ "additionalProperties": {
131
+ "type": "object",
132
+ "required": ["kind"],
133
+ "properties": {
134
+ "kind": { "enum": ["custom", "swift-host", "dispatch-matrix"] },
135
+ "file": { "type": "string", "pattern": "^[A-Za-z0-9][A-Za-z0-9._-]{0,60}\\.yml$" },
136
+ "on": { "type": "object", "propertyNames": { "enum": ["push", "pull_request", "workflow_dispatch"] } },
137
+ "concurrency": { "type": "object", "additionalProperties": false, "required": ["group"], "properties": { "group": { "type": "string", "pattern": "^[A-Za-z0-9][A-Za-z0-9._-]{0,60}$" }, "cancelInProgress": { "type": "boolean" } } },
138
+ "checkout": { "type": "object" },
139
+ "timeoutMinutes": { "type": "integer", "minimum": 1, "maximum": 360 },
140
+ "runsOn": { "oneOf": [{ "type": "string" }, { "type": "array", "items": { "type": "string" } }] },
141
+ "os": { "type": "array", "items": { "type": "string" } },
142
+ "packages": { "type": "array", "items": { "type": "string" } },
143
+ "swiftArgs": { "type": "array", "items": { "type": "string" } },
144
+ "toolchain": {
145
+ "type": "object",
146
+ "additionalProperties": false,
147
+ "properties": {
148
+ "rust": { "type": "string", "pattern": "^(stable|beta|nightly|[0-9]+\\.[0-9]+(\\.[0-9]+)?)$" },
149
+ "swift": { "type": "object", "additionalProperties": false, "required": ["version", "sha256"], "properties": { "version": { "type": "string", "pattern": "^[0-9]+\\.[0-9]+(\\.[0-9]+)?$" }, "sha256": { "type": "string", "pattern": "^[0-9a-f]{64}$" } } }
150
+ }
151
+ },
152
+ "steps": { "type": "array", "items": { "type": "object", "required": ["shell", "run"], "additionalProperties": false, "properties": { "name": { "type": "string" }, "shell": { "enum": ["bash", "pwsh"] }, "workingDirectory": { "type": "string" }, "run": { "type": "string" } } } },
153
+ "artifact": { "type": "object", "required": ["name", "path"], "additionalProperties": false, "properties": { "name": { "type": "string" }, "path": { "type": "string" }, "retentionDays": { "type": "integer", "minimum": 1, "maximum": 90 }, "ifNoFilesFound": { "enum": ["error", "warn", "ignore"] }, "when": { "enum": ["success", "always"] } } },
154
+ "inputs": { "type": "object" },
155
+ "plan": { "type": "object" },
156
+ "jobs": { "type": "array" },
157
+ "collect": { "type": "object" }
158
+ }
159
+ }
160
+ }
124
161
  ,"swift": {
125
162
  "type": "object",
126
163
  "additionalProperties": false,
@@ -211,7 +248,15 @@
211
248
  },
212
249
  "gate": {
213
250
  "type": "object", "required": ["path"], "additionalProperties": false,
214
- "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
+ }
215
260
  },
216
261
  "qaEvidencePath": {
217
262
  "type": "string",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rightkit/ci",
3
- "version": "0.2.49",
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": {
@@ -30,7 +32,7 @@
30
32
  },
31
33
  "repository": {
32
34
  "type": "git",
33
- "url": "git+https://github.com/Orthic-Labs/rightkit.git",
35
+ "url": "git+https://github.com/bogusyogi/rightkit.git",
34
36
  "directory": "packages/ci"
35
37
  },
36
38
  "scripts": {
package/sync.mjs CHANGED
@@ -6,8 +6,9 @@ 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
+ import { renderWorkflows } from "./workflows.mjs";
11
12
  import { renderTemplate, MANAGED_MARKER } from "./render.mjs";
12
13
 
13
14
  const packageRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)));
@@ -30,9 +31,47 @@ function releaseChainDependencyError(repoPath, manifest) {
30
31
  return null;
31
32
  }
32
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
+
33
72
  /** Render every lane declared in the manifest. Returns { lane, filename, content }[]. */
34
73
  export function renderLanes(manifest, repoPath) {
35
- return manifest.lanes.map((lane) => {
74
+ const laneFiles = manifest.lanes.map((lane) => {
36
75
  const context = buildRenderContext(manifest, repoPath, lane);
37
76
  const filename = LANE_FILENAMES[lane];
38
77
  const templatePath = manifest.profile === "rust-hybrid"
@@ -41,6 +80,8 @@ export function renderLanes(manifest, repoPath) {
41
80
  const templateText = fs.readFileSync(templatePath, "utf8");
42
81
  return { lane, filename, content: applyCheckoutOptions(renderTemplate(templateText, context), manifest) };
43
82
  });
83
+ // manifest.workflows: named custom, swift-host and dispatch-matrix workflows (see workflows.mjs).
84
+ return [...laneFiles, ...renderWorkflows(manifest, repoPath)];
44
85
  }
45
86
 
46
87
  /** List files in <repo>/.github/workflows that carry the right-git managed marker. */
@@ -104,6 +145,12 @@ export async function planSync(repoPath, deps = {}, manifestOverride = null) {
104
145
  return { ok: false, stage: "dependency", errors: [dependencyError], changes: [] };
105
146
  }
106
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
+
107
154
  const rendered = renderLanes(loaded.manifest, repoPath);
108
155
  const wantedFilenames = new Set(rendered.map((r) => r.filename));
109
156
  const changes = [];
@@ -133,8 +180,8 @@ export async function planSync(repoPath, deps = {}, manifestOverride = null) {
133
180
 
134
181
  const conflicts = changes.filter((change) => change.action === "managed-conflict");
135
182
  return conflicts.length
136
- ? { ok: false, stage: "managed-conflict", errors: conflicts.map((change) => `${change.filename} is unmanaged`), changes }
137
- : { 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 };
138
185
  }
139
186
 
140
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:
@@ -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: