CI takes 12 minutes mostly because dependencies are downloaded every run.
BeginnerScenarioGitHub Actions
Answer
Situation read → No dependency caching.
What I'd do →
- Use the built-in cache of setup actions (
cache: npm|pip|maven|gradle) oractions/cache@v4withkey: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}andrestore-keys. - Cache the package manager cache directory, not
node_modules. - Watch the 10 GB per-repo cache limit and eviction.
Why → Keying on the lockfile hash invalidates exactly when dependencies change.
Interview tip → Caches from PR branches are not shared with sibling branches, only from the default and base branches.
More on GitHub Actions
What are workflows, jobs, steps and actions in GitHub Actions?BeginnerWhat events can trigger a workflow?BeginnerWhat is the difference between `pull_request` and `pull_request_target`?AdvancedWhat is a runner, and how do GitHub-hosted and self-hosted runners differ?BeginnerHow do you pass data between steps and between jobs?IntermediateHow does a build matrix work?Intermediate