GH

Caching & Workflow Optimization

Speed up CI/CD execution and reduce redundant overhead.

Details

Language / Topic
github-actionsGitHub Actions
Category
Performance

Rules

balanced
- Use `actions/cache` with a precise key including lockfile hash to avoid stale caches: `key: deps-${{ hashFiles('**/lockfile') }}`.
- Use `restore-keys` fallback for partial cache hits when the exact key misses.
- Cache dependencies with `actions/cache` using lockfile hash in the key: `key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}`.
- Use `restore-keys` for prefix-based fallback: `restore-keys: ${{ runner.os }}-node-` — stale cache is faster than no cache.
- Use language-specific setup actions with built-in caching: `actions/setup-node` with `cache: 'npm'`, `actions/setup-python` with `cache: 'pip'`.
- Cache build outputs (`.next/cache`, `dist/`, `.turbo/`) in addition to dependencies for faster CI.
- Set appropriate `SEGMENT_DOWNLOAD_TIMEOUT` for large caches to avoid timeout failures.