pnpm 项目在 CI 里跑 install 慢,缓存总是配不好。试了几种方案,记录下正确的姿势。
GitHub Actions:
- uses: pnpm/action-setup@v3
with: { version: 9 }
- uses: actions/setup-node@v4
with:
node-version: 20
cache: pnpm
- run: pnpm install --frozen-lockfile
关键点:
- 必须用
--frozen-lockfile,否则可能改 lockfile。 - cache key 用 pnpm-lock.yaml 的 hash。
- setup-node 的
cache: pnpm会自动缓存 store。
配好后 install 从 60s 掉到 8s。
大家 CI 缓存都咋配?