Skip to content

Lesson 3 of 9 · 23m

Dependencies, Artifacts, Caching, and Concurrency

The mechanics that decide whether CI is fast and correct: job graphs, artifact boundaries, cache keys, and cancellation policy.

Fast CI is rarely fast because someone found a magic runner size. It is fast because the dependency graph is honest, artifacts are small, caches are keyed correctly, and obsolete work cancels itself. Slow CI is usually four reasonable decisions compounding into a twenty-minute queue.

needs is a dependency graph, not decoration

Jobs run in parallel unless connected with needs. That is the feature. Do not serialize everything because one job once depended on another.

jobs:
  lint: {runs-on: ubuntu-latest}
  unit: {runs-on: ubuntu-latest}
  package: {needs: [lint, unit], runs-on: ubuntu-latest}
  deploy: {needs: package, runs-on: ubuntu-latest}

lint and unit start together. package waits for both. If lint is a nice-to-have signal rather than a release gate, do not put it in the deployment path.

Artifacts are for handoff, not storage

Artifacts cross job boundaries and support review evidence. They are not your primary artifact repository. Keep CI handoff artifacts small and short-lived.

- uses: actions/upload-artifact@v4
  with:
    name: test-report-${{ matrix.node }}
    path: reports/junit.xml
    retention-days: 5
    if-no-files-found: error

Use unique names in matrices or uploads collide. Use if-no-files-found: error when absence means a broken build; the default warning can hide a silent failure.

Caching is an optimization with correctness rules

actions/cache keys determine reuse. A broad key gives fast but wrong dependencies. A narrow key gives correctness but constant cache misses.

- uses: actions/setup-node@v4
  with:
    node-version: 22
    cache: npm
    cache-dependency-path: package-lock.json

For monorepos, set the exact lockfile path or composite hash. Do not cache node_modules blindly when the package manager already has a better cache format. npm, pnpm, pip, Maven, and Cargo each cache different things.

Concurrency prevents obsolete deployments

concurrency:
  group: deploy-${{ github.ref }}
  cancel-in-progress: true

For CI, cancellation is usually desirable: a newer push supersedes the old one. For deployment, think harder. Canceling halfway through a migration can be worse than letting it finish. A common pattern is cancellation for build/test groups, but cancel-in-progress: false for production deployment groups.

Field notes

  • Artifacts are immutable once uploaded in a run; downloading the wrong one is often a naming problem, not a GitHub outage.
  • Cache restore-keys are prefix matches. Understand fallback behavior before relying on it.
  • needs failures propagate. Skipped upstream dependencies can silently skip downstream jobs unless if uses always() carefully.
  • Queue time often dominates runner time. Measure both before buying larger runners.

Was this lesson helpful?

Sign in to rate