Cache dependencies in Forgejo Actions

Caching is a performance feature, not a correctness feature. Workflows should pass cold before relying on cache hits.

Actions

What this solves

You want faster Forgejo Actions runs without hiding dependency or runner problems.

Best fit

  • pnpm and npm installs
  • Python wheels
  • Go module cache
  • Rust cargo cache

How to think about it

Good cache keys are tied to dependency lockfiles and toolchain versions. A cache should reduce repeated work without masking missing install steps or making a job depend on state that may disappear.

Lockfile-based cache key

steps:
  - uses: actions/checkout@v4
  - uses: actions/cache@v4
    with:
      path: ~/.npm
      key: npm-${{ hashFiles('package-lock.json') }}
  - run: npm ci
  - run: npm test

Practical path

  1. 01 Make the workflow pass without a cache first.
  2. 02 Choose cache keys based on lockfiles and toolchain versions.
  3. 03 Track whether cache hits reduce runtime enough to justify the complexity.

When to choose another path

Make the job pass after clearing all caches.

Include lockfiles and language versions in cache keys.

Measure runtime before and after so cache maintenance is justified.

Next resources

Related reading