Skip to content

Commit 85aa44b

Browse files
authored
perf(release): publish without the Nix dev shell (#1257)
* perf(ccusage): drop schema regeneration from the publish build The publish build ran `generate:schema`, which compiles and runs the Rust `generate-config-schema` binary on every `pnpm publish` and pkg-pr-new pack. The committed apps/ccusage/config-schema.json is already kept in sync with the Rust source by the `nix flake check` schema-drift check, so regenerating it during packaging is redundant: it adds cargo build time and a hard Rust toolchain dependency to the publish path. `build` now runs only `tsdown` and `ensure:native-binary`. The `generate:schema` script stays for local regeneration (`pnpm --filter ccusage run generate:schema` and `just schema`). * ci(release): publish to npm without the Nix dev shell The npm publish job runs on a GitHub-hosted runner (required for npm provenance, which rejects self-hosted/Blacksmith runners), so it never gets the Blacksmith sticky-disk Nix cache and re-downloaded the full dev shell (Rust toolchain, litellm, etc.) from cache.nixos.org on every release — ~5 minutes of the ~7-minute job for a task that only needs node, pnpm and bun. Now that the publish build no longer invokes cargo, drop `nix develop` and set up the toolchain directly: pnpm/action-setup (reads packageManager), setup-node, then `pnpm install --frozen-lockfile`, which downloads the bun runtime declared in engines.runtime so the `ensure:native-binary` script resolves it from node_modules/.bin during packaging. * ci: scope the Blacksmith sticky-disk Nix store per job The sticky-disk key was shared across every Linux job of the same arch. A sticky disk clones the last committed snapshot and re-commits on completion, so jobs that realize different Nix closures (a full dev shell vs. a single `nix build`) overwrote each other's store on the shared key, forcing cold re-downloads from cache.nixos.org — the source of the large run-to-run variance in pkg-pr-new (149s vs 388s). Key the disk by `github.job` so each closure stays warm independently. * ci(release): provision pnpm from the pinned Nix profile Replace pnpm/action-setup with `nix profile install --inputs-from . nixpkgs#pnpm` so the publish toolchain is pinned to the flake's locked nixpkgs (pnpm 11.1.1, identical to the dev shell) instead of a separate action's resolution, while still avoiding the full `nix develop` dev shell that made the job slow. setup-node stays solely for the npm publish configuration (registry + OIDC provenance .npmrc wiring); the locked nixpkgs node is below the engines floor, so node is sourced from setup-node. bun is not installed here — `pnpm install` downloads it via engines.runtime into node_modules/.bin, where the prepack `ensure:native-binary` script resolves it.
1 parent b7948ab commit 85aa44b

3 files changed

Lines changed: 10 additions & 3 deletions

File tree

‎.github/actions/setup-linux-blacksmith-sticky-disk/action.yaml‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ runs:
2424
if: steps.blacksmith.outputs.enabled == 'true'
2525
uses: useblacksmith/stickydisk@2b7a836cbb2b48f4780ae76a7b6fd79d545fb54a # v1.3.0
2626
with:
27-
key: ${{ github.repository }}-nix-${{ runner.os }}-${{ runner.arch }}
27+
# Scope the disk per job: a sticky disk clones the last committed
28+
# snapshot and re-commits on completion, so jobs that realize different
29+
# Nix closures (e.g. a full dev shell vs. a single `nix build`) would
30+
# otherwise overwrite each other's store on a shared key and force cold
31+
# re-downloads. Keying by job keeps each closure warm independently.
32+
key: ${{ github.repository }}-nix-${{ runner.os }}-${{ runner.arch }}-${{ github.job }}
2833
path: /nix
2934

3035
- name: Prepare mounted Nix store ownership

‎.github/workflows/release.yaml‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ jobs:
9090
registry-url: 'https://registry.npmjs.org'
9191
node-version: lts/*
9292
package-manager-cache: false
93+
- run: nix profile install --inputs-from . nixpkgs#pnpm
94+
- run: pnpm install --frozen-lockfile
9395
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
9496
with:
9597
pattern: ccusage-native-*
@@ -100,7 +102,7 @@ jobs:
100102
for archive in "$RUNNER_TEMP"/native-packages/*.tar; do
101103
tar -xf "$archive"
102104
done
103-
- run: nix develop --command pnpm --filter='./apps/ccusage' --filter='./packages/ccusage-*' publish --provenance --no-git-checks --access public
105+
- run: pnpm --filter='./apps/ccusage' --filter='./packages/ccusage-*' publish --provenance --no-git-checks --access public
104106

105107
release:
106108
needs:

‎apps/ccusage/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
},
3030
"scripts": {
3131
"bench": "node scripts/bench.mjs",
32-
"build": "pnpm run generate:schema && tsdown && pnpm run ensure:native-binary",
32+
"build": "tsdown && pnpm run ensure:native-binary",
3333
"build:rust": "cargo build --manifest-path ../../rust/Cargo.toml --release --bin ccusage",
3434
"ensure:native-binary": "bun scripts/ensure-native-binary.ts",
3535
"generate:schema": "cargo run --quiet --manifest-path ../../rust/Cargo.toml --bin generate-config-schema -- config-schema.json && oxfmt --write config-schema.json && cp config-schema.json ../../docs/public/config-schema.json",

0 commit comments

Comments
 (0)