Compare commits

...

115 Commits
v2.0.0 ... next

Author SHA1 Message Date
Zoltan Kochan
0ffe724fa5 feat: support standalone mode with @pnpm/exe bootstrap
- When standalone=true, bootstrap with @pnpm/exe via npm ci
- When standalone=false, bootstrap with pnpm via npm ci
- Both use pnpm self-update to reach the target version
- Remove --ignore-scripts from npm ci so @pnpm/exe install scripts run
- Add standalone test back to CI

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-16 02:29:31 +01:00
Zoltan Kochan
a722bd2d87 refactor: use pnpm self-update instead of installing target separately
- Bootstrap pnpm via npm ci (verified by lockfile)
- Use `pnpm self-update <version>` for explicit version
- Let pnpm handle packageManager field automatically
- Remove standalone/exe-specific install logic (pnpm handles this)
- Update tests to not run pnpm install against the action repo itself

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-16 02:24:28 +01:00
Zoltan Kochan
49b8837b49 fix: run bootstrap pnpm via node instead of bin shim
Use `node .../pnpm/bin/pnpm.cjs` to run the bootstrap pnpm, matching
the approach used by the old bundled pnpm.cjs. This avoids issues with
the .bin symlink on different platforms.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-16 02:15:16 +01:00
Zoltan Kochan
9fbc6cd1d1 fix: use --no-lockfile for target install
--lockfile-dir pointing to GITHUB_WORKSPACE causes the bootstrap pnpm
to use the project's pnpm-lock.yaml (which tracks project deps, not
pnpm itself), corrupting the install. Revert to --no-lockfile for now.
Lockfile-based integrity verification can be added when pnpm v11 has
proper support for verifying the pnpm package itself.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-16 02:06:14 +01:00
Zoltan Kochan
af96d9fd0e fix: always use pnpm (not @pnpm/exe) for bootstrap and update lockfile
The bootstrap only needs regular pnpm to install the target package.
@pnpm/exe requires install scripts which we skip with --ignore-scripts.
Also regenerate pnpm-lock.yaml to match current package.json.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-16 02:02:44 +01:00
Zoltan Kochan
1fb299a44f fix: remove packageManager field and fix Windows npm spawn
- Remove packageManager from package.json to avoid version conflict
  when the action tests against itself (uses: ./)
