Skip to content

Commit 2ad03c4

Browse files
authored
🤖 perf: skip redundant bun cache restore when node_modules exists (#1026)
## Problem Windows builds were taking ~8 minutes, with setup-mux taking ~2.5 minutes. ### Root Cause The `cache-hit` output from `actions/cache` is `false` for partial restore-key matches. This caused: 1. node_modules cache restored via restore-key → `cache-hit='false'` 2. Bun install cache also restored (275MB) → 88s decompression on Windows tar/zstd 3. `bun install` runs but is a no-op (node_modules exists) 4. Post-job: both caches re-saved with new keys (~77s combined) ### Timeline breakdown (from [this run](https://github.com/coder/mux/actions/runs/20063325241/job/57545464568)): | Step | Duration | |------|----------| | Restore node_modules | 30s | | **Restore bun cache** | **88s** ← wasted | | bun install | 0.5s | | choco install make | 12s | | bun run build | 53s | | make dist-win | 163s | | **Post: save caches** | **77s** ← partially wasted | ## Solution Check if `node_modules/.bin` actually exists after cache restore, instead of relying on `cache-hit` output. This is more reliable for determining if we need to install dependencies. ## Expected improvement ~88-165 seconds saved on Windows builds when lockfile hash changes (partial cache hit scenario). _Generated with `mux`_
1 parent dfaf29c commit 2ad03c4

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

.github/actions/setup-mux/action.yml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,20 @@ runs:
2222
restore-keys: |
2323
${{ runner.os }}-${{ runner.arch }}-bun-${{ steps.bun-version.outputs.version }}-node-modules-
2424
25+
- name: Check if node_modules exists
26+
id: check-node-modules
27+
shell: bash
28+
run: |
29+
if [ -d "node_modules" ] && [ -d "node_modules/.bin" ]; then
30+
echo "exists=true" >> $GITHUB_OUTPUT
31+
else
32+
echo "exists=false" >> $GITHUB_OUTPUT
33+
fi
34+
35+
# Only restore bun install cache when node_modules is completely missing.
36+
# This avoids 88+ seconds of tar/zstd decompression on Windows for partial cache hits.
2537
- name: Cache bun install cache
26-
if: steps.cache-node-modules.outputs.cache-hit != 'true'
38+
if: steps.check-node-modules.outputs.exists != 'true'
2739
id: cache-bun-install
2840
uses: actions/cache@v4
2941
with:
@@ -33,6 +45,6 @@ runs:
3345
${{ runner.os }}-bun-cache-
3446
3547
- name: Install dependencies
36-
if: steps.cache-node-modules.outputs.cache-hit != 'true'
48+
if: steps.check-node-modules.outputs.exists != 'true'
3749
shell: bash
3850
run: bun install --frozen-lockfile

0 commit comments

Comments
 (0)