Compare commits

...

62 Commits

Author SHA1 Message Date
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
18 changed files with 237821 additions and 1280 deletions

14
.github/FUNDING.yml vendored
View File

@ -1,12 +1,2 @@
# These are supported funding model platforms
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']
custom:
- https://opencollective.com/pnpm

View File

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

View File

@ -15,19 +15,19 @@ jobs:
fail-fast: false
matrix:
pnpm:
- 4.11.1
- 9.15.5
os:
- ubuntu-latest
- macos-latest
- windows-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Run the action
uses: ./
with:
version: 4.11.1
version: 9.15.5
- name: 'Test: which'
run: which pnpm; which pnpx
@ -35,8 +35,8 @@ jobs:
- name: 'Test: install'
run: pnpm install
test_explicit_inputs:
name: Test with explicit inputs
test_dest:
name: Test with dest
runs-on: ${{ matrix.os }}
@ -44,19 +44,19 @@ jobs:
fail-fast: false
matrix:
pnpm:
- 4.11.1
- 9.15.5
os:
- ubuntu-latest
- macos-latest
- windows-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Run the action
uses: ./
with:
version: 4.11.1
version: 9.15.5
dest: ~/test/pnpm
- name: 'Test: which'
@ -65,6 +65,61 @@ jobs:
- name: 'Test: install'
run: pnpm install
test_standalone:
name: Test with standalone
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- macos-latest
- windows-latest
standalone:
- true
- false
steps:
- uses: actions/checkout@v4
- name: Run the action
uses: ./
with:
version: 9.15.0
standalone: ${{ matrix.standalone }}
- name: install Node.js
uses: actions/setup-node@v4
with:
# pnpm@7.0.0 is not compatible with Node.js 12
node-version: 12.22.12
- name: 'Test: which (pnpm)'
run: which pnpm
- name: 'Test: which (pnpx)'
if: matrix.standalone == false
run: which pnpx
- name: 'Test: install when standalone is true'
if: matrix.standalone
run: pnpm install
- name: 'Test: install when standalone is false'
if: matrix.standalone == false
# Since the default shell on windows runner is pwsh, we specify bash explicitly
shell: bash
run: |
if pnpm install; then
echo "pnpm install should fail"
exit 1
else
echo "pnpm install failed as expected"
fi
test_run_install:
name: 'Test with run_install (${{ matrix.run_install.name }}, ${{ matrix.os }})'
@ -74,7 +129,7 @@ jobs:
fail-fast: false
matrix:
pnpm:
- 4.11.1
- 9.15.5
os:
- ubuntu-latest
- macos-latest
@ -94,7 +149,6 @@ jobs:
- --global-dir=./pnpm-global
- npm
- yarn
- pnpm
- name: 'array'
value: |
- {}
@ -104,15 +158,14 @@ jobs:
- --global-dir=./pnpm-global
- npm
- yarn
- pnpm
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Run the action
uses: ./
with:
version: 4.11.1
version: 9.15.5
run_install: ${{ matrix.run_install.value }}
- name: 'Test: which'

2
.gitignore vendored
View File