- Use shell: true on Windows so spawn can find npm.cmd

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-16 01:58:24 +01:00
Zoltan Kochan
24a61aa18d fix: remove "type": "module" from package.json
Node.js treats dist/index.js as ESM due to "type": "module",
but the bundle uses CJS require() calls. Remove the field so
Node.js defaults to CJS for .js files.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-16 01:55:56 +01:00
Zoltan Kochan
ab0b84aeb1 fix: bundle as CJS to support @actions/* packages
The @actions/* packages use CJS require() for Node.js builtins,
which fails with "Dynamic require of 'os' is not supported" when
bundled as ESM. Switch esbuild output to CJS format.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-16 01:54:09 +01:00
Zoltan Kochan
dc312cdfd7 feat!: replace bundled pnpm binary with npm + lockfile bootstrap
Remove the 9MB bundled pnpm.cjs/worker.js and instead use npm ci with
committed package-lock.json files (~5KB) to install a bootstrap pnpm,
which then installs the target version with integrity verification via
the project's pnpm-lock.yaml.

Also switch from ncc to esbuild and modernize to ESM.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-16 01:52:34 +01:00
Zoltan Kochan
fc06bc1257 feat!: run the action on Node.js 24 (#205) 2026-03-13 11:30:26 +01:00
Zoltan Kochan
b906affcce Revert "feat!: run the action on Node.js 24 (#205)"
This reverts commit 9b5745cdf0.
2026-03-11 15:54:42 +01:00
Zoltan Kochan
9b5745cdf0 feat!: run the action on Node.js 24 (#205) 2026-02-17 13:30:54 +01:00
Boosted-Bonobo
1e1c8eafbd ci: pin github actions (#199) 2025-12-15 14:31:35 +01:00
Khải
b9e1dbc72f fix(ci): exclude macos (#197) 2025-12-10 13:54:29 +01:00
Khải
61bc82c7df refactor: remove star imports (#196) 2025-12-10 13:14:52 +01:00
Jeremiasz Major
e94b270858 feat: store caching (#188)
* add pnpm store caching

* style: format

* no semicolons
* no star imports
* import order

* style: no star imports

---------

Co-authored-by: khai96_ <hvksmr1996@gmail.com>
2025-12-07 22:16:49 +01:00
Chris Martin
ee7b8711bd Clarify that package_json_file is relative to GITHUB_WORKSPACE (#184)
* Clarify that package_json_file is relative to GITHUB_WORKSPACE

Clarify the description for package_json_file parameter to specify that the path must be relative to the repository root.

* Apply suggestion from @zkochan

---------

Co-authored-by: Zoltan Kochan <z@kochan.io>
2025-12-07 01:36:02 +01:00
silverwind
3a0024f066 Remove unused @types/node-fetch dependency (#186) 2025-12-05 16:50:59 +01:00
Roman Usherenko
72f04517b7 Update README.md (#175)
fix the string run_install example
2025-12-05 15:32:46 +01:00
Adrian Riedel
41ff726559 feat: support installation from custom NPM registry (#179)
copy .npmrc from GitHub workspace if it exists so that PNPM respects custom
registry configurations when self-installing
2025-10-08 10:48:14 +02:00
Matthias
f2b2b233b5 Remove --frozen-lockfile from examples (#171) 2025-07-11 00:08:35 +02:00
Matthias
77504a59bc Fix multiline run_install example in README.md (#167) 2025-06-25 18:10:02 +02:00
Kevin Cui
d648c2dd06 fix: not allow install multiple package manager (#161)
When a project has both npm and pnpm, using pnpm/action-setup will result in an error: `Multiple versions of pnpm specified`.

The previous implementation was only meant to avoid the "ERR_PNPM_BAD_PM_VERSION" error, but it did not take into account the situation of multiple different package managers.

Signed-off-by: Kevin Cui <bh@bugs.cc>
2025-03-28 08:37:14 +08:00
Zoltan Kochan
a7487c7e89 feat: update dist 2025-02-06 22:30:07 +01:00
Zoltan Kochan
fff70888d0 test: update pnpm to v9 2025-02-06 22:24:21 +01:00
Daniel Bayley
6e3017af18 docs: support package.yaml (#157) 2025-02-06 22:13:04 +01:00
Daniel Bayley
0cb0538c33 feat: support package.yaml (#156) 2025-02-06 22:04:41 +01:00
Azat S.
e303250a24 docs: update pnpm version in readme examples (#154) 2025-01-09 00:42:18 +01:00
Karl Horky
ac5bf11548 Update examples to use pnpm v9 (#142) 2024-08-14 16:07:48 +02:00
its-monotype
18ac635edf docs: remove redundant manual cache due to setup-node cache (#131) 2024-07-05 15:24:26 +02:00
Zoltan Kochan
0d0b43217a docs: add warning about v2 2024-07-05 14:37:28 +02:00
Karl Horky
0eb0e97082 Add readme example for omitting version (#134)
* Add readme example for omitting `version`

* docs: more detailed explanations

---------

Co-authored-by: Khải <hvksmr1996@gmail.com>
2024-07-04 10:37:24 +02:00
hyesung oh
23657c8550 docs: change order of setup node and pnpm (#129) 2024-06-16 14:33:23 +02:00
Linda_pp
5d79380f29 fix: add missing outputs metadata to action.yml (#127) 2024-06-12 16:45:37 +02:00
Ben McCann
562dbbf611 fix: correct typo in error message (#125) 2024-06-12 16:44:03 +02:00
Ben McCann
00884bcdc5 docs: use cached pnpm installation (#128) 2024-06-12 16:38:46 +02:00
Zoltan Kochan
fe02b34f77 docs: bump action-setup version in README 2024-05-07 15:16:48 +02:00
Karl Horky
bee1f099e5 feat: throw error when multiple versions specified (#122)
* Throw error when multiple versions specified

* fix: fmt

* fix: fmt

* Swallow error on ENOENT

* Match versions

* refactor: install pnpm

---------

Co-authored-by: Khải <hvksmr1996@gmail.com>
Co-authored-by: Zoltan Kochan <z@kochan.io>
2024-05-06 23:24:46 +02:00
Sukka
ce859e384f refactor: replace fs-extra with Node.js built-in fs methods (#120) 2024-04-16 11:26:31 +02:00
Zoltan Kochan
2ab6dce4f5 docs(README): fix link to LICENSE 2024-03-27 22:17:57 +01:00
Ethan Neff
e280758d01 docs(README): update dependency versions (#117) 2024-03-27 22:12:51 +01:00
dependabot[bot]
129abb77bf Bump undici from 5.28.2 to 5.28.3 (#115)
Bumps [undici](https://github.com/nodejs/undici) from 5.28.2 to 5.28.3.
- [Release notes](https://github.com/nodejs/undici/releases)
- [Commits](https://github.com/nodejs/undici/compare/v5.28.2...v5.28.3)

---
updated-dependencies:
- dependency-name: undici
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-02-17 10:59:33 +01:00
Zoltan Kochan
a3252b78c4 docs(README): update version 2024-02-08 11:28:50 +01:00
Erik Burton
1ee9c9d01d feat!: node20 upgrade (#110)
* upgrade versions to latest

* remove usage of ts-schema-autogen

* fix: update pnpm sources

* update build/output

* use node20

* fix: run-install array output

* fix: maintain behaviour for parseRunInstall, error messages

* fix: another edge case for input.args

* fix: use zod for input validation

* fix: use zod.infer for exported RunInstall types

* fix: remove @types/js-yaml

---------

Co-authored-by: Zoltan Kochan <z@kochan.io>
2024-02-08 11:22:15 +01:00
dependabot[bot]
ebcfd6995d Bump actions/setup-node from 3 to 4 (#103)
Bumps [actions/setup-node](https://github.com/actions/setup-node) from 3 to 4.
- [Release notes](https://github.com/actions/setup-node/releases)
- [Commits](https://github.com/actions/setup-node/compare/v3...v4)

---
updated-dependencies:
- dependency-name: actions/setup-node
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-10 21:58:17 +02:00
Steven Yung
d2613e087f docs: update pnpm version in caching example (#94) 2023-09-27 19:17:23 +03:00
dependabot[bot]
d928be8e0c Bump actions/checkout from 3 to 4 (#96)
Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 4.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v3...v4)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-09-27 19:17:06 +03:00
Khải
d882d12c64 feat: standalone binary (#92)
* feat: add an option to install the self-contained binary version of pnpm

* test: add a test about nodejs_bundled

* style: remove an empty line

* chore: use newer pnpm

* chore: update dependencies

* feat: rename `nodejs_bundled` to `standalone`

as @zkochan suggested

* docs: add

---------

Co-authored-by: Takashi Sato <takashi@tks.st>
2023-07-26 14:50:04 +03:00
Khải
0b715c7ebb Merge pull request #75 from ojeytonwilliams/fix/caching-example
docs: update the caching example
2023-07-25 17:00:41 +07:00
Khải
2ed49cbb02 Merge pull request #88 from KengoTODA/make-path-configurable
support projects that have package.json in non-root directory
2023-07-25 16:59:00 +07:00
Khải
218cb35941 Merge pull request #69 from zakuro9715/zakuro9715-patch-2
Remove corepack url in error message
2023-07-25 14:16:42 +07:00
Khải
3723f63bb4 Merge pull request #90 from pnpm/optional-version
feat: make version actually optional
2023-07-25 14:05:04 +07:00
khai96_
849d884800 feat: make version actually optional
closes https://github.com/pnpm/action-setup/issues/85
2023-07-25 14:01:28 +07:00
khai96_
f92eb0edb6 docs: update pnpm version in readme
fixes https://github.com/pnpm/action-setup/issues/89
2023-07-25 13:50:35 +07:00
Kengo TODA
b27f801bf9 feat: add package_json_file option
Signed-off-by: Kengo TODA <skypencil@gmail.com>
2023-07-08 07:02:46 +08:00
Khải
11dd14d0c0 Change sponsor to pnpm's opencollective 2023-04-22 17:39:01 +07:00
Oliver Eyton-Williams
61eb8c655a docs: update the caching example 2023-03-08 00:13:47 +01:00
zakuro
65db188e28 Remove corepack url in error message 2022-11-09 06:54:12 +09:00
Khải
0609f0983b Merge pull request #66 from mrienstra/patch-1
docs: drop minor & patch version from examples
2022-11-02 12:09:43 +07:00
Michael Rienstra
7208fa2733 docs: drop minor & patch version from examples 2022-11-01 21:55:20 -07:00
Khải
1bd00a2972 Merge pull request #64 from mrienstra/patch-1
typo: not latest version
2022-10-26 10:32:07 +07:00
Michael Rienstra
d5601fb603 bump first occurrence of actions/checkout to v3 2022-10-25 10:52:54 -07:00
Michael Rienstra
bc06aa6030 typo: not latest version 2022-10-25 10:42:24 -07:00
Khải
cd2af74528 Merge pull request #62 from melMass/mel/fix-readme
fix: ️ cross-platform example
2022-10-18 17:29:18 +07:00
Mel Massadian
c8a150e137 fix: ️ just use shell:bash
set-output is deprecated see #58
2022-10-18 12:23:15 +02:00
Mel Massadian
ed0172a253 fix: ️ cross-platform example 2022-10-18 12:02:38 +02:00
Zoltan Kochan
c3b53f6a16 chore(release): 2.2.4 2022-10-15 21:12:50 +03:00
Zoltan Kochan
21e88da200 fix(deps): update 2022-10-15 21:12:13 +03:00
Zoltan Kochan
fc3334fa11 build 2022-10-15 21:09:00 +03:00
Sébastien Vanvelthem
d01953a678 Update action/core to 1.10.0 to fix deprecation warnings (#59)
* chore: update action/core to 1.10.0

* chore(lock): freshen
2022-10-15 20:57:21 +03:00
Khải
3360b50db7 Merge pull request #58 from belgattitude/doc-adapt-to-new-github-env
Doc update to account for deprecated `set-output`.
2022-10-13 22:23:23 +07:00
Sébastien Vanvelthem
6f9e9a867a docs: update to new github env 2022-10-13 16:58:06 +02:00
Khải
537643d491 Merge pull request #56 from i7eo/master
chore: bump node version
2022-10-11 11:58:06 +07:00
George Tan
f4129fb46e fix
Update node version, see https://github.blog/changelog/2022-09-22-github-actions-all-actions-will-begin-running-on-node16-instead-of-node12/
2022-10-11 10:56:24 +08:00
Lew Blood
6e1964dde3 Fix spacing issue in README.md example (#48) 2022-06-17 23:17:05 +03:00
Zoltan Kochan
10693b3829 Update action.yml 2022-05-28 17:23:43 +03:00
Zoltan Kochan
99ecd24520 v2.2.2 2022-05-28 17:22:28 +03:00
Zoltan Kochan
958500fcab fix: do not download pnpm from get.pnpm.io (#46)
* fix: do not download pnpm from get.pnpm.io

* fix: remove redundant files
2022-05-28 16:54:43 +03:00
Khải
57b9359b4c Merge pull request #41 from nelson6e65/patch-1
docs(readme): improve Cache example
2022-05-07 10:00:37 +07:00
Khải
ec1a8b444c Change runs-on back to ubuntu-latest 2022-05-07 09:59:56 +07:00
Nelson Martell
73e15250cb docs(readme): improve and fix cache example
Dynamically detect the Store directory and use the latest GitHub actions.
2022-05-06 21:57:00 -05:00
Khải
10b4b0b462 Merge pull request #36 from pnpm/dependabot/github_actions/actions/checkout-3
Bump actions/checkout from 2 to 3
2022-03-08 10:33:01 +07:00
Khải
5fa8980bf4 Update dependabot.yml 2022-03-08 10:32:48 +07:00
dependabot[bot]
ae78e9abbe Bump actions/checkout from 2 to 3
Bumps [actions/checkout](https://github.com/actions/checkout) from 2 to 3.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v2...v3)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-03-07 23:02:26 +00:00
Jack Works
35ab4267a1 fix: packageManager reader (#35)
* fix: packageManager reader

* chore: resolve review

* chore: run build
2022-02-25 12:43:26 +08:00
khai96_
11ba3424e0 fmt 2022-02-23 10:07:15 +07:00
Khải
847a737d63 Merge pull request #33 from pnpm/packageManager
feat: try support packageManager
2022-02-22 16:39:23 +07:00
Zoltan Kochan
225f3bb4b0 build 2022-02-22 11:34:20 +02:00
Zoltan Kochan
777a50d72e Update src/install-pnpm/run.ts 2022-02-22 11:32:59 +02:00
khai96_
e7c10c6fc5 Update dist/index.js 2022-02-22 13:04:41 +07:00
Jack Works
a576a70bc6 chore: resolve review 2022-02-22 13:37:35 +08:00
Jack Works
1d51e20937 feat: try support packageManager 2022-02-22 12:26:05 +08:00
Khải
ad2b35ae0c Merge pull request #32 from pnpm/retry-fetch
fix: retry fetch of pnpm script
2022-02-21 10:28:16 +07:00
Zoltan Kochan
d8ea532ac4 fix: retry fetch of pnpm script
close #22
2022-02-20 21:49:26 +02:00
khai96_
2270f39ef6 v2.1.0 2022-02-08 19:53:18 +07:00
khai96_
394c848db6 Update the bundle 2022-02-08 19:50:57 +07:00
Khải
e13928ccc5 Merge pull request #27 from metonym/fix-jobs-syntax
Specify job name to fix syntax error
2022-02-08 19:48:36 +07:00
Khải
93bd5a123d Merge pull request #29 from pnpm/pnpm-v7
The pnpm home directory should be added to PATH and PNPM_HOME
2022-02-08 19:47:28 +07:00
Zoltan Kochan
9eb14dd77c decrease bundle size 2022-02-08 14:44:50 +02:00
Zoltan Kochan
eafb777c56 download script from pnpm.io 2022-02-08 00:39:20 +02:00
Zoltan Kochan
e6378df420 PNPM_HOME_PATH=>PNPM_HOME 2022-02-08 00:21:53 +02:00
Zoltan Kochan
6ff6e97bc6 The pnpm home directory should be added to PATH and PNPM_HOME
This change is needed to make the action compatible with pnpm v7.

Related breaking change in pnpm: pnpm/pnpm#4280
2022-02-07 23:15:44 +02:00
Eric Liu
45d9c91ff6 Specify job name to fix syntax error 2022-01-29 08:17:29 -08:00
Khải
15569a497d Merge pull request #26 from ai/patch-1
Improve `version` docs
2021-12-16 21:20:06 +07:00
Andrey Sitnik
d70eebd14a Update README.md
Co-authored-by: Khải <hvksmr1996@gmail.com>
2021-12-16 17:18:46 +03:00
Andrey Sitnik
3bf8acf16f Improve version docs 2021-12-16 17:12:07 +03:00
Khải
3c2fe8c592 Merge pull request #21 from gaggle/patch-1
Spelling
2021-10-12 19:45:45 +07:00
Jon Lauridsen
76cc04cd5e Spelling 2021-10-12 13:34:10 +02:00
Khải
bcad811784 Remove unused env from examples 2021-07-24 08:25:23 +07:00
Khải
602b36f177 Remove uses of undefined variables from examples 2021-07-24 08:22:22 +07:00
Khải
74a0fdc1a4 Merge pull request #14 from Jack-Works-forks/master
Update README: use lockfile hash instead of package.json hash
2021-06-01 09:44:13 +07:00
Jack Works
493e98ec5e Update README.md 2021-06-01 10:42:26 +08:00
khai96_
646cdf4821 Update versions in README examples to the latest 2021-04-24 21:13:36 +07:00
Khải
a1ba6cf5ae Merge pull request #11 from pnpm/zkochan-patch-1
docs(readme): PNPM=>pnpm
2021-03-27 18:50:58 +07:00
Zoltan Kochan
41b381a08b docs(readme): PNPM=>pnpm 2021-03-27 13:45:01 +02:00
26 changed files with 1887 additions and 1094 deletions

14
.github/FUNDING.yml vendored
View File

@@ -1,12 +1,2 @@
# These are supported funding model platforms custom:
- https://opencollective.com/pnpm
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: khai96_
open_collective: # Collective unavailable
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # disabled
otechie: # Replace with a single Otechie username
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']

View File

@@ -5,6 +5,3 @@ updates:
schedule: schedule:
interval: weekly interval: weekly
open-pull-requests-limit: 10 open-pull-requests-limit: 10
labels:
- dependabot
- github-actions

View File

@@ -15,28 +15,36 @@ jobs:
fail-fast: false fail-fast: false
matrix: matrix:
pnpm: pnpm:
- 4.11.1 - 9.15.5
os: os:
- ubuntu-latest - ubuntu-latest
- macos-latest - macos-latest
- windows-latest - windows-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
- name: Run the action - name: Run the action
uses: ./ uses: ./
with: with:
version: 4.11.1 version: 9.15.5
- name: 'Test: which' - name: 'Test: which'
run: which pnpm; which pnpx run: which pnpm; which pnpx
- name: 'Test: install' - name: 'Test: version'
run: pnpm install run: pnpm --version
test_explicit_inputs: - name: 'Test: install in a fresh project'
name: Test with explicit inputs run: |
mkdir /tmp/test-project
cd /tmp/test-project
pnpm init
pnpm add is-odd
shell: bash
test_dest:
name: Test with dest
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
@@ -44,26 +52,61 @@ jobs:
fail-fast: false fail-fast: false
matrix: matrix:
pnpm: pnpm:
- 4.11.1 - 9.15.5
os: os:
- ubuntu-latest - ubuntu-latest
- macos-latest - macos-latest
- windows-latest - windows-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
- name: Run the action - name: Run the action
uses: ./ uses: ./
with: with:
version: 4.11.1 version: 9.15.5
dest: ~/test/pnpm dest: ~/test/pnpm
- name: 'Test: which' - name: 'Test: which'
run: which pnpm && which pnpx run: which pnpm && which pnpx
- name: 'Test: install' - name: 'Test: version'
run: pnpm install run: pnpm --version
test_standalone:
name: Test with standalone
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- windows-latest
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
- name: Run the action
uses: ./
with:
version: 9.15.0
standalone: true
- name: 'Test: which'
run: which pnpm
- name: 'Test: version'
run: pnpm --version
- name: 'Test: install in a fresh project'
run: |
mkdir /tmp/test-standalone
cd /tmp/test-standalone
pnpm init
pnpm add is-odd
shell: bash
test_run_install: test_run_install:
name: 'Test with run_install (${{ matrix.run_install.name }}, ${{ matrix.os }})' name: 'Test with run_install (${{ matrix.run_install.name }}, ${{ matrix.os }})'
@@ -74,7 +117,7 @@ jobs:
fail-fast: false fail-fast: false
matrix: matrix:
pnpm: pnpm:
- 4.11.1 - 9.15.5
os: os:
- ubuntu-latest - ubuntu-latest
- macos-latest - macos-latest
@@ -82,11 +125,6 @@ jobs:
run_install: run_install:
- name: 'null' - name: 'null'
value: 'null' value: 'null'
- name: 'empty object'
value: '{}'
- name: 'recursive'
value: |
recursive: true
- name: 'global' - name: 'global'
value: | value: |
args: args:
@@ -94,29 +132,18 @@ jobs:
- --global-dir=./pnpm-global - --global-dir=./pnpm-global
- npm - npm
- yarn - yarn
- pnpm
- name: 'array'
value: |
- {}
- recursive: true
- args:
- --global
- --global-dir=./pnpm-global
- npm
- yarn
- pnpm
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
- name: Run the action - name: Run the action
uses: ./ uses: ./
with: with:
version: 4.11.1 version: 9.15.5
run_install: ${{ matrix.run_install.value }} run_install: ${{ matrix.run_install.value }}
- name: 'Test: which' - name: 'Test: which'
run: which pnpm; which pnpx run: which pnpm; which pnpx
- name: 'Test: install' - name: 'Test: version'
run: pnpm install run: pnpm --version

120
README.md
View File

@@ -1,16 +1,24 @@
# Setup PNPM > ## :warning: Upgrade from v2!
>
> The v2 version of this action [has stopped working](https://github.com/pnpm/action-setup/issues/135) with newer Node.js versions. Please, upgrade to the latest version to fix any issues.
Install PNPM package manager. # Setup pnpm
Install pnpm package manager.
## Inputs ## Inputs
### `version` ### `version`
**Required** Version of PNPM to install. Version of pnpm to install.
**Optional** when there is a [`packageManager` field in the `package.json`](https://nodejs.org/api/corepack.html).
otherwise, this field is **required** It supports npm versioning scheme, it could be an exact version (such as `6.24.1`), or a version range (such as `6`, `6.x.x`, `6.24.x`, `^6.24.1`, `*`, etc.), or `latest`.
### `dest` ### `dest`
**Optional** Where to store PNPM files. **Optional** Where to store pnpm files.
### `run_install` ### `run_install`
@@ -32,7 +40,25 @@ If `run_install` is a YAML string representation of either an object or an array
#### `run_install.args` #### `run_install.args`
**Optional** (_type:_ `string[]`) Additional arguments after `pnpm [recursive] install`, e.g. `[--frozen-lockfile, --strict-peer-dependencies]`. **Optional** (_type:_ `string[]`) Additional arguments after `pnpm [recursive] install`, e.g. `[--ignore-scripts, --strict-peer-dependencies]`.
### `cache`
**Optional** (_type:_ `boolean`, _default:_ `false`) Whether to cache the pnpm store directory.
### `cache_dependency_path`
**Optional** (_type:_ `string|string[]`, _default:_ `pnpm-lock.yaml`) File path to the pnpm lockfile, which contents hash will be used as a cache key.
### `package_json_file`
**Optional** (_type:_ `string`, _default:_ `package.json`) File path to the `package.json`/[`package.yaml`](https://github.com/pnpm/pnpm/pull/1799) to read "packageManager" configuration.
### `standalone`
**Optional** (_type:_ `boolean`, _default:_ `false`) When set to true, [@pnpm/exe](https://www.npmjs.com/package/@pnpm/exe), which is a Node.js bundled package, will be installed, enabling using `pnpm` without Node.js.
This is useful when you want to use a incompatible pair of Node.js and pnpm.
## Outputs ## Outputs
@@ -46,7 +72,9 @@ Location of `pnpm` and `pnpx` command.
## Usage example ## Usage example
### Just install PNPM ### Install only pnpm without `packageManager`
This works when the repo either doesn't have a `package.json` or has a `package.json` but it doesn't specify `packageManager`.
```yaml ```yaml
on: on:
@@ -54,15 +82,18 @@ on:
- pull_request - pull_request
jobs: jobs:
runs-on: ubuntu-latest install:
runs-on: ubuntu-latest
steps: steps:
- uses: pnpm/action-setup@v1.2.1 - uses: pnpm/action-setup@v4
with: with:
version: 5.17.2 version: 10
``` ```
### Install PNPM and a few NPM packages ### Install only pnpm with `packageManager`
Omit `version` input to use the version in the [`packageManager` field in the `package.json`](https://nodejs.org/api/corepack.html).
```yaml ```yaml
on: on:
@@ -70,18 +101,34 @@ on:
- pull_request - pull_request
jobs: jobs:
runs-on: ubuntu-latest install:
runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: pnpm/action-setup@v4
```
- uses: pnpm/action-setup@v1.2.1 ### Install pnpm and a few npm packages
with:
version: 5.17.2 ```yaml
run_install: | on:
- recursive: true - push
args: [--frozen-lockfile, --strict-peer-dependencies] - pull_request
- args: [--global, gulp, prettier, typescript]
jobs:
install:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with:
version: 10
run_install: |
- recursive: true
args: [--strict-peer-dependencies]
- args: [--global, gulp, prettier, typescript]
``` ```
### Use cache to reduce installation time ### Use cache to reduce installation time
@@ -92,26 +139,21 @@ on:
- pull_request - pull_request
jobs: jobs:
runs-on: ubuntu-latest cache-and-install:
runs-on: ubuntu-latest
steps: steps:
build: - name: Checkout
- uses: actions/checkout@v2 uses: actions/checkout@v4
- name: Cache pnpm modules - uses: pnpm/action-setup@v4
uses: actions/cache@v2 name: Install pnpm
env:
cache-name: cache-pnpm-modules
with: with:
path: ~/.pnpm-store version: 10
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ matrix.node-version }}-${{ hashFiles('**/package.json') }} cache: true
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-${{ matrix.node-version }}-
- uses: pnpm/action-setup@v1.2.1 - name: Install dependencies
with: run: pnpm install
version: 5.17.2
run_install: true
``` ```
**Note:** You don't need to run `pnpm store prune` at the end; post-action has already taken care of that. **Note:** You don't need to run `pnpm store prune` at the end; post-action has already taken care of that.
@@ -122,4 +164,4 @@ This action does not setup Node.js for you, use [actions/setup-node](https://git
## License ## License
[MIT](https://git.io/JfclH) © [Hoàng Văn Khải](https://github.com/KSXGitHub/) [MIT](https://github.com/pnpm/action-setup/blob/master/LICENSE.md) © [Hoàng Văn Khải](https://github.com/KSXGitHub/)

View File

@@ -1,21 +1,42 @@
name: Setup PNPM name: Setup pnpm
description: Install PNPM package manager description: Install pnpm package manager
branding: branding:
icon: package icon: package
color: orange color: orange
inputs: inputs:
version: version:
description: Version of PNPM to install description: Version of pnpm to install
required: true required: false
dest: dest:
description: Where to store PNPM files description: Where to store pnpm files
required: false required: false
default: ~/setup-pnpm default: ~/setup-pnpm
run_install: run_install:
description: If specified, run `pnpm install` description: If specified, run `pnpm install`
required: false required: false
default: 'null' default: 'null'
cache:
description: Whether to cache the pnpm store directory
required: false
default: 'false'
cache_dependency_path:
description: File path to the pnpm lockfile, which contents hash will be used as a cache key
required: false
default: 'pnpm-lock.yaml'
package_json_file:
description: File path to the package.json to read "packageManager" configuration. This path must be relative to the repository root (GITHUB_WORKSPACE).
required: false
default: 'package.json'
standalone:
description: When set to true, @pnpm/exe, which is a Node.js bundled package, will be installed, enabling using pnpm without Node.js.
required: false
default: 'false'
outputs:
dest:
description: Expanded path of inputs#dest
bin_dest:
description: Location of `pnpm` and `pnpx` command
runs: runs:
using: node12 using: node24
main: dist/index.js main: dist/index.js
post: dist/index.js post: dist/index.js

290
dist/index.js vendored

File diff suppressed because one or more lines are too long

View File

@@ -1,27 +1,23 @@
{ {
"private": true, "private": true,
"scripts": { "scripts": {
"build:schemas": "ts-schema-autogen generate", "build:bundle": "esbuild src/index.ts --bundle --platform=node --target=node24 --format=cjs --minify --outfile=dist/index.js --loader:.json=json",
"build:ncc": "ncc build --minify --no-source-map-register --no-cache dist/tsc/index.js --out dist/", "build": "pnpm run build:bundle",
"build": "pnpm run build:schemas && tsc && pnpm run build:ncc",
"start": "pnpm run build && sh ./run.sh" "start": "pnpm run build && sh ./run.sh"
}, },
"dependencies": { "dependencies": {
"node-fetch": "^2.6.1", "@actions/cache": "^4.1.0",
"@actions/core": "^1.10.1",
"@actions/exec": "^1.1.1",
"@actions/glob": "^0.5.0",
"@types/expand-tilde": "^2.0.2",
"@types/node": "^22.0.0",
"expand-tilde": "^2.0.2", "expand-tilde": "^2.0.2",
"js-yaml": "^4.0.0", "yaml": "^2.3.4",
"ajv": "^6.12.5", "zod": "^3.22.4"
"fs-extra": "^9.1.0",
"@actions/core": "^1.2.6",
"@types/expand-tilde": "^2.0.0",
"@types/node-fetch": "^2.5.8",
"@types/js-yaml": "^4.0.0",
"@types/fs-extra": "^9.0.8",
"@types/node": "^14.14.35"
}, },
"devDependencies": { "devDependencies": {
"typescript": "^4.2.3", "esbuild": "^0.27.4",
"@ts-schema-autogen/cli": "^0.1.2", "typescript": "^5.3.3"
"@vercel/ncc": "^0.27.0"
} }
} }

1807
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

1
run.sh
View File

@@ -4,4 +4,5 @@ export HOME="$(pwd)"
export INPUT_VERSION=4.11.1 export INPUT_VERSION=4.11.1
export INPUT_DEST='~/pnpm.temp' export INPUT_DEST='~/pnpm.temp'
export INPUT_RUN_INSTALL=null export INPUT_RUN_INSTALL=null
export INPUT_standalone=false
exec node dist/index.js exec node dist/index.js

View File

@@ -0,0 +1,19 @@
import { isFeatureAvailable } from '@actions/cache'
import { endGroup, startGroup, warning } from '@actions/core'
import { Inputs } from '../inputs'
import { runRestoreCache } from './run'
export async function restoreCache(inputs: Inputs) {
if (!inputs.cache) return
if (!isFeatureAvailable()) {
warning('Cache is not available, skipping cache restoration')
return
}
startGroup('Restoring cache...')
await runRestoreCache(inputs)
endGroup()
}
export default restoreCache

39
src/cache-restore/run.ts Normal file
View File

@@ -0,0 +1,39 @@
import { restoreCache } from '@actions/cache'
import { debug, info, saveState, setOutput } from '@actions/core'
import { getExecOutput } from '@actions/exec'
import { hashFiles } from '@actions/glob'
import os from 'os'
import { Inputs } from '../inputs'
export async function runRestoreCache(inputs: Inputs) {
const cachePath = await getCacheDirectory()
saveState('cache_path', cachePath)
const fileHash = await hashFiles(inputs.cacheDependencyPath)
if (!fileHash) {
throw new Error('Some specified paths were not resolved, unable to cache dependencies.')
}
const primaryKey = `pnpm-cache-${process.env.RUNNER_OS}-${os.arch()}-${fileHash}`
debug(`Primary key is ${primaryKey}`)
saveState('cache_primary_key', primaryKey)
let cacheKey = await restoreCache([cachePath], primaryKey)
setOutput('cache-hit', Boolean(cacheKey))
if (!cacheKey) {
info(`Cache is not found`)
return
}
saveState('cache_restored_key', cacheKey)
info(`Cache restored from key: ${cacheKey}`)
}
async function getCacheDirectory() {
const { stdout } = await getExecOutput('pnpm store path --silent')
const cacheFolderPath = stdout.trim()
debug(`Cache folder is set to "${cacheFolderPath}"`)
return cacheFolderPath
}

15
src/cache-save/index.ts Normal file
View File

@@ -0,0 +1,15 @@
import { setFailed } from '@actions/core'
import { Inputs } from '../inputs'
import { runSaveCache } from './run'
export async function saveCache(inputs: Inputs) {
if (!inputs.cache) return
try {
await runSaveCache()
} catch (error) {
setFailed((error as Error).message)
}
}
export default saveCache

18
src/cache-save/run.ts Normal file
View File

@@ -0,0 +1,18 @@
import { saveCache } from '@actions/cache'
import { getState, info } from '@actions/core'
export async function runSaveCache() {
const state = getState('cache_restored_key')
const primaryKey = getState('cache_primary_key')
const cachePath = getState('cache_path')
if (primaryKey === state) {
info(`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`)
return
}
const cacheId = await saveCache([cachePath], primaryKey)
if (cacheId == -1) return
info(`Cache saved with the key: ${primaryKey}`)
}

View File

@@ -1,21 +1,39 @@
import { setFailed, saveState, getState } from '@actions/core' import { setFailed, saveState, getState } from '@actions/core'
import getInputs from './inputs' import restoreCache from './cache-restore'
import setOutputs from './outputs' import saveCache from './cache-save'
import getInputs, { Inputs } from './inputs'
import installPnpm from './install-pnpm' import installPnpm from './install-pnpm'
import setOutputs from './outputs'
import pnpmInstall from './pnpm-install' import pnpmInstall from './pnpm-install'
import pruneStore from './pnpm-store-prune' import pruneStore from './pnpm-store-prune'
async function main() { async function main() {
const inputs = getInputs() const inputs = getInputs()
const isPost = getState('is_post')
if (isPost === 'true') return pruneStore(inputs) if (getState('is_post') === 'true') {
await runPost(inputs)
} else {
await runMain(inputs)
}
}
async function runMain(inputs: Inputs) {
saveState('is_post', 'true') saveState('is_post', 'true')
await installPnpm(inputs) await installPnpm(inputs)
console.log('Installation Completed!') console.log('Installation Completed!')
setOutputs(inputs) setOutputs(inputs)
await restoreCache(inputs)
pnpmInstall(inputs) pnpmInstall(inputs)
} }
async function runPost(inputs: Inputs) {
pruneStore(inputs)
await saveCache(inputs)
}
main().catch(error => { main().catch(error => {
console.error(error) console.error(error)
setFailed(error) setFailed(error)

View File

@@ -1,11 +1,15 @@
import { getInput, InputOptions } from '@actions/core' import { getBooleanInput, getInput, InputOptions } from '@actions/core'
import expandTilde from 'expand-tilde' import expandTilde from 'expand-tilde'
import { RunInstall, parseRunInstall } from './run-install' import { RunInstall, parseRunInstall } from './run-install'
export interface Inputs { export interface Inputs {
readonly version: string readonly version?: string
readonly dest: string readonly dest: string
readonly cache: boolean
readonly cacheDependencyPath: string
readonly runInstall: RunInstall[] readonly runInstall: RunInstall[]
readonly packageJsonFile: string
readonly standalone: boolean
} }
const options: InputOptions = { const options: InputOptions = {
@@ -15,9 +19,13 @@ const options: InputOptions = {
const parseInputPath = (name: string) => expandTilde(getInput(name, options)) const parseInputPath = (name: string) => expandTilde(getInput(name, options))
export const getInputs = (): Inputs => ({ export const getInputs = (): Inputs => ({
version: getInput('version', options), version: getInput('version'),
dest: parseInputPath('dest'), dest: parseInputPath('dest'),
cache: getBooleanInput('cache'),
cacheDependencyPath: parseInputPath('cache_dependency_path'),
runInstall: parseRunInstall('run_install'), runInstall: parseRunInstall('run_install'),
packageJsonFile: parseInputPath('package_json_file'),
standalone: getBooleanInput('standalone'),
}) })
export default getInputs export default getInputs

View File

@@ -1,21 +0,0 @@
{
"$schema": "https://raw.githubusercontent.com/ksxnodeapps/ts-schema-autogen/master/packages/schemas/config.schema.json",
"instruction": {
"compilerOptions": {
"strict": true,
"target": "ES2018",
"lib": [
"ES2018",
"ES2019",
"ES2020",
"ESNext"
],
"moduleResolution": "Node",
"esModuleInterop": true,
"resolveJsonModule": true
},
"input": "run-install.ts",
"symbol": "RunInstallInput",
"output": "run-install-input.schema.json"
}
}

View File

@@ -1,39 +0,0 @@
{
"anyOf": [
{
"$ref": "#/definitions/RunInstall"
},
{
"type": "array",
"items": {
"$ref": "#/definitions/RunInstall"
}
},
{
"type": [
"null",
"boolean"
]
}
],
"definitions": {
"RunInstall": {
"type": "object",
"properties": {
"recursive": {
"type": "boolean"
},
"cwd": {
"type": "string"
},
"args": {
"type": "array",
"items": {
"type": "string"
}
}
}
}
},
"$schema": "http://json-schema.org/draft-07/schema#"
}

View File

@@ -1,39 +1,41 @@
import process from 'process' import { getInput, error } from '@actions/core'
import { load } from 'js-yaml' import { parse as parseYaml } from 'yaml'
import Ajv from 'ajv' import { z, ZodError } from 'zod'
import { getInput, error, InputOptions } from '@actions/core'
import runInstallSchema from './run-install-input.schema.json'
export interface RunInstall { const RunInstallSchema = z.object({
readonly recursive?: boolean recursive: z.boolean().optional(),
readonly cwd?: string cwd: z.string().optional(),
readonly args?: readonly string[] args: z.array(z.string()).optional(),
} })
export type RunInstallInput = const RunInstallInputSchema = z.union([
| null z.null(),
| boolean z.boolean(),
| RunInstall RunInstallSchema,
| RunInstall[] z.array(RunInstallSchema),
])
const options: InputOptions = { export type RunInstallInput = z.infer<typeof RunInstallInputSchema>
required: true, export type RunInstall = z.infer<typeof RunInstallSchema>
}
export function parseRunInstall(name: string): RunInstall[] { export function parseRunInstall(inputName: string): RunInstall[] {
const result: RunInstallInput = load(getInput(name, options)) as any const input = getInput(inputName, { required: true })
const ajv = new Ajv({ const parsedInput: unknown = parseYaml(input)
allErrors: true,
}) try {
const validate = ajv.compile(runInstallSchema) const result: RunInstallInput = RunInstallInputSchema.parse(parsedInput)
if (!validate(result)) { if (!result) return []
for (const errorItem of validate.errors!) { if (result === true) return [{ recursive: true }]
error(`with.run_install${errorItem.dataPath}: ${errorItem.message}`) if (Array.isArray(result)) return result
return [result]
} catch (exception: unknown) {
error(`Error for input "${inputName}" = ${input}`)
if (exception instanceof ZodError) {
error(`Errors: ${exception.errors}`)
} else {
error(`Exception: ${exception}`)
} }
return process.exit(1) process.exit(1)
} }
if (!result) return []
if (result === true) return [{ recursive: true }]
if (Array.isArray(result)) return result
return [result]
} }

View File

@@ -0,0 +1,147 @@
{
"name": "bootstrap-exe",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"dependencies": {
"@pnpm/exe": "10.32.1"
}
},
"node_modules/@pnpm/exe": {
"version": "10.32.1",
"resolved": "https://registry.npmjs.org/@pnpm/exe/-/exe-10.32.1.tgz",
"integrity": "sha512-baEtwHeZwmZAdBuuDDL6tbdGg5KpxhPxr3QFfYTGXvY6ws+Z1bN0mQ7ZjcaXBSC1HuLpVXnZ6NsBiaZ2DMv4vg==",
"hasInstallScript": true,
"license": "MIT",
"bin": {
"pnpm": "pnpm"
},
"funding": {
"url": "https://opencollective.com/pnpm"
},
"optionalDependencies": {
"@pnpm/linux-arm64": "10.32.1",
"@pnpm/linux-x64": "10.32.1",
"@pnpm/macos-arm64": "10.32.1",
"@pnpm/macos-x64": "10.32.1",
"@pnpm/win-arm64": "10.32.1",
"@pnpm/win-x64": "10.32.1"
}
},
"node_modules/@pnpm/linux-arm64": {
"version": "10.32.1",
"resolved": "https://registry.npmjs.org/@pnpm/linux-arm64/-/linux-arm64-10.32.1.tgz",
"integrity": "sha512-6uB0B+XvunQwHGzIMk2JCkl4Ur6BtM4XbJSwB/mgpWmXDoX/KTJmgx2lodcTjgJSGSySCHfIVuTR9sj/F2D4EA==",
"cpu": [
"arm64"
],
"license": "MIT",
"optional": true,
"os": [
"linux"
],
"bin": {
"pnpm": "pnpm"
},
"funding": {
"url": "https://opencollective.com/pnpm"
}
},
"node_modules/@pnpm/linux-x64": {
"version": "10.32.1",
"resolved": "https://registry.npmjs.org/@pnpm/linux-x64/-/linux-x64-10.32.1.tgz",
"integrity": "sha512-AM2tv23Fg7h+nV+adqA/SkZKUysSIEetHfBwYFl8ArgdgkqbGoQy0rAOdKYQBb920CqfexXfI8OA8kPCzRxYng==",
"cpu": [
"x64"
],
"license": "MIT",
"optional": true,
"os": [
"linux"
],
"bin": {
"pnpm": "pnpm"
},
"funding": {
"url": "https://opencollective.com/pnpm"
}
},
"node_modules/@pnpm/macos-arm64": {
"version": "10.32.1",
"resolved": "https://registry.npmjs.org/@pnpm/macos-arm64/-/macos-arm64-10.32.1.tgz",
"integrity": "sha512-Zr4JkhRbtGVsYgbuGZO0dq/6FPOn072Pdo0ubmqWtc14cUATKgAJD7efG03yqr3MLgtwFHgdtUzZ1WsaYAtUTA==",
"cpu": [
"arm64"
],
"license": "MIT",
"optional": true,
"os": [
"darwin"
],
"bin": {
"pnpm": "pnpm"
},
"funding": {
"url": "https://opencollective.com/pnpm"
}
},
"node_modules/@pnpm/macos-x64": {
"version": "10.32.1",
"resolved": "https://registry.npmjs.org/@pnpm/macos-x64/-/macos-x64-10.32.1.tgz",
"integrity": "sha512-Yk6q3oFDu//OniXJxfTSHo+aew1LX81FcbzJAtEkcCeTQ0SLbQT6J3QiOMNikp8n8IjNhsy+bn2bdkUxaw+akA==",
"cpu": [
"x64"
],
"license": "MIT",
"optional": true,
"os": [
"darwin"
],
"bin": {
"pnpm": "pnpm"
},
"funding": {
"url": "https://opencollective.com/pnpm"
}
},
"node_modules/@pnpm/win-arm64": {
"version": "10.32.1",
"resolved": "https://registry.npmjs.org/@pnpm/win-arm64/-/win-arm64-10.32.1.tgz",
"integrity": "sha512-P8rsP5IUetpYjr2iwggoswL2qUukYrJoToXWuMyo8immn58CsYxaXsHVQ1Oq1R3XMfmGGWTXLsiJuQ7H991MRg==",
"cpu": [
"arm64"
],
"license": "MIT",
"optional": true,
"os": [
"win32"
],
"bin": {
"pnpm": "pnpm.exe"
},
"funding": {
"url": "https://opencollective.com/pnpm"
}
},
"node_modules/@pnpm/win-x64": {
"version": "10.32.1",
"resolved": "https://registry.npmjs.org/@pnpm/win-x64/-/win-x64-10.32.1.tgz",
"integrity": "sha512-i24GwbtBO8ojrhp8WWimX7NgZs0UKH1171oRt6qcRL+a+FxE0Eggv2y0KP7ZI7F3+LZMarwr3tnYsZryfciUOg==",
"cpu": [
"x64"
],
"license": "MIT",
"optional": true,
"os": [
"win32"
],
"bin": {
"pnpm": "pnpm.exe"
},
"funding": {
"url": "https://opencollective.com/pnpm"
}
}
}
}

View File

@@ -0,0 +1,28 @@
{
"name": "bootstrap-pnpm",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"dependencies": {
"pnpm": "latest"
}
},
"node_modules/pnpm": {
"version": "10.32.1",
"resolved": "https://registry.npmjs.org/pnpm/-/pnpm-10.32.1.tgz",
"integrity": "sha512-pwaTjw6JrBRWtlY+q07fHR+vM2jRGR/FxZeQ6W3JGORFarLmfWE94QQ9LoyB+HMD5rQNT/7KnfFe8a1Wc0jyvg==",
"license": "MIT",
"bin": {
"pnpm": "bin/pnpm.cjs",
"pnpx": "bin/pnpx.cjs"
},
"engines": {
"node": ">=18.12"
},
"funding": {
"url": "https://opencollective.com/pnpm"
}
}
}
}

View File

@@ -9,7 +9,7 @@ export async function install(inputs: Inputs) {
const status = await runSelfInstaller(inputs) const status = await runSelfInstaller(inputs)
endGroup() endGroup()
if (status) { if (status) {
return setFailed(`Something does wrong, self-installer exits with code ${status}`) return setFailed(`Something went wrong, self-installer exits with code ${status}`)
} }
} }

View File

@@ -1,28 +1,119 @@
import { addPath, exportVariable } from '@actions/core'
import { spawn } from 'child_process' import { spawn } from 'child_process'
import { execPath } from 'process' import { rm, writeFile, mkdir } from 'fs/promises'
import { join } from 'path' import { readFileSync } from 'fs'
import { remove, ensureFile, writeFile } from 'fs-extra' import path from 'path'
import fetch from 'node-fetch' import util from 'util'
import { Inputs } from '../inputs' import { Inputs } from '../inputs'
import { parse as parseYaml } from 'yaml'
import pnpmLock from './bootstrap/pnpm-lock.json'
import exeLock from './bootstrap/exe-lock.json'
const BOOTSTRAP_PNPM_PACKAGE_JSON = JSON.stringify({ private: true, dependencies: { pnpm: pnpmLock.packages['node_modules/pnpm'].version } })
const BOOTSTRAP_EXE_PACKAGE_JSON = JSON.stringify({ private: true, dependencies: { '@pnpm/exe': exeLock.packages['node_modules/@pnpm/exe'].version } })
export async function runSelfInstaller(inputs: Inputs): Promise<number> { export async function runSelfInstaller(inputs: Inputs): Promise<number> {
const { version, dest } = inputs const { version, dest, packageJsonFile, standalone } = inputs
const target = version ? `pnpm@${version}` : 'pnpm'
const pkgJson = join(dest, 'package.json')
await remove(dest) // Install bootstrap pnpm via npm (integrity verified by committed lockfile)
await ensureFile(pkgJson) await rm(dest, { recursive: true, force: true })
await writeFile(pkgJson, JSON.stringify({ private: true })) await mkdir(dest, { recursive: true })
const cp = spawn(execPath, ['-', 'install', target, '--no-lockfile'], { const lockfile = standalone ? exeLock : pnpmLock
cwd: dest, const packageJson = standalone ? BOOTSTRAP_EXE_PACKAGE_JSON : BOOTSTRAP_PNPM_PACKAGE_JSON
stdio: ['pipe', 'inherit', 'inherit'], await writeFile(path.join(dest, 'package.json'), packageJson)
}) await writeFile(path.join(dest, 'package-lock.json'), JSON.stringify(lockfile))
const response = await fetch('https://pnpm.js.org/pnpm.js') const npmExitCode = await runCommand('npm', ['ci'], { cwd: dest })
response.body.pipe(cp.stdin) if (npmExitCode !== 0) {
return npmExitCode
}
return new Promise((resolve, reject) => { const pnpmHome = path.join(dest, 'node_modules', '.bin')
addPath(pnpmHome)
exportVariable('PNPM_HOME', pnpmHome)
const bootstrapPnpm = standalone
? path.join(dest, 'node_modules', '@pnpm', 'exe', 'pnpm')
: path.join(dest, 'node_modules', 'pnpm', 'bin', 'pnpm.cjs')
// Determine the target version
const targetVersion = readTargetVersion({ version, packageJsonFile })
if (targetVersion) {
const cmd = standalone ? bootstrapPnpm : process.execPath
const args = standalone ? ['self-update', targetVersion] : [bootstrapPnpm, 'self-update', targetVersion]
const exitCode = await runCommand(cmd, args, { cwd: dest })
if (exitCode !== 0) {
return exitCode
}
}
return 0
}
function readTargetVersion(opts: {
readonly version?: string | undefined
readonly packageJsonFile: string
}): string | undefined {
const { version, packageJsonFile } = opts
const { GITHUB_WORKSPACE } = process.env
let packageManager: unknown
if (GITHUB_WORKSPACE) {
try {
const content = readFileSync(path.join(GITHUB_WORKSPACE, packageJsonFile), 'utf8');
({ packageManager } = packageJsonFile.endsWith(".yaml")
? parseYaml(content, { merge: true })
: JSON.parse(content)
)
} catch (error: unknown) {
// Swallow error if package.json doesn't exist in root
if (!util.types.isNativeError(error) || !('code' in error) || error.code !== 'ENOENT') throw error
}
}
if (version) {
if (
typeof packageManager === 'string' &&
packageManager.startsWith('pnpm@') &&
packageManager.replace('pnpm@', '') !== version
) {
throw new Error(`Multiple versions of pnpm specified:
- version ${version} in the GitHub Action config with the key "version"
- version ${packageManager} in the package.json with the key "packageManager"
Remove one of these versions to avoid version mismatch errors like ERR_PNPM_BAD_PM_VERSION`)
}
return version
}
if (typeof packageManager === 'string' && packageManager.startsWith('pnpm@')) {
// pnpm will handle version management via packageManager field
return undefined
}
if (!GITHUB_WORKSPACE) {
throw new Error(`No workspace is found.
If you've intended to let pnpm/action-setup read preferred pnpm version from the "packageManager" field in the package.json file,
please run the actions/checkout before pnpm/action-setup.
Otherwise, please specify the pnpm version in the action configuration.`)
}
throw new Error(`No pnpm version is specified.
Please specify it by one of the following ways:
- in the GitHub Action config with the key "version"
- in the package.json with the key "packageManager"`)
}
function runCommand(cmd: string, args: string[], opts: { cwd: string }): Promise<number> {
return new Promise<number>((resolve, reject) => {
const cp = spawn(cmd, args, {
cwd: opts.cwd,
stdio: ['pipe', 'inherit', 'inherit'],
shell: process.platform === 'win32',
})
cp.on('error', reject) cp.on('error', reject)
cp.on('close', resolve) cp.on('close', resolve)
}) })

View File

@@ -1,5 +1,5 @@
import { spawnSync } from 'child_process'
import { setFailed, startGroup, endGroup } from '@actions/core' import { setFailed, startGroup, endGroup } from '@actions/core'
import { spawnSync } from 'child_process'
import { Inputs } from '../inputs' import { Inputs } from '../inputs'
import { patchPnpmEnv } from '../utils' import { patchPnpmEnv } from '../utils'

View File

@@ -1,5 +1,5 @@
import { spawnSync } from 'child_process'
import { warning, startGroup, endGroup } from '@actions/core' import { warning, startGroup, endGroup } from '@actions/core'
import { spawnSync } from 'child_process'
import { Inputs } from '../inputs' import { Inputs } from '../inputs'
import { patchPnpmEnv } from '../utils' import { patchPnpmEnv } from '../utils'
@@ -13,7 +13,7 @@ export function pruneStore(inputs: Inputs) {
const { error, status } = spawnSync('pnpm', ['store', 'prune'], { const { error, status } = spawnSync('pnpm', ['store', 'prune'], {
stdio: 'inherit', stdio: 'inherit',
shell: true, shell: true,
env: patchPnpmEnv(inputs) env: patchPnpmEnv(inputs),
}) })
endGroup() endGroup()

View File

@@ -1,10 +1,10 @@
import process from 'process'
import path from 'path' import path from 'path'
import process from 'process'
import { Inputs } from '../inputs' import { Inputs } from '../inputs'
export const getBinDest = (inputs: Inputs): string => path.join(inputs.dest, 'node_modules', '.bin') export const getBinDest = (inputs: Inputs): string => path.join(inputs.dest, 'node_modules', '.bin')
export const patchPnpmEnv = (inputs: Inputs): NodeJS.ProcessEnv => ({ export const patchPnpmEnv = (inputs: Inputs): NodeJS.ProcessEnv => ({
...process.env, ...process.env,
PATH: getBinDest(inputs) + path.delimiter + process.env.PATH PATH: getBinDest(inputs) + path.delimiter + process.env.PATH,
}) })

View File

@@ -1,30 +1,19 @@
{ {
"compilerOptions": { "compilerOptions": {
"target": "ES2018", "target": "ES2022",
"module": "CommonJS", "module": "ESNext",
"moduleResolution": "Node", "moduleResolution": "bundler",
"resolveJsonModule": true, "resolveJsonModule": true,
"lib": [ "lib": [
"ES2018", "ES2023"
"ES2019",
"ES2020",
"ESNext"
], ],
"outDir": "./dist/tsc", "noEmit": true,
"preserveConstEnums": true,
"incremental": false,
"declaration": true,
"sourceMap": true,
"importHelpers": false,
"strict": true, "strict": true,
"pretty": true, "pretty": true,
"noUnusedLocals": true, "noUnusedLocals": true,
"noUnusedParameters": true, "noUnusedParameters": true,
"noImplicitReturns": true, "noImplicitReturns": true,
"noFallthroughCasesInSwitch": true, "noFallthroughCasesInSwitch": true,
"esModuleInterop": true, "esModuleInterop": true
"experimentalDecorators": true,
"emitDecoratorMetadata": true
} }
} }