Skip to content

Commit a28ac7f

Browse files
byapparovclaude
andcommitted
build: SHA-pin actions/checkout and harden the Bun pin test (#226 review 2)
- pin actions/checkout to d23441a4 (# v6) in ci and publish - CONTRIBUTING: Bun ^1.4.3 (1.4.3 or a later 1.x), matching the hook - pin test discovers every workflow with a setup-bun step, asserts each reads package.json and every action ref is a commit SHA - pin test rejects a BUN_VERSION default and requires the :? guard Bun download checksum in the bun-node image deferred to #227. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015nwvfUHdM3bgMgD9Zpz7Mj
1 parent 0d84507 commit a28ac7f

4 files changed

Lines changed: 38 additions & 17 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
verify:
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v6
13+
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6
1414
- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
1515
with:
1616
bun-version-file: package.json

‎.github/workflows/publish.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
contents: read
1313
id-token: write
1414
steps:
15-
- uses: actions/checkout@v6
15+
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6
1616
- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
1717
with:
1818
bun-version-file: package.json

‎CONTRIBUTING.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Any other OpenAI-compatible provider does not need a code change: users define i
3232

3333
## Developing Aictrl
3434

35-
- Requirements: Bun 1.4.3, the version pinned in the root `package.json` `packageManager` field
35+
- Requirements: Bun ^1.4.3 (1.4.3 or a later 1.x), from the root `package.json` `packageManager` field
3636
- Install dependencies and start the dev server from the repo root:
3737

3838
```bash
Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,54 @@
1-
import { expect, test } from "bun:test"
1+
import { describe, expect, test } from "bun:test"
22
import path from "path"
33

44
// The compiled binary embeds the Bun that built it, so every toolchain entry
55
// point must take the version from the root package.json `packageManager`.
66
const root = path.resolve(import.meta.dir, "../../../..")
77
const read = (file: string) => Bun.file(path.join(root, file)).text()
88

9+
type Step = { uses?: string; with?: Record<string, string> }
10+
type Workflow = { jobs: Record<string, { uses?: string; steps?: Step[] }> }
11+
12+
const workflowFiles = Array.from(new Bun.Glob(".github/workflows/*.{yml,yaml}").scanSync({ cwd: root })).sort()
13+
const workflows = await Promise.all(
14+
workflowFiles.map(async (file) => ({ file, workflow: Bun.YAML.parse(await read(file)) as Workflow })),
15+
)
16+
const steps = (workflow: Workflow) => Object.values(workflow.jobs).flatMap((job) => job.steps ?? [])
17+
const isSetupBun = (step: Step) => step.uses?.startsWith("oven-sh/setup-bun@") ?? false
18+
const bunWorkflows = workflows.filter(({ workflow }) => steps(workflow).some(isSetupBun))
19+
920
test("packageManager pins an exact Bun version", async () => {
1021
const pkg = JSON.parse(await read("package.json"))
1122
expect(pkg.packageManager).toMatch(/^bun@\d+\.\d+\.\d+$/)
1223
})
1324

14-
test.each([".github/workflows/ci.yml", ".github/workflows/publish.yml"])(
15-
"%s installs Bun from package.json",
16-
async (file) => {
17-
const workflow = Bun.YAML.parse(await read(file)) as {
18-
jobs: Record<string, { steps: { uses?: string; with?: Record<string, string> }[] }>
19-
}
20-
const setups = Object.values(workflow.jobs)
21-
.flatMap((job) => job.steps)
22-
.filter((step) => step.uses?.startsWith("oven-sh/setup-bun@"))
23-
expect(setups.length).toBeGreaterThan(0)
24-
for (const step of setups) {
25+
test("CI and release workflows install Bun", () => {
26+
expect(bunWorkflows.map(({ file }) => file)).toEqual(
27+
expect.arrayContaining([".github/workflows/ci.yml", ".github/workflows/publish.yml"]),
28+
)
29+
})
30+
31+
describe.each(bunWorkflows)("$file", ({ workflow }) => {
32+
test("installs Bun from package.json", () => {
33+
for (const step of steps(workflow).filter(isSetupBun)) {
2534
expect(step.with).toEqual({ "bun-version-file": "package.json" })
2635
}
27-
},
28-
)
36+
})
37+
38+
test("pins every action to a commit SHA", () => {
39+
const uses = [
40+
...Object.values(workflow.jobs).flatMap((job) => (job.uses ? [job.uses] : [])),
41+
...steps(workflow).flatMap((step) => (step.uses ? [step.uses] : [])),
42+
]
43+
for (const ref of uses.filter((ref) => !ref.startsWith("./"))) {
44+
expect(ref).toMatch(/@[0-9a-f]{40}$/)
45+
}
46+
})
47+
})
2948

3049
test("bun-node image has no Bun version of its own", async () => {
3150
const dockerfile = await read("packages/containers/bun-node/Dockerfile")
3251
expect(dockerfile).toMatch(/^ARG BUN_VERSION$/m)
52+
expect(dockerfile).not.toMatch(/^ARG\s+BUN_VERSION=/m)
53+
expect(dockerfile).toContain('"${BUN_VERSION:?')
3354
})

0 commit comments

Comments
 (0)