Introducing a new way to review your PRs.

Read the announcement

pnpm / action-setup

Install pnpm package manager

View on GitHub

12 documents · Updated Nov 6, 2026

docs / cache-restoration

Cache restoration

Cache restoration loads a reusable pnpm store before the action installs dependencies. It uses the configured dependency files to identify the expected store state, then reports whether the restored cache exactly matches that state or only provides older reusable data.

Restoration role

The restore step runs during the action's main phase after pnpm is available and before any configured dependency install. It is optional: the action skips it when cache is disabled, and it warns and skips it when the GitHub Actions cache service is not available. See Action runtime for its place in the full lifecycle.

The restored store is shared with the later install step through pnpm's normal store location. An exact match can support a fully warm install. A partial match still gives pnpm package data that it can reuse while resolving the current dependency state. See Dependency installation for the next stage.

References: src/index.ts• L18-30 src/…/index.ts• L6-17 src/…/index.ts• L5-24 action.yml• L18-25

Cache identity

The cache identity represents the environment and dependency inputs that shape the pnpm store. The action hashes the configured dependency paths, then combines that hash with the runner operating system and CPU architecture to form the primary key.

Cache valuePurpose
Dependency path hashChanges when the contents of the configured lockfile or dependency files change.
Runner operating systemPrevents reuse across operating systems with different store contents.
CPU architecturePrevents reuse across architectures with different package data.
Primary keyIdentifies the store expected for the current run.

The default dependency path is pnpm-lock.yaml. Users can provide multiple paths as newline-delimited input when more than one dependency file must affect the cache identity. The action fails the restore when a configured path cannot be resolved, because a cache based on incomplete dependency input could be misleading.

References: src/…/run.ts• L12-19 src/…/index.ts• L5-12 src/…/index.ts• L21-28 action.yml• L22-25

Restore-key reuse

The action uses a runner-specific key prefix as a restore key. This allows a changed lockfile to reuse an older pnpm store instead of starting with an empty store, while the current install adds or updates the package data needed for the new dependency state.

The cache service returns the key that it restored. The action sets cache-hit to true only when that key equals the current primary key. A prefix match therefore supplies useful data but does not claim that the current dependency state is already cached.

This distinction connects restoration to Cache persistence: an exact hit does not need a new save, while a prefix match remains eligible for a new cache under the current primary key.

References: src/…/run.ts• L21-40 src/…/run.ts• L4-17

Restoration flow

The restoration flow first finds the store that pnpm currently uses. It then computes the primary key, asks the cache service to restore the store, and records the result for both action outputs and the later post phase.

This diagram shows how dependency inputs become cache state before installation begins.

flowchart TD
    A[Cache enabled] --> B[Find pnpm store path]
    B --> C[Hash configured dependency paths]
    C --> D[Build OS and architecture primary key]
    D --> E[Try exact key and runner prefix]
    E --> F{Cache key returned?}
    F -- No --> G[Continue with empty or existing store]
    F -- Yes --> H[Record restored key]
    H --> I{Restored key equals primary key?}
    I -- Yes --> J[Report exact cache hit]
    I -- No --> K[Report reusable prefix match]
    G --> L[Run dependency installation]
    J --> L
    K --> L

The action saves the store path, primary key, and restored key in GitHub Actions state. The post phase uses this state to decide whether a later cache save is needed. See Action outputs for the externally visible cache result and pnpm provisioning for the prerequisite that makes the store path available.

References: src/…/run.ts• L8-10 src/…/run.ts• L17-40 src/index.ts• L23-30 src/…/run.ts• L4-17

Cache state boundaries

Cache restoration does not install packages or decide how pnpm resolves dependencies. It prepares reusable store data and passes the exact-hit result to the install and post-save stages.

BoundaryResponsibility
Cache input and dependency pathsDecide whether restoration runs and which files define the cache identity.
RestorationLocate the pnpm store, request a matching cache, and record the result.
Dependency installationUse the available store while making the requested dependency state.
Cache persistenceSave the changed store under the new primary key when the restore was not exact.

For cleanup after installation, see pnpm store pruning. For input syntax and install options, see Action inputs.

References: src/…/index.ts• L6-17 src/…/run.ts• L8-40 src/…/index.ts• L5-37 src/…/run.ts• L4-17

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the dependency paths used for hashing aligned with the documented cache_dependency_path input and its default.
  • Keep the operating system and architecture parts of the primary key aligned with the cache data that pnpm can safely reuse.
  • Preserve the difference between an exact primary-key match and a restore-key prefix match. The prefix case must still allow a later save.
  • Keep the saved state names aligned with the post phase and with the cache output that reports an exact hit.
  • Keep cache restoration before dependency installation so the install can use restored store data.

Important failure modes

TriggerConsequenceGuard
cache is disabledThe action does not restore the pnpm store.Enable the cache input when the workflow needs store reuse.
A configured dependency path cannot be resolvedThe action fails instead of computing a cache key from incomplete inputs.Keep every cache_dependency_path entry present in the workspace.
The cache service is unavailableRestoration is skipped and the workflow continues without this cache step.Treat the install as a cold or partially warm run.
Only the runner-prefix key matchesAn older store is restored, but the run must still install dependencies and later create a more specific cache.Use cache-hit only for an exact primary-key match.
The pnpm store path cannot be obtainedThe action cannot select the directory to restore.Provision pnpm before the restore step.

Key files

FileWhy to read it
src/…/run.tsShows how the store path, dependency hash, cache keys, restore result, and saved state fit together.
src/…/index.tsShows the cache-enabled and cache-service availability guards.
src/index.tsShows that restoration occurs after pnpm provisioning and before dependency installation.
src/…/index.tsDefines the cache settings passed into restoration.
action.ymlDefines the public cache inputs and the action's main and post phases.
src/…/run.tsShows how restoration state controls whether the later save is skipped or performed.