The Problem
Our GitHub Actions pipeline was taking 40+ minutes. Engineers were losing focus waiting for CI results.
Optimization Techniques
1. Aggressive Dependency Caching
- uses: actions/cache@v4
with:
path: |
~/.npm
node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
2. Parallel Job Matrix
Split tests across 4 workers:
strategy:
matrix:
shard: [1, 2, 3, 4]
steps:
- run: npm test -- --shard=${{ matrix.shard }}/4
3. Skip Redundant Steps
Use `paths` filters to skip Docker builds when only docs change:
on:
push:
paths:
- 'src/**'
- 'Dockerfile'