Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions .github/workflows/typecheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,35 @@ on:
workflow_dispatch:

jobs:
typecheck:
shard:
name: typecheck (${{ matrix.shard }}/5)
runs-on: blacksmith-4vcpu-ubuntu-2404
strategy:
fail-fast: false
matrix:
shard: [1, 2, 3, 4, 5]
steps:
- name: Checkout repository
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1

- name: Setup Bun
uses: ./.github/actions/setup-bun

# One slice of the workspace per job: all 37 packages at once is more than a 4-vCPU runner
# can hold, and the job that tried used to die mid-run. Assignment is by sorted package
# name (see script/typecheck-shard.ts), so a failure names the package.
- name: Run typecheck
run: bun typecheck
run: bun script/typecheck-shard.ts $((${{ matrix.shard }} - 1)) 5

# The one check branch protection requires. It passes only when every shard did, so the
# protection rule keeps its name and the matrix can change shape underneath it.
typecheck:
name: typecheck
runs-on: ubuntu-latest
needs: shard
if: always()
steps:
- name: Every shard passed
run: |
echo "shards: ${{ needs.shard.result }}"
test "${{ needs.shard.result }}" = "success"
20 changes: 0 additions & 20 deletions .husky/pre-push

This file was deleted.

21 changes: 9 additions & 12 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"typecheck": "bun turbo typecheck",
"upgrade-opentui": "bun run script/upgrade-opentui.ts",
"postinstall": "bun run --cwd packages/core fix-node-pty",
"prepare": "husky",
"random": "echo 'Random script'",
"sso": "aws sso login --sso-session=opencode --no-browser",
"translate:app": "bun run script/translate-app.ts",
Expand Down Expand Up @@ -105,7 +104,6 @@
"@types/mime-types": "3.0.1",
"@typescript/native-preview": "catalog:",
"glob": "13.0.5",
"husky": "9.1.7",
"oxlint": "1.60.0",
"oxlint-tsgolint": "0.21.0",
"prettier": "3.6.2",
Expand Down
50 changes: 50 additions & 0 deletions script/typecheck-shard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env bun
/**
* Typecheck one slice of the workspace.
*
* Every package at once needs more memory than a 4-vCPU runner has, and the pre-push hook that
* used to do exactly that was killed mid-run often enough to lose a release. So CI runs the
* packages in a fixed number of shards, each its own job: `bun script/typecheck-shard.ts 2 5`
* runs the third of five. The assignment is by sorted package name, so it is stable across runs
* and a failure names the package, not the shard.
*/
import path from "path"

const [indexArg, totalArg] = process.argv.slice(2)
const index = Number(indexArg)
const total = Number(totalArg)
if (!Number.isInteger(index) || !Number.isInteger(total) || total < 1 || index < 0 || index >= total) {
console.error("usage: bun script/typecheck-shard.ts <index> <total>")
process.exit(2)
}

const root = path.resolve(import.meta.dir, "..")
const manifest = (await Bun.file(path.join(root, "package.json")).json()) as {
workspaces: string[] | { packages: string[] }
}
const patterns = Array.isArray(manifest.workspaces) ? manifest.workspaces : manifest.workspaces.packages

// A Set, because the workspace globs overlap (`packages/*` and `packages/slack`).
const packages = new Set<string>()
for (const pattern of patterns) {
const glob = new Bun.Glob(path.posix.join(pattern, "package.json"))
for await (const file of glob.scan({ cwd: root, dot: false })) {
if (file.includes("node_modules/")) continue
const json = (await Bun.file(path.join(root, file)).json()) as { name?: string; scripts?: Record<string, string> }
if (json.name && json.scripts?.typecheck) packages.add(json.name)
}
}
const sorted = [...packages].sort()

const mine = sorted.filter((_, i) => i % total === index)
if (mine.length === 0) {
console.log(`shard ${index + 1}/${total}: nothing to check`)
process.exit(0)
}
console.log(`shard ${index + 1}/${total}: ${mine.join(", ")}`)

const proc = Bun.spawn(["bun", "turbo", "typecheck", ...mine.flatMap((name) => ["--filter", name])], {
cwd: root,
stdio: ["inherit", "inherit", "inherit"],
})
process.exit(await proc.exited)
Loading