Action runtime orchestration
The action runtime prepares a requested pnpm toolchain for one GitHub Actions job and can use it to install project dependencies. It coordinates input handling, pnpm setup, store caching, install commands, post-run cleanup, and values for later workflow steps.
Runtime lifecycle
Two-phase action lifecycle
The action metadata sends dist/index.js to GitHub Actions for both the main phase and the post phase. The main phase prepares the tool and performs dependency work. The post phase runs after later job steps so it can clean and save the pnpm store used by the job.
The main phase follows this order:
- Read and normalize settings through input handling.
- Provision the requested pnpm version through pnpm provisioning.
- Publish command paths through output publication.
- Restore the optional store through cache restoration.
- Run the requested dependency commands through install execution.
The post phase uses run state from the main phase. It prunes the store through store pruning, then saves changed data through cache persistence.
This diagram shows how the main phase prepares dependency work and how the post phase preserves the result.
flowchart TD
A[Action starts] --> B[Read and normalize inputs]
B --> C[Provision requested pnpm]
C --> D{Provisioning succeeds?}
D -- No --> E[Report failure and stop main phase]
D -- Yes --> F[Publish pnpm paths]
F --> G{Cache enabled?}
G -- Yes --> H[Restore pnpm store]
G -- No --> I[Skip cache restore]
H --> I
I --> J[Run dependency installs]
J --> K[Later post phase]
K --> L[Prune store when installs ran]
L --> M[Save changed store]
References: action.yml• L34-42 dist/index.js• L264-273
Shared run state
The main phase records the normalized settings and cache information that the post phase needs. This lets the post phase use the same store target and cache decision without rebuilding them after the main callback has ended.
This state link is important because GitHub Actions invokes the post callback separately. An incomplete main phase leaves the post phase without enough information for a complete cache save.
References: dist/index.js• L273 action.yml• L39-42
Main phase
Configuration and pnpm preparation
The action turns GitHub Action inputs into one run configuration. That configuration controls the pnpm version and destination. It also controls standalone mode, caching, dependency-file paths, the package file, and install requests. See input handling for the input contract.
The pnpm version can come from the action input or package-manager metadata in the selected package file. The runtime also accepts the devEngines.packageManager form. Conflicting declarations stop provisioning before cache or install work can use an unclear tool version. See pnpm provisioning for the toolchain contract.
The standalone choice depends on the pnpm release. Older supported releases use the executable package when standalone mode is enabled. pnpm 12 uses the plain pnpm package's native executable. The runtime starts dependency work only after provisioning succeeds.
References: action.yml• L6-33 dist/index.js• L264-273
Cache restoration and dependency work
When caching is enabled, the action restores the store used by the selected pnpm command. The cache key includes the runner platform, CPU type, and hashes of the configured dependency files. An exact key represents the current dependency inputs. A prefix match can still provide useful older packages, but it is not an exact match for the later save decision. See cache restoration.
The action restores the store before it runs install requests. Install execution then runs each normalized request in order. A cache miss does not stop installation because pnpm can fetch missing packages and add them to the store.
References: action.yml• L18-29 dist/index.js• L273
Post phase
Store cleanup
The post phase prunes the pnpm store only when the run requested at least one install command. This keeps the stored data smaller and avoids cleanup for runs that only provision pnpm. See store pruning.
Pruning is best effort. A prune error becomes a warning, so the post phase can still try to save useful dependency data.
References: dist/index.js• L273
Cache persistence
The post phase saves the store under the current primary key when restoration did not use that exact key. This turns a miss or older prefix match into a cache for the current dependency inputs. An exact match skips the save because that cache already represents those inputs. See cache persistence.
Cache saving depends on the cache input. A save error fails the post phase. An unavailable or unused cache does not change the rest of the run.
References: action.yml• L18-25 dist/index.js• L273
Job interface
Reported outputs
After pnpm provisioning succeeds, the action publishes the expanded destination and the directory that contains the usable pnpm and pnpx commands. Later workflow steps can use these values when they need an explicit command path. The declared outputs are dest and bin_dest; cache match status remains internal to the save decision. See action outputs.
The command path points to the selected pnpm version rather than only the bootstrap copy. The runtime publishes the final command directory after provisioning selects that version.
References: action.yml• L34-38 dist/index.js• L273
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the action.yml main and post declarations aligned with the two-phase behavior in dist/index.js.
- Keep the state names written during cache restoration aligned with the names read during cache persistence.
- When changing the pnpm command path, check both the job
PATHand thebin_destoutput. They must use the same requested version. - When changing dependency-file inputs or cache-key rules, check exact-match handling and saving after a prefix restore.
- When changing install options, check the post-phase condition that decides whether store pruning runs.
- When changing pnpm version discovery or standalone rules, check the action input description and the bundled runtime together.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| No pnpm version is supplied and the package file has no supported pnpm declaration. | Provisioning fails. The main phase does not publish outputs or run installs. | Run checkout before this action or set version explicitly. |
| The action input and package file specify different pnpm versions. | Provisioning stops with a version mismatch error. | Keep one source of truth for the pnpm version. |
| A configured dependency path does not produce a file hash. | Cache restoration fails before dependency installation. | Point cache_dependency_path at files present in the workspace. |
| A restored cache matches only the platform prefix. | Installation can use older store data. The post phase saves under the new primary key. | Treat only an exact primary-key match as a complete cache match. |
| An install request exits with an error. | The action marks the run as failed, although it checks later normalized requests. | Review the request, working directory, and its arguments. |
Key files
| File | Why to read it |
|---|---|
| action.yml | Defines the GitHub Action entrypoint, inputs, outputs, Node.js runtime, and main/post phases. |
| dist/index.js | Provides the bundled runtime that coordinates provisioning, install work, cleanup, cache handling, and output publication. |
| src/…/index.ts | Defines the normalized settings passed through the run. |
| src/…/run.ts | Explains how the selected pnpm command becomes available to later phases. |
| src/…/index.ts | Shows how normalized install requests become job commands. |
| src/…/run.ts | Defines the store location, cache key, and exact-match rule. |
| src/…/run.ts | Defines when the post phase writes a new cache. |
| src/…/index.ts | Defines when post-phase store cleanup runs and how cleanup errors are handled. |
| src/…/index.ts | Defines the values exposed to later workflow steps. |