Skip to content

Optimize GitHub Actions npm install time by shrinking and reusing the right caches#8540

Merged
pubkey merged 1 commit into
masterfrom
copilot/optimize-ci-npm-install-time
May 18, 2026
Merged

Optimize GitHub Actions npm install time by shrinking and reusing the right caches#8540
pubkey merged 1 commit into
masterfrom
copilot/optimize-ci-npm-install-time

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 18, 2026

CI was spending unnecessary time restoring and saving large per-job dependency caches, then retrying full npm install runs with fixed sleeps. This change narrows npm caching to tarballs, reuses a shared cache across equivalent jobs, and lets npm handle transient fetch retries directly.

  • Cache only the npm tarball store

    • Removed ./node_modules, ./docs-src/node_modules, and other workspace node_modules paths from Actions caches
    • Kept ~/.npm as the shared cache target, which is cheaper to restore/save and still speeds installs
  • Deduplicate cache keys across equivalent jobs

    • Replaced many job-specific root dependency cache keys with one shared key:
      • Linux/Windows jobs now reuse the same root dependency cache shape per OS
      • Cache invalidation now tracks package.json and .npmrc changes
  • Replace shell retry chains with npm-native fetch retries

    • Removed repeated patterns like npm install || (sleep 15 && npm install) ...
    • Added workflow-level npm fetch retry settings and prefer-offline so retries happen at the network fetch layer instead of rerunning the whole install
  • Preserve non-npm caching where needed

    • Split the FoundationDB workflow cache so Docker layer caching remains separate from npm dependency caching
env:
  NPM_CONFIG_FETCH_RETRIES: 3
  NPM_CONFIG_FETCH_RETRY_FACTOR: 2
  NPM_CONFIG_FETCH_RETRY_MINTIMEOUT: 5000
  NPM_CONFIG_FETCH_RETRY_MAXTIMEOUT: 20000
  NPM_CONFIG_PREFER_OFFLINE: true

- name: Reuse npm cache folder
  uses: actions/cache@v5
  with:
    path: |
      ~/.npm
    key: ${{ runner.os }}-npm-root-v1-${{ hashFiles('**/package.json', '**/.npmrc') }}

- name: install npm dependencies
  run: npm install

Agent-Logs-Url: https://github.com/pubkey/rxdb/sessions/f3053277-d263-48bc-95f1-c4dcb321fa1c

Co-authored-by: pubkey <8926560+pubkey@users.noreply.github.com>
@pubkey pubkey marked this pull request as ready for review May 18, 2026 13:38
@pubkey pubkey merged commit 9805c15 into master May 18, 2026
26 of 27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants