-
Notifications
You must be signed in to change notification settings - Fork 14
ci: harden dependency audit checks #990
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e06c8ca
ci: remove unused perf Playwright browser cache
Astro-Han c542a4e
ci: add dependency audit checks
Astro-Han 3f4141f
ci: pin Bun audit runtime
Astro-Han a71eaeb
test: include workflow env contract type
Astro-Han f99749c
ci: keep Bun audit advisory
Astro-Han 69e62f5
test: require setup-bun version pins
Astro-Han 42bc2aa
ci: fail dev dependency audit advisories
Astro-Han File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| name: dev-dep-audit | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: [dev] | ||
|
|
||
| concurrency: | ||
| group: dev-dep-audit-${{ github.event.pull_request.number || github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| dev-dep-audit: | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 10 | ||
| steps: | ||
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # actions/checkout@v6 | ||
| with: | ||
| persist-credentials: false | ||
|
|
||
| - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # actions/setup-node@v6.4.0 | ||
| with: | ||
| node-version: "24" | ||
|
|
||
| - uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # oven-sh/setup-bun@v2 | ||
| with: | ||
| # Load-bearing for `bun audit` exit semantics; do not bump without re-verifying advisory exit codes. | ||
| bun-version: "1.3.14" | ||
|
|
||
| - name: Install dependencies | ||
| run: bun install --frozen-lockfile | ||
|
|
||
| - name: Run Bun audit | ||
| run: bun audit --audit-level=high |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
packages/opencode/test/github/bun-version-workflow.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| import { describe, expect, test } from "bun:test" | ||
| import fs from "node:fs" | ||
| import path from "node:path" | ||
| import { fileURLToPath } from "node:url" | ||
| import { parseWorkflow, type Workflow } from "./workflow-parser" | ||
|
|
||
| const repoRoot = fileURLToPath(new URL("../../../..", import.meta.url)) | ||
| const workflowsRoot = path.join(repoRoot, ".github", "workflows") | ||
| const expectedBunVersion = "1.3.14" | ||
| const auditComment = "Load-bearing for `bun audit` exit semantics" | ||
|
|
||
| function collectSetupBunPins(workflow: Workflow, relativePath: string) { | ||
| const pins: string[] = [] | ||
|
|
||
| for (const [jobName, job] of Object.entries(workflow.jobs ?? {})) { | ||
| for (const [stepIndex, step] of (job.steps ?? []).entries()) { | ||
| if (!step.uses?.startsWith("oven-sh/setup-bun@")) continue | ||
|
|
||
| const bunVersion = step.with?.["bun-version"] ?? "<missing>" | ||
| pins.push(`${relativePath}:${jobName}:step-${stepIndex + 1}:bun-version: ${JSON.stringify(bunVersion)}`) | ||
| } | ||
| } | ||
|
|
||
| return pins | ||
| } | ||
|
|
||
| describe("GitHub workflow Bun version pin", () => { | ||
| test("detects setup-bun steps that omit bun-version", () => { | ||
| const workflow: Workflow = { | ||
| jobs: { | ||
| unpinned: { | ||
| steps: [{ uses: "oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6" }], | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| expect(collectSetupBunPins(workflow, "synthetic.yml")).toEqual([ | ||
| "synthetic.yml:unpinned:step-1:bun-version: \"<missing>\"", | ||
| ]) | ||
| }) | ||
|
|
||
| test("keeps every setup-bun runtime on the audit-verified Bun version", () => { | ||
| const packageJson = JSON.parse(fs.readFileSync(path.join(repoRoot, "package.json"), "utf8")) as { | ||
| packageManager?: string | ||
| } | ||
| expect(packageJson.packageManager).toBe(`bun@${expectedBunVersion}`) | ||
|
|
||
| const workflowFiles = fs | ||
| .readdirSync(workflowsRoot) | ||
| .filter((name) => name.endsWith(".yml")) | ||
| .sort() | ||
| .map((name) => path.join(workflowsRoot, name)) | ||
|
|
||
| const setupBunPins: string[] = [] | ||
| const missingComments: string[] = [] | ||
|
|
||
| for (const workflowPath of workflowFiles) { | ||
| const relativePath = path.relative(repoRoot, workflowPath) | ||
| setupBunPins.push(...collectSetupBunPins(parseWorkflow(workflowPath), relativePath)) | ||
|
|
||
| const lines = fs.readFileSync(workflowPath, "utf8").split(/\r?\n/) | ||
| for (const [index, line] of lines.entries()) { | ||
| if (!line.includes("bun-version:")) continue | ||
|
|
||
| const previousLines = lines.slice(Math.max(0, index - 3), index).join("\n") | ||
| if (!previousLines.includes(auditComment)) { | ||
| missingComments.push(`${relativePath}:${index + 1}`) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| expect(setupBunPins).toEqual([ | ||
| ".github/workflows/build.yml:build-electron:step-5:bun-version: \"1.3.14\"", | ||
| ".github/workflows/ci.yml:typecheck:step-3:bun-version: \"1.3.14\"", | ||
| ".github/workflows/ci.yml:lint:step-3:bun-version: \"1.3.14\"", | ||
| ".github/workflows/ci.yml:frontend-architecture:step-5:bun-version: \"1.3.14\"", | ||
| ".github/workflows/ci.yml:unit-app:step-3:bun-version: \"1.3.14\"", | ||
| ".github/workflows/ci.yml:unit-ui:step-3:bun-version: \"1.3.14\"", | ||
| ".github/workflows/ci.yml:unit-opencode:step-3:bun-version: \"1.3.14\"", | ||
| ".github/workflows/ci.yml:unit-desktop:step-3:bun-version: \"1.3.14\"", | ||
| ".github/workflows/desktop-smoke.yml:smoke-macos-arm64:step-3:bun-version: \"1.3.14\"", | ||
| ".github/workflows/dev-dep-audit.yml:dev-dep-audit:step-3:bun-version: \"1.3.14\"", | ||
| ".github/workflows/e2e-artifacts.yml:e2e-artifacts:step-3:bun-version: \"1.3.14\"", | ||
| ".github/workflows/officecli-bump.yml:officecli-bump:step-3:bun-version: \"1.3.14\"", | ||
| ".github/workflows/perf-probe-baseline.yml:perf-probe-baseline:step-7:bun-version: \"1.3.14\"", | ||
| ".github/workflows/windows-advisory.yml:unit-windows:step-3:bun-version: \"1.3.14\"", | ||
| ]) | ||
| expect(missingComments).toEqual([]) | ||
| }) | ||
| }) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.