@avi2dg/checks 0.41.1 → 0.42.0

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/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  Every release of `@avi2dg/checks`, newest first, written by the release from its conventional commits.
4
4
 
5
+ ## 0.42.0
6
+
7
+ Released 2026-10-14.
8
+
9
+ ### Features
10
+
11
+ - **delivery:** fail a setup-bun step whose Bun version drifts from the fleet pin [#156](https://github.com/avi2d/checks/pull/156)
12
+
5
13
  ## 0.41.1
6
14
 
7
15
  Released 2026-10-14.
package/README.md CHANGED
@@ -10,7 +10,7 @@ Each repository owns its workflows and native tool configs, as [Native settings]
10
10
  <!-- generated prerequisites: bun run build writes it from package.json, .bun-version and scripts/doc-blocks.ts -->
11
11
 
12
12
  - A git repository, whose history the range gates read.
13
- - Bun 1.4.2, which runs every bin.
13
+ - Bun 1.4.3, which runs every bin.
14
14
  - The peer dependencies, at the exact versions the kit pins:
15
15
  - `@effect/tsgo` 0.45.0
16
16
  - `@swc/core` 1.16.2
@@ -96,6 +96,8 @@ To consume the kit from a repository:
96
96
  "test": "checks-test"
97
97
  ```
98
98
 
99
+ 1. Write the Bun version [Before you begin](#before-you-begin) names to `.bun-version`, which [checks-ci-wiring](docs/gates/checks-ci-wiring.md#bun-version) holds every setup-bun step to.
100
+
99
101
  1. Run the scripts on every pull request in `.github/workflows/ci.yml`, fetching the whole history the range needs:
100
102
 
101
103
  ```yaml
@@ -109,6 +111,8 @@ To consume the kit from a repository:
109
111
  with:
110
112
  fetch-depth: 0
111
113
  - uses: oven-sh/setup-bun@v2
114
+ with:
115
+ bun-version-file: .bun-version
112
116
  - run: bun install --frozen-lockfile
113
117
  - run: bun run build
114
118
  - run: git diff --exit-code
@@ -115,6 +115,8 @@ jobs:
115
115
  steps:
116
116
  - uses: actions/checkout@v5
117
117
  - uses: oven-sh/setup-bun@v2
118
+ with:
119
+ bun-version-file: .bun-version
118
120
  - run: bun install --frozen-lockfile
119
121
  - run: ./node_modules/.bin/checks-advisories --all
120
122
  ```
@@ -49,9 +49,33 @@ In a private repository each mutation job carries exactly the labels `[self-host
49
49
  A public repository may keep `runs-on: ubuntu-latest` on every job, because a pull request from a fork runs its own code on the runner.
50
50
  The check knows a repository is private only from GitHub's event, so a run outside CI judges only the rules that hold in either.
51
51
 
52
+ ### Bun version
53
+
54
+ It also judges every step that uses `oven-sh/setup-bun`.
55
+ A step at ref `v2`, `v2.<minor>` or `v2.<minor>.<patch>` resolves its effective version in the order setup-bun v2 reads it.
56
+ A step at any other ref or at none fails, because the check knows only setup-bun v2's version resolution.
57
+ An input name matches in any case, as GitHub reads it.
58
+ The step input `with.bun-version` wins when it names a version, and an unquoted number counts as the text GitHub passes.
59
+ Else the file the step input `with.bun-version-file` names decides by its basename, when it yields a version.
60
+ A `package.json` file reads `packageManager` after `bun@`, and reads `engines.bun` only when `packageManager` is absent or holds no `bun@`.
61
+ A `.tool-versions` file reads the rest of the first line that starts with `bun`.
62
+ A `.bun-version` or `.bumrc` file reads the whole trimmed file.
63
+ Else the `package.json` at the workspace root reads the same way.
64
+ Else setup-bun installs latest.
65
+ A blank version counts as none.
66
+ A repository passes by writing the fleet version to `.bun-version` and naming that file in each step's `with.bun-version-file`.
67
+ The step fails the check when the version is missing or differs from the fleet bun version.
68
+ A range fails because it differs from the fleet version.
69
+ A version built from an expression fails because it cannot be shown equal before the run.
70
+ This rule skips a repository with no setup-bun step.
71
+ The fleet bun version equals the dotfiles mise pin.
72
+ A bump moves both together, so a kit release that moves the fleet version turns each consumer red until its pin follows.
73
+ Each refusal names the workflow file and line, the version found and where it was read, and the fleet version.
74
+
52
75
  ## What it reads
53
76
 
54
77
  The bin reads `.github/workflows/*.yml`, `*.yaml`, the `scripts` in `package.json` and the shell scripts those steps and scripts run from the working tree.
78
+ It reads each file a setup-bun step names for its version.
55
79
  It reads the target branch from `GITHUB_BASE_REF`, then from `refs/remotes/origin/HEAD` and then from the event file `GITHUB_EVENT_PATH` names.
56
80
  It reads whether the repository is private from `repository.private` in that event file.
57
81
  It parses the workflows with `Bun.YAML` without executing them.
@@ -65,7 +89,7 @@ It takes no arguments.
65
89
  | Code | Result |
66
90
  | --- | --- |
67
91
  | 0 | Every required command has a reachable step. |
68
- | 1 | A required command is missing or blocked, a job runs on the wrong runner, or a workflow names a missing workflow or job. |
92
+ | 1 | A required command is missing or blocked, a job runs on the wrong runner, a workflow names a missing workflow or job, or a setup-bun step drifts from the fleet bun version. |
69
93
  | 2 | A workflow or `package.json` cannot be decoded. |
70
94
 
71
95
  ## Sample output
@@ -67,6 +67,8 @@ jobs:
67
67
  steps:
68
68
  - uses: actions/checkout@v5
69
69
  - uses: oven-sh/setup-bun@v2
70
+ with:
71
+ bun-version-file: .bun-version
70
72
  - run: bun install --frozen-lockfile
71
73
  - run: bunx checks-flake --runs 10 --report flake-report.json
72
74
  - uses: actions/upload-artifact@v4
@@ -92,6 +92,8 @@ jobs:
92
92
  with:
93
93
  fetch-depth: 0
94
94
  - uses: oven-sh/setup-bun@v2
95
+ with:
96
+ bun-version-file: .bun-version
95
97
  - run: bun install --frozen-lockfile
96
98
  - run: bunx stryker run
97
99
  - run: |
@@ -69,6 +69,8 @@ jobs:
69
69
  - name: ref is a tag
70
70
  run: test "$GITHUB_REF_TYPE" = tag
71
71
  - uses: oven-sh/setup-bun@v2
72
+ with:
73
+ bun-version-file: .bun-version
72
74
  - run: bun install --frozen-lockfile
73
75
  - run: bun run build
74
76
  - run: git diff --exit-code
@@ -89,6 +91,8 @@ jobs:
89
91
  with:
90
92
  fetch-depth: 0
91
93
  - uses: oven-sh/setup-bun@v2
94
+ with:
95
+ bun-version-file: .bun-version
92
96
  - run: bun install --frozen-lockfile
93
97
  - name: extract release notes
94
98
  run: ./node_modules/.bin/checks-release-notes "${GITHUB_REF_NAME#v}" "$RUNNER_TEMP/release-notes.md"
@@ -120,6 +124,8 @@ jobs:
120
124
  - name: ref is a tag
121
125
  run: test "$GITHUB_REF_TYPE" = tag
122
126
  - uses: oven-sh/setup-bun@v2
127
+ with:
128
+ bun-version-file: .bun-version
123
129
  - run: bun install --frozen-lockfile
124
130
  - run: bun run build
125
131
  - run: git diff --exit-code
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@avi2dg/checks",
3
- "version": "0.41.1",
3
+ "version": "0.42.0",
4
4
  "description": "Deterministic checks shared across a set of TypeScript repositories",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -52,6 +52,7 @@
52
52
  "src/delivery/ci-wiring.ts",
53
53
  "src/delivery/shell-command.ts",
54
54
  "src/delivery/workflow-references.ts",
55
+ "src/delivery/bun-pin.ts",
55
56
  "src/delivery/mutation-job.ts",
56
57
  "src/delivery/secrets.ts",
57
58
  "src/delivery/gitleaks.ts",
@@ -0,0 +1,174 @@
1
+ import { Effect, FileSystem, Path, Schema } from "effect";
2
+ import { within } from "./mutation-job.ts";
3
+ import { isRecord, locate, workflowJobs, type Workflow } from "./workflow-references.ts";
4
+
5
+ export const FLEET_BUN_VERSION = "1.4.3";
6
+ const ROOT_MANIFEST = "package.json";
7
+
8
+ export type BunPinPolicy = {
9
+ readonly files: ReadonlyMap<string, string>;
10
+ readonly manifests: ReadonlyMap<string, unknown>;
11
+ };
12
+
13
+ export type BunPinFault = {
14
+ readonly location: string;
15
+ readonly fault: string;
16
+ };
17
+
18
+ const SETUP_BUN = /^oven-sh\/setup-bun(?:@(?<ref>.*))?$/i;
19
+ const V2_REF = /^v2(?:\.\d+){0,2}$/;
20
+
21
+ function setupBunRef(uses: unknown): string | undefined {
22
+ const match = typeof uses === "string" ? SETUP_BUN.exec(uses.trim()) : null;
23
+ return match === null ? undefined : (match.groups?.["ref"] ?? "");
24
+ }
25
+
26
+ function isExpression(value: string): boolean {
27
+ return value.includes("${{");
28
+ }
29
+
30
+ function baseName(name: string): string {
31
+ return name.slice(name.lastIndexOf("/") + 1);
32
+ }
33
+
34
+ function actionInput(step: Readonly<Record<string, unknown>>, name: string): string {
35
+ const inputs = isRecord(step["with"]) ? step["with"] : {};
36
+ const value = Object.entries(inputs).find(([key]) => key.toLowerCase() === name)?.[1];
37
+ return typeof value === "string" || typeof value === "number" || typeof value === "boolean" ? String(value).trim() : "";
38
+ }
39
+
40
+ function nonEmpty(version: string | undefined): string | undefined {
41
+ const trimmed = version?.trim();
42
+ return trimmed === "" ? undefined : trimmed;
43
+ }
44
+
45
+ function manifestBunVersion(manifest: unknown): string | undefined {
46
+ if (!isRecord(manifest)) return undefined;
47
+ const manager = manifest["packageManager"];
48
+ const engines = manifest["engines"];
49
+ const engine = isRecord(engines) ? engines["bun"] : undefined;
50
+ const version = manager === undefined || manager === null ? engine : typeof manager === "string" ? (manager.split("bun@")[1] ?? engine) : undefined;
51
+ return typeof version === "string" ? nonEmpty(version) : undefined;
52
+ }
53
+
54
+ const FILE_READERS = new Map<string, (text: string) => string | undefined>([
55
+ [".tool-versions", (text) => /^bun\s*(?<version>.*?)$/m.exec(text)?.groups?.["version"]],
56
+ [".bumrc", (text) => text],
57
+ [".bun-version", (text) => text],
58
+ ]);
59
+
60
+ function fileBunVersion(policy: BunPinPolicy, key: string): string | undefined {
61
+ if (baseName(key) === "package.json") return manifestBunVersion(policy.manifests.get(key));
62
+ const text = policy.files.get(key);
63
+ const read = FILE_READERS.get(baseName(key));
64
+ return text === undefined || read === undefined ? undefined : nonEmpty(read(text));
65
+ }
66
+
67
+ type BunPinRequest = {
68
+ readonly version: string | undefined;
69
+ readonly source: string;
70
+ readonly expression: string | undefined;
71
+ };
72
+
73
+ function rootRequest(policy: BunPinPolicy, consulted: string): BunPinRequest {
74
+ const version = manifestBunVersion(policy.manifests.get(ROOT_MANIFEST));
75
+ return { version, source: version === undefined ? consulted : ROOT_MANIFEST, expression: undefined };
76
+ }
77
+
78
+ function bunPinRequest(policy: BunPinPolicy, step: Readonly<Record<string, unknown>>): BunPinRequest {
79
+ const pinned = actionInput(step, "bun-version");
80
+ if (pinned !== "") {
81
+ return isExpression(pinned)
82
+ ? { version: undefined, source: "with.bun-version", expression: pinned }
83
+ : { version: pinned, source: "with.bun-version", expression: undefined };
84
+ }
85
+ const file = actionInput(step, "bun-version-file");
86
+ if (file === "") return rootRequest(policy, ROOT_MANIFEST);
87
+ const source = `with.bun-version-file ${file}`;
88
+ if (isExpression(file)) return { version: undefined, source, expression: file };
89
+ const key = within("", file);
90
+ const version = key === undefined ? undefined : fileBunVersion(policy, key);
91
+ return version === undefined ? rootRequest(policy, `${source} or ${ROOT_MANIFEST}`) : { version, source, expression: undefined };
92
+ }
93
+
94
+ function bunPinFault(policy: BunPinPolicy, step: Readonly<Record<string, unknown>>): string | undefined {
95
+ const request = bunPinRequest(policy, step);
96
+ if (request.expression !== undefined) {
97
+ return `requests bun ${request.expression} from ${request.source}, which cannot be shown equal to ${FLEET_BUN_VERSION} before the run`;
98
+ }
99
+ if (request.version === undefined) {
100
+ return `pins no bun version from ${request.source}, so setup-bun installs latest, want ${FLEET_BUN_VERSION}`;
101
+ }
102
+ return request.version === FLEET_BUN_VERSION ? undefined : `requests bun ${request.version} from ${request.source}, want ${FLEET_BUN_VERSION}`;
103
+ }
104
+
105
+ function unknownRefFault(ref: string): string {
106
+ return `uses oven-sh/setup-bun at ${ref === "" ? "no ref" : ref}, but the check knows only setup-bun v2's version resolution, so the step must use oven-sh/setup-bun@v2`;
107
+ }
108
+
109
+ export function findBunPinFaults(policy: BunPinPolicy, workflows: readonly Workflow[]): readonly BunPinFault[] {
110
+ return workflows.flatMap((workflow) => {
111
+ const at = locate(workflow.path, workflow.text.split("\n"));
112
+ return workflowJobs(workflow).flatMap(([id, job]) => {
113
+ const steps = Array.isArray(job["steps"]) ? job["steps"] : [];
114
+ return steps.flatMap((step: unknown, index: number) => {
115
+ if (!isRecord(step)) return [];
116
+ const ref = setupBunRef(step["uses"]);
117
+ if (ref === undefined) return [];
118
+ const fault = V2_REF.test(ref) ? bunPinFault(policy, step) : unknownRefFault(ref);
119
+ return fault === undefined ? [] : [{ location: at(["jobs", id, "steps", index, "uses"], String(step["uses"]), `job ${id} step ${index + 1}`), fault }];
120
+ });
121
+ });
122
+ });
123
+ }
124
+
125
+ export function formatBunPinReport(faults: readonly BunPinFault[]): string {
126
+ return [`ci-wiring: ${faults.length} setup-bun step(s) drift from the fleet bun version:`, ...faults.map(({ location, fault }) => ` ${location}: ${fault}`)].join("\n");
127
+ }
128
+
129
+ function versionFileKeys(job: Readonly<Record<string, unknown>>): readonly string[] {
130
+ const steps = Array.isArray(job["steps"]) ? job["steps"] : [];
131
+ const keys: string[] = [];
132
+ for (const step of steps) {
133
+ if (!isRecord(step) || !V2_REF.test(setupBunRef(step["uses"]) ?? "")) continue;
134
+ const file = actionInput(step, "bun-version-file");
135
+ if (file === "" || isExpression(file)) continue;
136
+ const key = within("", file);
137
+ if (key !== undefined) keys.push(key);
138
+ }
139
+ return keys;
140
+ }
141
+
142
+ function wantedBunPinFiles(workflows: readonly Workflow[]): ReadonlySet<string> {
143
+ const wanted = new Set<string>([ROOT_MANIFEST]);
144
+ for (const workflow of workflows) {
145
+ for (const [, job] of workflowJobs(workflow)) {
146
+ for (const key of versionFileKeys(job)) wanted.add(key);
147
+ }
148
+ }
149
+ return wanted;
150
+ }
151
+
152
+ const readJsonFile = Effect.fn("readJsonFile")(function* (file: string) {
153
+ return yield* (yield* FileSystem.FileSystem).readFileString(file).pipe(
154
+ Effect.flatMap(Schema.decodeUnknownEffect(Schema.fromJsonString(Schema.Unknown))),
155
+ Effect.orElseSucceed((): undefined => undefined),
156
+ );
157
+ });
158
+
159
+ export const readBunPinPolicy = Effect.fn("readBunPinPolicy")(function* (root: string, workflows: readonly Workflow[]) {
160
+ const path = yield* Path.Path;
161
+ const fs = yield* FileSystem.FileSystem;
162
+ const files = new Map<string, string>();
163
+ const manifests = new Map<string, unknown>();
164
+ for (const name of wantedBunPinFiles(workflows)) {
165
+ if (baseName(name) === "package.json") {
166
+ const parsed: unknown = yield* readJsonFile(path.join(root, name));
167
+ if (parsed !== undefined) manifests.set(name, parsed);
168
+ } else {
169
+ const text = yield* fs.readFileString(path.join(root, name)).pipe(Effect.orElseSucceed((): undefined => undefined));
170
+ if (text !== undefined) files.set(name, text);
171
+ }
172
+ }
173
+ return { files, manifests };
174
+ });
@@ -3,9 +3,13 @@ import { Config, Console, Effect, FileSystem, Path, Schema } from "effect";
3
3
  import { defaultBranch, git } from "../core/git.ts";
4
4
  import { runMain } from "../core/main.ts";
5
5
  import { ENTRY_POINT, KIT_GATES, type KitGate } from "../core/gates.ts";
6
+ import { findBunPinFaults, formatBunPinReport, readBunPinPolicy } from "./bun-pin.ts";
6
7
  import { readShellFiles, runsMutation, within, type Run } from "./mutation-job.ts";
7
8
  import { invokes, mentions, plainCommand, type Command } from "./shell-command.ts";
8
- import { findMissingWorkflows, formatMissingReport, isRecord, names, type Workflow } from "./workflow-references.ts";
9
+ import { findMissingWorkflows, formatMissingReport, isRecord, names, workflowJobs, type Workflow } from "./workflow-references.ts";
10
+
11
+ export { FLEET_BUN_VERSION, findBunPinFaults, formatBunPinReport } from "./bun-pin.ts";
12
+ export type { BunPinFault, BunPinPolicy } from "./bun-pin.ts";
9
13
 
10
14
  export type { Command };
11
15
 
@@ -297,11 +301,6 @@ function jobRuns(workflow: Workflow, job: Readonly<Record<string, unknown>>): re
297
301
  return steps.flatMap((step: unknown) => (isRecord(step) && typeof step["run"] === "string" ? [{ script: step["run"], dir: stepDirectory(step["working-directory"], dir) }] : []));
298
302
  }
299
303
 
300
- function workflowJobs(workflow: Workflow): readonly (readonly [string, Readonly<Record<string, unknown>>])[] {
301
- const jobs = isRecord(workflow.document) ? workflow.document["jobs"] : undefined;
302
- return isRecord(jobs) ? Object.entries(jobs).flatMap(([id, job]) => (isRecord(job) ? [[id, job] as const] : [])) : [];
303
- }
304
-
305
304
  export function findRunnerFaults(policy: RunnerPolicy, workflows: readonly Workflow[]): readonly RunnerFault[] {
306
305
  return workflows.flatMap((workflow) =>
307
306
  workflowJobs(workflow).flatMap(([id, job]) => {
@@ -378,7 +377,9 @@ const wiring = Effect.gen(function* () {
378
377
  const runs = workflows.flatMap((workflow) => workflowJobs(workflow).flatMap(([, job]) => jobRuns(workflow, job)));
379
378
  const faults = findRunnerFaults({ visibility: yield* readVisibility, scripts, files: yield* readShellFiles(root, scripts, runs) }, workflows);
380
379
  if (faults.length > 0) yield* Console.error(formatRunnerReport(faults));
381
- return gaps.length === 0 && faults.length === 0 && missing.length === 0;
380
+ const bunFaults = findBunPinFaults(yield* readBunPinPolicy(root, workflows), workflows);
381
+ if (bunFaults.length > 0) yield* Console.error(formatBunPinReport(bunFaults));
382
+ return gaps.length === 0 && faults.length === 0 && missing.length === 0 && bunFaults.length === 0;
382
383
  });
383
384
 
384
385
  if (import.meta.main) runMain("ci-wiring", wiring);
@@ -15,6 +15,11 @@ export function isRecord(value: unknown): value is Record<string, unknown> {
15
15
  return typeof value === "object" && value !== null && !Array.isArray(value);
16
16
  }
17
17
 
18
+ export function workflowJobs(workflow: Workflow): readonly (readonly [string, Readonly<Record<string, unknown>>])[] {
19
+ const jobs = isRecord(workflow.document) ? workflow.document["jobs"] : undefined;
20
+ return isRecord(jobs) ? Object.entries(jobs).flatMap(([id, job]) => (isRecord(job) ? [[id, job] as const] : [])) : [];
21
+ }
22
+
18
23
  export function names(value: unknown): readonly string[] | undefined {
19
24
  if (typeof value === "string") return [value];
20
25
  if (!Array.isArray(value)) return undefined;
@@ -108,7 +113,7 @@ function nodeAt(lines: readonly string[], keys: readonly Key[]): Node | undefine
108
113
  );
109
114
  }
110
115
 
111
- function locate(path: string, lines: readonly string[]): Locator {
116
+ export function locate(path: string, lines: readonly string[]): Locator {
112
117
  const used = new Map<string, number>();
113
118
  return (keys, needle, fallback) => {
114
119
  const node = nodeAt(lines, keys);