pnpm store pruning
pnpm store pruning is the post-run cleanup step that removes pnpm store data that the completed dependency work no longer needs. It runs before the action saves a changed store to the GitHub Actions cache, so future runs can reuse a smaller cache without carrying forward unused package data.
Cleanup purpose
The pnpm store is shared package data used by dependency installation. Each install can add package versions or metadata to this store, while a later lockfile change can leave older data unused. Pruning gives the store a cleanup boundary at the end of an action run.
The cleanup uses pnpm's store-prune behavior rather than trying to decide which package data is safe to remove itself. This keeps the action aligned with pnpm's view of store content.
Lifecycle position
The cleanup belongs to the action's post phase. The main phase reads the inputs, prepares pnpm, restores any cache, and runs the configured install commands. The post phase restores the saved inputs, prunes the store, and then offers the resulting store to the cache-saving flow.
The following flow shows how pruning connects dependency installation with cache persistence.
flowchart LR
A[Configured install commands] --> B[Dependency installation]
B --> C[Post phase]
C --> D[Prune pnpm store]
D --> E[Save changed store to cache]
D --> F[No cache save when caching is disabled]
Post-run cleanup
The action schedules its post phase when the main phase starts. The post phase uses the inputs saved by the main phase, so pruning can occur after the install work has ended without repeating input parsing.
Pruning completes before cache persistence. As a result, a cache save uses the cleaned store rather than the store as it existed immediately after installation. See cache persistence for the rules that decide whether that cleaned store is saved.
References: src/index.ts• L10-16 src/index.ts• L18-36 src/…/index.ts• L11-18
Pruning condition
Pruning is tied to configured install work. When the run_install input produces no install commands, the action skips pruning because this run did not ask the action to install dependencies.
The cache input does not control whether pruning runs. If install commands are configured, pruning can still run when cache use is disabled; the later cache-saving step then exits without saving the store.
Install command presence
The action checks the parsed runInstall list. A non-empty list means the action has install work to clean up after. The list is also the source used by the installation phase, which keeps the cleanup decision tied to the same user request.
References: src/…/index.ts• L5-12 src/…/index.ts• L21-29 src/…/index.ts• L5-9 src/…/index.ts• L5-12
Failure handling
The cleanup is best effort. The action reports a warning when pnpm cannot start or when the prune command returns a non-zero status, but it does not turn that cleanup result into a failed action by itself.
This behavior separates dependency installation status from store maintenance status. A failed install can still reach the post phase, while a cleanup problem does not hide the primary result of the workflow. Cache persistence can therefore receive the store after a warning; its own save rules still apply.
Command result
The cleanup command inherits the pnpm command environment prepared earlier in the run. Its output appears in a grouped action log, which lets an engineer see the cleanup result without treating the cleanup as a separate workflow step.
References: src/…/index.ts• L11-28 src/…/index.ts• L14-24 src/index.ts• L39-42
Related flows
Pruning is one part of the action runtime rather than a separate cache policy. Action runtime orchestration gives the full run sequence. Dependency installation explains the work that creates or updates store data. Cache restoration explains how an earlier store enters the run, and cache persistence explains how the cleaned result can leave it.
The cleanup does not change the action's reported outputs. Action outputs covers those values, while pnpm provisioning covers how the pnpm command becomes available before pruning runs. Action inputs describes the input that controls install configuration.
Store handoff
The restore and save flows use pnpm's reported store path. Pruning acts on that same store, so the data cleaned in the post phase is the data that the cache flow can persist for a later run.
References: src/…/run.ts• L8-10 src/…/run.ts• L43-48 src/…/run.ts• L4-17 src/index.ts• L33-37
Change checklist
When these files or sections are changed, remember to consider these:
- If the action lifecycle changes, preserve the order of pruning before cache saving. Reversing that order can persist store data before cleanup.
- If
run_installparsing changes, verify that the same parsed install set still controls both installation and the pruning decision. - If cache path or cache state handling changes, verify that pruning still affects the store path used by cache persistence.
- If failure policy changes, verify that cleanup warnings do not accidentally replace the install result or prevent the post phase from reaching cache handling.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| No install commands are configured | The store is not pruned during this run. | Configure run_install when the action is responsible for dependency installation and cleanup. |
| The pnpm command cannot start | The action logs a warning and continues the post phase. | Ensure the pnpm executable prepared by provisioning remains on the post-phase command path. |
pnpm store prune returns a non-zero status | The action logs the exit status without failing the action from pruning alone. | Review the warning and treat store cleanup as a separate health signal from install success. |
| Pruning runs after cache persistence | The cache can retain data that pruning would have removed. | Keep the post-phase order as prune, then save cache. |
Key files
| File | Why to read it |
|---|---|
| src/…/index.ts | Defines when pruning is skipped and how the pnpm cleanup result is reported. |
| src/index.ts | Shows the main and post phases and places pruning before cache saving. |
| src/…/index.ts | Defines the parsed install-command set and cache flag used by the lifecycle. |
| src/…/run.ts | Shows how the post-prune store is considered for cache persistence. |
| src/…/run.ts | Shows how the cache flow identifies the pnpm store path that pruning later cleans. |
| action.yml | Documents the public run_install and cache inputs and the post-action entry point. |