GKGulshan Kumar
HomeBlogSlashing CI/CD Runtime by 50% with GitHu
CI/CD7 min read

Slashing CI/CD Runtime by 50% with GitHub Actions Optimization

GK
Gulshan Kumar
10 February 2025

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'

Results


MetricBeforeAfter Build time40 min19 min Deploy time15 min10 min Cache hit rate0%85%
← Back to Blog✉️ Discuss this post