Skip to content

Commit b1cac37

Browse files
committed
feat: add install input to opt out of auto pnpm install
The action runs `pnpm install` by default when a package.json is present. Set `install: false` to skip it — useful for jobs that only need pnpm itself (e.g. `pnpm audit`, lockfile-only regeneration).
1 parent c4ced00 commit b1cac37

6 files changed

Lines changed: 134 additions & 66 deletions

File tree

.github/workflows/test.yaml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,44 @@ jobs:
281281
esac
282282
shell: bash
283283

284+
install-false:
285+
# `install: false` skips the auto-install step even though a manifest is
286+
# present.
287+
name: 'install: false skips pnpm install'
288+
runs-on: ubuntu-latest
289+
steps:
290+
- uses: actions/checkout@v6
291+
292+
- name: Set up package.json with a dependency
293+
run: |
294+
rm -f pnpm-lock.yaml
295+
cat > package.json <<'EOF'
296+
{
297+
"packageManager": "pnpm@11.1.0",
298+
"dependencies": {
299+
"is-odd": "3.0.1"
300+
}
301+
}
302+
EOF
303+
shell: bash
304+
305+
- uses: ./
306+
with:
307+
version: '11.1.0'
308+
install: false
309+
310+
- name: 'Test: node_modules was not populated'
311+
run: |
312+
set -e
313+
if [ -d node_modules/is-odd ]; then
314+
echo "Expected install: false to skip pnpm install, but node_modules/is-odd exists"
315+
exit 1
316+
fi
317+
# pnpm itself should still be on PATH.
318+
which pnpm
319+
pnpm --version
320+
shell: bash
321+
284322
no-runtime:
285323
# No runtime input, no devEngines.runtime. Action installs pnpm only and
286324
# leaves the runtime outputs empty. With no package.json, `pnpm install`

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ If your `package.json` declares `devEngines.runtime`, the action picks up the ru
1616
| `cache` | Cache the pnpm store directory. Default: `false`. |
1717
| `cache-dependency-path` | Path(s) to the pnpm lockfile, used to compute the cache key. Default: `pnpm-lock.yaml`. |
1818
| `package-json-file` | Path to `package.json` (relative to `GITHUB_WORKSPACE`). Default: `package.json`. |
19+
| `install` | Run `pnpm install` after setup. Default: `true`. Set to `false` for jobs that only need pnpm itself (e.g. `pnpm audit`, lockfile-only regeneration). |
1920

2021
## Outputs
2122

@@ -90,12 +91,23 @@ jobs:
9091
cache: true
9192
```
9293

94+
### Skip `pnpm install`
95+
96+
For jobs that only need pnpm itself — e.g. `pnpm audit`, lockfile-only regeneration — set `install: false`:
97+
98+
```yaml
99+
- uses: pnpm/setup@v0
100+
with:
101+
install: false
102+
- run: pnpm audit
103+
```
104+
93105
## How it works
94106

95107
1. The action installs `@pnpm/exe` (a Node.js-bundled standalone build of pnpm) into `dest`, then self-updates to the requested pnpm version.
96108
2. `PNPM_HOME` is exported and `$PNPM_HOME/bin` is added to `PATH`.
97109
3. The action runs `pnpm runtime set <name> <version> -g`, which downloads the requested runtime into `$PNPM_HOME/bin` — making `node`, `bun`, or `deno` available to later workflow steps.
98-
4. If a `package.json` exists in the workspace, the action runs `pnpm install`. When the `runtime` input is set, `--no-runtime` is appended so the just-installed runtime isn't shadowed by a different version declared in `devEngines.runtime`. This flag requires pnpm ≥ 11.1.0.
110+
4. If a `package.json` exists in the workspace, the action runs `pnpm install` (unless `install: false` is set). When the `runtime` input is set, `--no-runtime` is appended so the just-installed runtime isn't shadowed by a different version declared in `devEngines.runtime`. This flag requires pnpm ≥ 11.1.0.
99111

100112
## License
101113

action.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,20 @@ inputs:
3838
description: File path to the package.json to read `packageManager` and `devEngines.runtime` configuration. This path must be relative to the repository root (GITHUB_WORKSPACE).
3939
required: false
4040
default: 'package.json'
41+
install:
42+
description: |
43+
Whether to run `pnpm install` after pnpm and the runtime are set up.
44+
45+
When set to `true` (the default), the action runs `pnpm install` in the
46+
workspace when a package.json is present. When the `runtime` input is
47+
also set, `--no-runtime` is appended automatically so the installed
48+
runtime isn't shadowed by a different version declared in
49+
`devEngines.runtime`.
50+
51+
Set to `false` to skip the install step — useful for jobs that only
52+
need pnpm itself (e.g. `pnpm audit`, lockfile-only regeneration).
53+
required: false
54+
default: 'true'
4155
outputs:
4256
dest:
4357
description: Expanded path of inputs#dest

dist/index.js

Lines changed: 64 additions & 64 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ async function runMain() {
3838

3939
await restoreCache(inputs)
4040

41-
pnpmInstall(inputs)
41+
if (inputs.install) {
42+
pnpmInstall(inputs)
43+
}
4244
}
4345

4446
async function runPost() {

src/inputs/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export interface Inputs {
1717
readonly cacheDependencyPath: string
1818
readonly packageJsonFile: string
1919
readonly runtime?: RuntimeInput
20+
readonly install: boolean
2021
}
2122

2223
const options: InputOptions = {
@@ -56,6 +57,7 @@ export const getInputs = (): Inputs => ({
5657
cacheDependencyPath: parseInputPath('cache-dependency-path'),
5758
packageJsonFile: parseInputPath('package-json-file'),
5859
runtime: parseRuntime(),
60+
install: getBooleanInput('install'),
5961
})
6062

6163
export default getInputs

0 commit comments

Comments
 (0)