GH

CI/CD Pipeline Optimization

Caching, parallelization, and build speed optimization for GitHub Actions

Details

Language / Topic
github-actionsGitHub Actions
Category
Performance

Rules

balanced
- Cache dependency installations: actions/cache for node_modules, pip cache, Go module cache
- Parallelize independent jobs: lint, type-check, unit test, and E2E test as separate concurrent jobs
- Use path filters to skip workflows when irrelevant files change: on.push.paths: ['src/**']
- Choose appropriate runner sizes: ubuntu-latest for most jobs, larger runners for memory-heavy builds
- Use artifacts to pass build output between jobs instead of rebuilding in each job
- Cache dependencies: actions/cache or setup-* action built-in caching; key on lockfile hash for invalidation
- Parallel job structure: lint | type-check | unit-test | e2e-test → build → deploy (independent jobs run concurrently)
- Path filters: on.push.paths to skip CI on docs-only or config-only changes; paths-ignore for exclusions
- Runner selection: ubuntu-latest (2-core) for most jobs; large runners (8-core) for heavy builds/tests
- Artifacts: actions/upload-artifact after build, actions/download-artifact in deploy job — build once, deploy anywhere
- Combine small steps: one npm ci + build step instead of separate install and build jobs (reduce overhead)
- Use setup-* actions with built-in caching: actions/setup-node with cache: 'npm' handles caching automatically
- Matrix strategy for multi-version testing; use fail-fast: true for PR feedback, false for release validation
- Conditional steps: if: github.event_name == 'push' && github.ref == 'refs/heads/main' to skip deploy on PRs
- Use concurrency with cancel-in-progress to stop superseded PR workflow runs
- Cache Docker layers: docker/build-push-action with cache-from/cache-to for container builds