@ -2,6 +2,8 @@ node_modules
*.log
/dist/*
!/dist/index.js
!/dist/pnpm.cjs
!/dist/worker.js
tmp
temp
*.tmp

View File

@ -1,3 +1,7 @@
> ## :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.
# Setup pnpm
Install pnpm package manager.
@ -38,6 +42,16 @@ If `run_install` is a YAML string representation of either an object or an array
**Optional** (_type:_ `string[]`) Additional arguments after `pnpm [recursive] install`, e.g. `[--frozen-lockfile, --strict-peer-dependencies]`.
### `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
### `dest`
@ -50,7 +64,9 @@ Location of `pnpm` and `pnpx` command.
## 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
on:
@ -62,9 +78,26 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: pnpm/action-setup@v2.1.0
- uses: pnpm/action-setup@v4
with:
version: 6.0.2
version: 10
```
### 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
on:
- push
- pull_request
jobs:
install:
runs-on: ubuntu-latest
steps:
- uses: pnpm/action-setup@v4
```
### Install pnpm and a few npm packages
@ -79,11 +112,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v2.1.0
- uses: pnpm/action-setup@v4
with:
version: 6.0.2
version: 10
run_install: |
- recursive: true
args: [--frozen-lockfile, --strict-peer-dependencies]
@ -102,21 +135,23 @@ jobs:
runs-on: ubuntu-latest
steps:
build:
- uses: actions/checkout@v2
- name: Checkout
uses: actions/checkout@v4
- name: Cache pnpm modules
uses: actions/cache@v2
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-
- uses: pnpm/action-setup@v4
name: Install pnpm
with:
version: 10
run_install: false
- uses: pnpm/action-setup@v2.1.0
with:
version: 6.0.2
run_install: true
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'
- name: Install dependencies
run: pnpm install
```
**Note:** You don't need to run `pnpm store prune` at the end; post-action has already taken care of that.
@ -127,4 +162,4 @@ This action does not setup Node.js for you, use [actions/setup-node](https://git
## 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,20 +1,34 @@
name: Setup PNPM
description: Install PNPM package manager
name: Setup pnpm
description: Install pnpm package manager
branding:
icon: package
color: orange
inputs:
version:
description: Version of PNPM to install
description: Version of pnpm to install
required: false
dest:
description: Where to store PNPM files
description: Where to store pnpm files
required: false
default: ~/setup-pnpm
run_install:
description: If specified, run `pnpm install`
required: false
default: 'null'
package_json_file:
description: File path to the package.json to read "packageManager" configuration
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:
using: node12
using: node20
main: dist/index.js
post: dist/index.js

34
dist/index.js vendored

File diff suppressed because one or more lines are too long

220780
dist/pnpm.cjs vendored Normal file

File diff suppressed because one or more lines are too long

16625
dist/worker.js vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,28 +1,23 @@
{
"private": true,
"scripts": {
"build:schemas": "ts-schema-autogen generate",
"build:ncc": "ncc build --minify --no-source-map-register --no-cache dist/tsc/index.js --out dist/",
"build": "pnpm run build:schemas && tsc && pnpm run build:ncc",
"start": "pnpm run build && sh ./run.sh"
"build": "tsc && pnpm run build:ncc",
"start": "pnpm run build && sh ./run.sh",
"update-pnpm-dist": "pnpm install && cp ./node_modules/pnpm/dist/pnpm.cjs ./dist/pnpm.cjs && cp ./node_modules/pnpm/dist/worker.js ./dist/worker.js"
},
"dependencies": {
"@actions/core": "^1.6.0",
"@pnpm/fetch": "^4.2.5",
"@pnpm/logger": "^4.0.0",
"@types/expand-tilde": "^2.0.0",
"@types/fs-extra": "^9.0.13",
"@types/js-yaml": "^4.0.5",
"@types/node": "^14.18.10",
"@types/node-fetch": "^2.6.1",
"ajv": "^6.12.6",
"@actions/core": "^1.10.1",
"@types/expand-tilde": "^2.0.2",
"@types/node": "^20.11.5",
"@types/node-fetch": "^2.6.11",
"expand-tilde": "^2.0.2",
"fs-extra": "^10.0.0",
"js-yaml": "^4.1.0"
"yaml": "^2.3.4",
"zod": "^3.22.4"
},
"devDependencies": {
"@ts-schema-autogen/cli": "^0.1.2",
"@vercel/ncc": "^0.33.3",
"typescript": "^4.5.5"
"@vercel/ncc": "^0.38.1",
"pnpm": "^8.14.3",
"typescript": "^5.3.3"
}
}

1221
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_DEST='~/pnpm.temp'
export INPUT_RUN_INSTALL=null
export INPUT_standalone=false
exec node dist/index.js

View File

@ -1,4 +1,4 @@
import { getInput, InputOptions } from '@actions/core'
import { getBooleanInput, getInput, InputOptions } from '@actions/core'
import expandTilde from 'expand-tilde'
import { RunInstall, parseRunInstall } from './run-install'
@ -6,6 +6,8 @@ export interface Inputs {
readonly version?: string
readonly dest: string
readonly runInstall: RunInstall[]
readonly packageJsonFile: string
readonly standalone: boolean
}
const options: InputOptions = {
@ -18,6 +20,8 @@ export const getInputs = (): Inputs => ({
version: getInput('version'),
dest: parseInputPath('dest'),
runInstall: parseRunInstall('run_install'),
packageJsonFile: parseInputPath('package_json_file'),
standalone: getBooleanInput('standalone'),
})
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 { getInput, error, InputOptions } from '@actions/core'
import Ajv from 'ajv'
import { load } from 'js-yaml'
import process from 'process'
import runInstallSchema from './run-install-input.schema.json'
import { getInput, error } from '@actions/core'
import * as yaml from 'yaml'
import { z, ZodError } from 'zod'
export interface RunInstall {
readonly recursive?: boolean
readonly cwd?: string
readonly args?: readonly string[]
}
const RunInstallSchema = z.object({
recursive: z.boolean().optional(),
cwd: z.string().optional(),
args: z.array(z.string()).optional(),
})
export type RunInstallInput =
| null
| boolean
| RunInstall
| RunInstall[]
const RunInstallInputSchema = z.union([
z.null(),
z.boolean(),
RunInstallSchema,
z.array(RunInstallSchema),
])
const options: InputOptions = {
required: true,
}
export type RunInstallInput = z.infer<typeof RunInstallInputSchema>
export type RunInstall = z.infer<typeof RunInstallSchema>
export function parseRunInstall(name: string): RunInstall[] {
const result: RunInstallInput = load(getInput(name, options)) as any
const ajv = new Ajv({
allErrors: true,
})
const validate = ajv.compile(runInstallSchema)
if (!validate(result)) {
for (const errorItem of validate.errors!) {
error(`with.run_install${errorItem.dataPath}: ${errorItem.message}`)
export function parseRunInstall(inputName: string): RunInstall[] {
const input = getInput(inputName, { required: true })
const parsedInput: unknown = yaml.parse(input)
try {
const result: RunInstallInput = RunInstallInputSchema.parse(parsedInput)
if (!result) return []
if (result === true) return [{ recursive: true }]
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

@ -1,31 +1,31 @@
import { addPath, exportVariable } from '@actions/core'
import fetch from '@pnpm/fetch'
import { spawn } from 'child_process'
import { remove, ensureFile, writeFile, readFile } from 'fs-extra'
import { rm, writeFile, mkdir } from 'fs/promises'
import { readFileSync } from 'fs'
import path from 'path'
import { execPath } from 'process'
import util from 'util'
import { Inputs } from '../inputs'
import YAML from 'yaml'
export async function runSelfInstaller(inputs: Inputs): Promise<number> {
const { version, dest } = inputs
const { version, dest, packageJsonFile, standalone } = inputs
// prepare self install
await remove(dest)
await rm(dest, { recursive: true, force: true })
// create dest directory after removal
await mkdir(dest, { recursive: true })
const pkgJson = path.join(dest, 'package.json')
await ensureFile(pkgJson)
// we have ensured the dest directory exists, we can write the file directly
await writeFile(pkgJson, JSON.stringify({ private: true }))
// prepare target pnpm
const target = await readTarget(version)
const cp = spawn(execPath, ['-', 'install', target, '--no-lockfile'], {
const target = await readTarget({ version, packageJsonFile, standalone })
const cp = spawn(execPath, [path.join(__dirname, 'pnpm.cjs'), 'install', target, '--no-lockfile'], {
cwd: dest,
stdio: ['pipe', 'inherit', 'inherit'],
})
const response = await fetch('https://get.pnpm.io/v6.16.js')
if (!response.body) throw new Error('Did not receive response body')
response.body.pipe(cp.stdin)
const exitCode = await new Promise<number>((resolve, reject) => {
cp.on('error', reject)
cp.on('close', resolve)
@ -38,28 +38,66 @@ export async function runSelfInstaller(inputs: Inputs): Promise<number> {
return exitCode
}
async function readTarget(version?: string | undefined) {
if (version) return `pnpm@${version}`
async function readTarget(opts: {
readonly version?: string | undefined
readonly packageJsonFile: string
readonly standalone: boolean
}) {
const { version, packageJsonFile, standalone } = opts
const { GITHUB_WORKSPACE } = process.env
let packageManager
if (GITHUB_WORKSPACE) {
try {
const content = readFileSync(path.join(GITHUB_WORKSPACE, packageJsonFile), 'utf8');
({ packageManager } = packageJsonFile.endsWith(".yaml")
? YAML.parse(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 `${ standalone ? '@pnpm/exe' : 'pnpm' }@${version}`
}
if (!GITHUB_WORKSPACE) {
throw new Error(`No workspace is found.
If you're intended to let pnpm/action-setup read preferred pnpm version from the "packageManager" field in the package.json file,
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.`)
}
const { packageManager } = JSON.parse(await readFile(path.join(GITHUB_WORKSPACE, 'package.json'), 'utf8'))
if (typeof packageManager !== 'string') {
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" (See https://nodejs.org/api/corepack.html)`)
- in the package.json with the key "packageManager"`)
}
if (!packageManager.startsWith('pnpm@')) {
throw new Error('Invalid packageManager field in package.json')
}
if (standalone) {
return packageManager.replace('pnpm@', '@pnpm/exe@')
}
return packageManager
}

View File

@ -1,15 +1,11 @@
{
"compilerOptions": {
"target": "ES2018",
"module": "CommonJS",
"moduleResolution": "Node",
"target": "ES2022",
"module": "Node16",
"resolveJsonModule": true,
"lib": [
"ES2018",
"ES2019",
"ES2020",
"ESNext"
"ES2023"
],
"outDir": "./dist/tsc",
"preserveConstEnums": true,