mirror of
https://github.com/pnpm/action-setup.git
synced 2026-03-16 23:36:11 +08:00
Compare commits
135 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0ffe724fa5 | ||
|
|
a722bd2d87 | ||
|
|
49b8837b49 | ||
|
|
9fbc6cd1d1 | ||
|
|
af96d9fd0e | ||
|
|
1fb299a44f | ||
|
|
24a61aa18d | ||
|
|
ab0b84aeb1 | ||
|
|
dc312cdfd7 | ||
|
|
fc06bc1257 | ||
|
|
b906affcce | ||
|
|
9b5745cdf0 | ||
|
|
1e1c8eafbd | ||
|
|
b9e1dbc72f | ||
|
|
61bc82c7df | ||
|
|
e94b270858 | ||
|
|
ee7b8711bd | ||
|
|
3a0024f066 | ||
|
|
72f04517b7 | ||
|
|
41ff726559 | ||
|
|
f2b2b233b5 | ||
|
|
77504a59bc | ||
|
|
d648c2dd06 | ||
|
|
a7487c7e89 | ||
|
|
fff70888d0 | ||
|
|
6e3017af18 | ||
|
|
0cb0538c33 | ||
|
|
e303250a24 | ||
|
|
ac5bf11548 | ||
|
|
18ac635edf | ||
|
|
0d0b43217a | ||
|
|
0eb0e97082 | ||
|
|
23657c8550 | ||
|
|
5d79380f29 | ||
|
|
562dbbf611 | ||
|
|
00884bcdc5 | ||
|
|
fe02b34f77 | ||
|
|
bee1f099e5 | ||
|
|
ce859e384f | ||
|
|
2ab6dce4f5 | ||
|
|
e280758d01 | ||
|
|
129abb77bf | ||
|
|
a3252b78c4 | ||
|
|
1ee9c9d01d | ||
|
|
ebcfd6995d | ||
|
|
d2613e087f | ||
|
|
d928be8e0c | ||
|
|
d882d12c64 | ||
|
|
0b715c7ebb | ||
|
|
2ed49cbb02 | ||
|
|
218cb35941 | ||
|
|
3723f63bb4 | ||
|
|
849d884800 | ||
|
|
f92eb0edb6 | ||
|
|
b27f801bf9 | ||
|
|
11dd14d0c0 | ||
|
|
61eb8c655a | ||
|
|
65db188e28 | ||
|
|
0609f0983b | ||
|
|
7208fa2733 | ||
|
|
1bd00a2972 | ||
|
|
d5601fb603 | ||
|
|
bc06aa6030 | ||
|
|
cd2af74528 | ||
|
|
c8a150e137 | ||
|
|
ed0172a253 | ||
|
|
c3b53f6a16 | ||
|
|
21e88da200 | ||
|
|
fc3334fa11 | ||
|
|
d01953a678 | ||
|
|
3360b50db7 | ||
|
|
6f9e9a867a | ||
|
|
537643d491 | ||
|
|
f4129fb46e | ||
|
|
6e1964dde3 | ||
|
|
10693b3829 | ||
|
|
99ecd24520 | ||
|
|
958500fcab | ||
|
|
57b9359b4c | ||
|
|
ec1a8b444c | ||
|
|
73e15250cb | ||
|
|
10b4b0b462 | ||
|
|
5fa8980bf4 | ||
|
|
ae78e9abbe | ||
|
|
35ab4267a1 | ||
|
|
11ba3424e0 | ||
|
|
847a737d63 | ||
|
|
225f3bb4b0 | ||
|
|
777a50d72e | ||
|
|
e7c10c6fc5 | ||
|
|
a576a70bc6 | ||
|
|
1d51e20937 | ||
|
|
ad2b35ae0c | ||
|
|
d8ea532ac4 | ||
|
|
2270f39ef6 | ||
|
|
394c848db6 | ||
|
|
e13928ccc5 | ||
|
|
93bd5a123d | ||
|
|
9eb14dd77c | ||
|
|
eafb777c56 | ||
|
|
e6378df420 | ||
|
|
6ff6e97bc6 | ||
|
|
45d9c91ff6 | ||
|
|
15569a497d | ||
|
|
d70eebd14a | ||
|
|
3bf8acf16f | ||
|
|
3c2fe8c592 | ||
|
|
76cc04cd5e | ||
|
|
bcad811784 | ||
|
|
602b36f177 | ||
|
|
74a0fdc1a4 | ||
|
|
493e98ec5e | ||
|
|
646cdf4821 | ||
|
|
a1ba6cf5ae | ||
|
|
41b381a08b | ||
|
|
3236b209b5 | ||
|
|
2124926520 | ||
|
|
ba9826e81c | ||
|
|
7c4472dbcf | ||
|
|
0db7fb9961 | ||
|
|
aefcd1e623 | ||
|
|
b7b9d6344b | ||
|
|
7e61ea5847 | ||
|
|
3a2c7247e1 | ||
|
|
2a105263a5 | ||
|
|
9facd4db8e | ||
|
|
6c1466d327 | ||
|
|
b26427e53e | ||
|
|
086f5bd3b6 | ||
|
|
bdb2a5ee76 | ||
|
|
8e1abe543f | ||
|
|
af6247d08a | ||
|
|
f87c8a916e | ||
|
|
d6790970e0 | ||
|
|
fa62771e12 |
14
.github/FUNDING.yml
vendored
14
.github/FUNDING.yml
vendored
@@ -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
|
||||
|
||||
7
.github/dependabot.yml
vendored
Normal file
7
.github/dependabot.yml
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: github-actions
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: weekly
|
||||
open-pull-requests-limit: 10
|
||||
96
.github/workflows/test.yaml
vendored
96
.github/workflows/test.yaml
vendored
@@ -3,6 +3,7 @@ name: Test Action
|
||||
on:
|
||||
- push
|
||||
- pull_request
|
||||
- workflow_dispatch
|
||||
|
||||
jobs:
|
||||
test_default_inputs:
|
||||
@@ -14,28 +15,36 @@ 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@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
|
||||
|
||||
- name: Run the action
|
||||
uses: ./
|
||||
with:
|
||||
version: 4.11.1
|
||||
version: 9.15.5
|
||||
|
||||
- name: 'Test: which'
|
||||
run: which pnpm; which pnpx
|
||||
|
||||
- name: 'Test: install'
|
||||
run: pnpm install
|
||||
- name: 'Test: version'
|
||||
run: pnpm --version
|
||||
|
||||
test_explicit_inputs:
|
||||
name: Test with explicit inputs
|
||||
- name: 'Test: install in a fresh project'
|
||||
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 }}
|
||||
|
||||
@@ -43,28 +52,61 @@ 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@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
|
||||
|
||||
- name: Run the action
|
||||
uses: ./
|
||||
with:
|
||||
version: 4.11.1
|
||||
version: 9.15.5
|
||||
dest: ~/test/pnpm
|
||||
bin_dest: ~/test/pnpm/.bin
|
||||
registry: http://registry.yarnpkg.com/
|
||||
|
||||
- name: 'Test: which'
|
||||
run: which pnpm && which pnpx
|
||||
|
||||
- name: 'Test: install'
|
||||
run: pnpm install
|
||||
- name: 'Test: version'
|
||||
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:
|
||||
name: 'Test with run_install (${{ matrix.run_install.name }}, ${{ matrix.os }})'
|
||||
@@ -75,7 +117,7 @@ jobs:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
pnpm:
|
||||
- 4.11.1
|
||||
- 9.15.5
|
||||
os:
|
||||
- ubuntu-latest
|
||||
- macos-latest
|
||||
@@ -83,11 +125,6 @@ jobs:
|
||||
run_install:
|
||||
- name: 'null'
|
||||
value: 'null'
|
||||
- name: 'empty object'
|
||||
value: '{}'
|
||||
- name: 'recursive'
|
||||
value: |
|
||||
recursive: true
|
||||
- name: 'global'
|
||||
value: |
|
||||
args:
|
||||
@@ -95,29 +132,18 @@ jobs:
|
||||
- --global-dir=./pnpm-global
|
||||
- npm
|
||||
- yarn
|
||||
- pnpm
|
||||
- name: 'array'
|
||||
value: |
|
||||
- {}
|
||||
- recursive: true
|
||||
- args:
|
||||
- --global
|
||||
- --global-dir=./pnpm-global
|
||||
- npm
|
||||
- yarn
|
||||
- pnpm
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
|
||||
|
||||
- name: Run the action
|
||||
uses: ./
|
||||
with:
|
||||
version: 4.11.1
|
||||
version: 9.15.5
|
||||
run_install: ${{ matrix.run_install.value }}
|
||||
|
||||
- name: 'Test: which'
|
||||
run: which pnpm; which pnpx
|
||||
|
||||
- name: 'Test: install'
|
||||
run: pnpm install
|
||||
- name: 'Test: version'
|
||||
run: pnpm --version
|
||||
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -8,3 +8,4 @@ temp
|
||||
*.temp
|
||||
tmp.*
|
||||
temp.*
|
||||
.pnpm-store
|
||||
|
||||
132
README.md
132
README.md
@@ -1,24 +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
|
||||
|
||||
### `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`
|
||||
|
||||
**Optional** Where to store PNPM files.
|
||||
|
||||
### `bin_dest`
|
||||
|
||||
**Optional** Where to store executables (`pnpm` and `pnpx` commands).
|
||||
|
||||
### `registry`
|
||||
|
||||
**Optional** (_default:_ `https://registry.npmjs.com`) Registry to download PNPM from.
|
||||
**Optional** Where to store pnpm files.
|
||||
|
||||
### `run_install`
|
||||
|
||||
@@ -40,7 +40,25 @@ If `run_install` is a YAML string representation of either an object or an array
|
||||
|
||||
#### `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
|
||||
|
||||
@@ -50,11 +68,13 @@ Expanded path of inputs#dest.
|
||||
|
||||
### `bin_dest`
|
||||
|
||||
Expanded path of inputs#bin_dest.
|
||||
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,15 +82,18 @@ on:
|
||||
- pull_request
|
||||
|
||||
jobs:
|
||||
runs-on: ubuntu-latest
|
||||
install:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: pnpm/action-setup@v1.2.0
|
||||
with:
|
||||
version: 4.11.1
|
||||
steps:
|
||||
- uses: pnpm/action-setup@v4
|
||||
with:
|
||||
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
|
||||
on:
|
||||
@@ -78,24 +101,67 @@ on:
|
||||
- pull_request
|
||||
|
||||
jobs:
|
||||
runs-on: ubuntu-latest
|
||||
install:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- uses: pnpm/action-setup@v1.2.0
|
||||
with:
|
||||
version: 4.11.1
|
||||
run_install: |
|
||||
- recursive: true
|
||||
args: [--frozen-lockfile, --strict-peer-dependencies]
|
||||
- args: [--global, gulp, prettier, typescript]
|
||||
steps:
|
||||
- uses: pnpm/action-setup@v4
|
||||
```
|
||||
|
||||
### Install pnpm and a few npm packages
|
||||
|
||||
```yaml
|
||||
on:
|
||||
- push
|
||||
- pull_request
|
||||
|
||||
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
|
||||
|
||||
```yaml
|
||||
on:
|
||||
- push
|
||||
- pull_request
|
||||
|
||||
jobs:
|
||||
cache-and-install:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- uses: pnpm/action-setup@v4
|
||||
name: Install pnpm
|
||||
with:
|
||||
version: 10
|
||||
cache: true
|
||||
|
||||
- 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.
|
||||
|
||||
## Notes
|
||||
|
||||
This action does not setup Node.js for you, use [actions/setup-node](https://github.com/actions/setup-node) yourself.
|
||||
|
||||
## 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/)
|
||||
|
||||
41
action.yml
41
action.yml
@@ -1,29 +1,42 @@
|
||||
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
|
||||
required: true
|
||||
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
|
||||
bin_dest:
|
||||
description: Where to store executables (pnpm and pnpx commands)
|
||||
required: false
|
||||
default: ~/setup-pnpm/.bin
|
||||
registry:
|
||||
description: Registry to download PNPM from
|
||||
required: false
|
||||
default: https://registry.npmjs.com
|
||||
run_install:
|
||||
description: If specified, run `pnpm install`
|
||||
required: false
|
||||
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:
|
||||
using: node12
|
||||
using: node24
|
||||
main: dist/index.js
|
||||
post: dist/index.js
|
||||
|
||||
290
dist/index.js
vendored
290
dist/index.js
vendored
File diff suppressed because one or more lines are too long
26
package.json
26
package.json
@@ -1,25 +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",
|
||||
"build:bundle": "esbuild src/index.ts --bundle --platform=node --target=node24 --format=cjs --minify --outfile=dist/index.js --loader:.json=json",
|
||||
"build": "pnpm run build:bundle",
|
||||
"start": "pnpm run build && sh ./run.sh"
|
||||
},
|
||||
"dependencies": {
|
||||
"node-fetch": "^2.6.0",
|
||||
"@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",
|
||||
"js-yaml": "^3.13.1",
|
||||
"ajv": "^6.12.0",
|
||||
"@actions/core": "^1.2.4",
|
||||
"@types/expand-tilde": "^2.0.0",
|
||||
"@types/node-fetch": "^2.5.7",
|
||||
"@types/js-yaml": "^3.12.3",
|
||||
"@types/node": "^13.13.5"
|
||||
"yaml": "^2.3.4",
|
||||
"zod": "^3.22.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "^3.8.3",
|
||||
"@ts-schema-autogen/cli": "^0.1.2",
|
||||
"@zeit/ncc": "^0.22.1"
|
||||
"esbuild": "^0.27.4",
|
||||
"typescript": "^5.3.3"
|
||||
}
|
||||
}
|
||||
|
||||
1729
pnpm-lock.yaml
generated
1729
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,10 @@
|
||||
{
|
||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||
"pinVersions": false,
|
||||
"extends": [
|
||||
"config:base"
|
||||
],
|
||||
"ignoreDeps": [
|
||||
"ajv"
|
||||
]
|
||||
}
|
||||
|
||||
3
run.sh
3
run.sh
@@ -3,7 +3,6 @@
|
||||
export HOME="$(pwd)"
|
||||
export INPUT_VERSION=4.11.1
|
||||
export INPUT_DEST='~/pnpm.temp'
|
||||
export INPUT_BIN_DEST='~/pnpm.temp/.bin'
|
||||
export INPUT_REGISTRY=https://registry.npmjs.com
|
||||
export INPUT_RUN_INSTALL=null
|
||||
export INPUT_standalone=false
|
||||
exec node dist/index.js
|
||||
|
||||
19
src/cache-restore/index.ts
Normal file
19
src/cache-restore/index.ts
Normal 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
39
src/cache-restore/run.ts
Normal 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
15
src/cache-save/index.ts
Normal 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
18
src/cache-save/run.ts
Normal 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}`)
|
||||
}
|
||||
26
src/index.ts
26
src/index.ts
@@ -1,21 +1,39 @@
|
||||
import { setFailed, saveState, getState } from '@actions/core'
|
||||
import getInputs from './inputs'
|
||||
import setOutputs from './outputs'
|
||||
import restoreCache from './cache-restore'
|
||||
import saveCache from './cache-save'
|
||||
import getInputs, { Inputs } from './inputs'
|
||||
import installPnpm from './install-pnpm'
|
||||
import setOutputs from './outputs'
|
||||
import pnpmInstall from './pnpm-install'
|
||||
import pruneStore from './pnpm-store-prune'
|
||||
|
||||
async function main() {
|
||||
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')
|
||||
|
||||
await installPnpm(inputs)
|
||||
console.log('Installation Completed!')
|
||||
setOutputs(inputs)
|
||||
|
||||
await restoreCache(inputs)
|
||||
|
||||
pnpmInstall(inputs)
|
||||
}
|
||||
|
||||
async function runPost(inputs: Inputs) {
|
||||
pruneStore(inputs)
|
||||
await saveCache(inputs)
|
||||
}
|
||||
|
||||
main().catch(error => {
|
||||
console.error(error)
|
||||
setFailed(error)
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
import { getInput, InputOptions } from '@actions/core'
|
||||
import { getBooleanInput, getInput, InputOptions } from '@actions/core'
|
||||
import expandTilde from 'expand-tilde'
|
||||
import { RunInstall, parseRunInstall } from './run-install'
|
||||
|
||||
export interface Inputs {
|
||||
readonly version: string
|
||||
readonly version?: string
|
||||
readonly dest: string
|
||||
readonly binDest: string
|
||||
readonly registry: string
|
||||
readonly cache: boolean
|
||||
readonly cacheDependencyPath: string
|
||||
readonly runInstall: RunInstall[]
|
||||
readonly packageJsonFile: string
|
||||
readonly standalone: boolean
|
||||
}
|
||||
|
||||
const options: InputOptions = {
|
||||
@@ -17,11 +19,13 @@ const options: InputOptions = {
|
||||
const parseInputPath = (name: string) => expandTilde(getInput(name, options))
|
||||
|
||||
export const getInputs = (): Inputs => ({
|
||||
version: getInput('version', options),
|
||||
version: getInput('version'),
|
||||
dest: parseInputPath('dest'),
|
||||
binDest: parseInputPath('bin_dest'),
|
||||
registry: getInput('registry', options),
|
||||
cache: getBooleanInput('cache'),
|
||||
cacheDependencyPath: parseInputPath('cache_dependency_path'),
|
||||
runInstall: parseRunInstall('run_install'),
|
||||
packageJsonFile: parseInputPath('package_json_file'),
|
||||
standalone: getBooleanInput('standalone'),
|
||||
})
|
||||
|
||||
export default getInputs
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
@@ -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#"
|
||||
}
|
||||
@@ -1,40 +1,41 @@
|
||||
import process from 'process'
|
||||
import { safeLoad } from 'js-yaml'
|
||||
import Ajv from 'ajv'
|
||||
import { getInput, error, InputOptions } from '@actions/core'
|
||||
import runInstallSchema from './run-install-input.schema.json'
|
||||
import { getInput, error } from '@actions/core'
|
||||
import { parse as parseYaml } 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 = safeLoad(getInput(name, options))
|
||||
const ajv = new Ajv({
|
||||
allErrors: true,
|
||||
async: false,
|
||||
})
|
||||
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 = parseYaml(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]
|
||||
}
|
||||
|
||||
147
src/install-pnpm/bootstrap/exe-lock.json
Normal file
147
src/install-pnpm/bootstrap/exe-lock.json
Normal 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"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
28
src/install-pnpm/bootstrap/pnpm-lock.json
Normal file
28
src/install-pnpm/bootstrap/pnpm-lock.json
Normal 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"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ export async function install(inputs: Inputs) {
|
||||
const status = await runSelfInstaller(inputs)
|
||||
endGroup()
|
||||
if (status) {
|
||||
return setFailed(`Something does wrong, self-installer exits with code ${status}`)
|
||||
return setFailed(`Something went wrong, self-installer exits with code ${status}`)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,23 +1,119 @@
|
||||
import { addPath, exportVariable } from '@actions/core'
|
||||
import { spawn } from 'child_process'
|
||||
import { execPath } from 'process'
|
||||
import { downloadSelfInstaller } from '../self-installer'
|
||||
import { rm, writeFile, mkdir } from 'fs/promises'
|
||||
import { readFileSync } from 'fs'
|
||||
import path from 'path'
|
||||
import util from 'util'
|
||||
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> {
|
||||
const cp = spawn(execPath, {
|
||||
env: {
|
||||
PNPM_VERSION: inputs.version,
|
||||
PNPM_DEST: inputs.dest,
|
||||
PNPM_BIN_DEST: inputs.binDest,
|
||||
PNPM_REGISTRY: inputs.registry,
|
||||
},
|
||||
stdio: ['pipe', 'inherit', 'inherit'],
|
||||
})
|
||||
const { version, dest, packageJsonFile, standalone } = inputs
|
||||
|
||||
const response = await downloadSelfInstaller()
|
||||
response.body.pipe(cp.stdin)
|
||||
// Install bootstrap pnpm via npm (integrity verified by committed lockfile)
|
||||
await rm(dest, { recursive: true, force: true })
|
||||
await mkdir(dest, { recursive: true })
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const lockfile = standalone ? exeLock : pnpmLock
|
||||
const packageJson = standalone ? BOOTSTRAP_EXE_PACKAGE_JSON : BOOTSTRAP_PNPM_PACKAGE_JSON
|
||||
await writeFile(path.join(dest, 'package.json'), packageJson)
|
||||
await writeFile(path.join(dest, 'package-lock.json'), JSON.stringify(lockfile))
|
||||
|
||||
const npmExitCode = await runCommand('npm', ['ci'], { cwd: dest })
|
||||
if (npmExitCode !== 0) {
|
||||
return npmExitCode
|
||||
}
|
||||
|
||||
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('close', resolve)
|
||||
})
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import { setOutput, addPath } from '@actions/core'
|
||||
import { Inputs } from '../inputs'
|
||||
import { getBinDest } from '../utils'
|
||||
|
||||
export function setOutputs(inputs: Inputs) {
|
||||
addPath(inputs.binDest)
|
||||
const binDest = getBinDest(inputs)
|
||||
addPath(binDest)
|
||||
setOutput('dest', inputs.dest)
|
||||
setOutput('bin_dest', inputs.binDest)
|
||||
setOutput('bin_dest', binDest)
|
||||
}
|
||||
|
||||
export default setOutputs
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { spawnSync } from 'child_process'
|
||||
import { setFailed, startGroup, endGroup } from '@actions/core'
|
||||
import { spawnSync } from 'child_process'
|
||||
import { Inputs } from '../inputs'
|
||||
import { patchPnpmEnv } from '../utils'
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { spawnSync } from 'child_process'
|
||||
import { warning, startGroup, endGroup } from '@actions/core'
|
||||
import { spawnSync } from 'child_process'
|
||||
import { Inputs } from '../inputs'
|
||||
import { patchPnpmEnv } from '../utils'
|
||||
|
||||
@@ -13,7 +13,7 @@ export function pruneStore(inputs: Inputs) {
|
||||
const { error, status } = spawnSync('pnpm', ['store', 'prune'], {
|
||||
stdio: 'inherit',
|
||||
shell: true,
|
||||
env: patchPnpmEnv(inputs)
|
||||
env: patchPnpmEnv(inputs),
|
||||
})
|
||||
endGroup()
|
||||
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
import fetch from 'node-fetch'
|
||||
import url from './url'
|
||||
export const downloadSelfInstaller = () => fetch(url)
|
||||
export default downloadSelfInstaller
|
||||
@@ -1,2 +0,0 @@
|
||||
export * from './url'
|
||||
export * from './download'
|
||||
@@ -1,3 +0,0 @@
|
||||
export const ref = '301414cec74a2b6b63c95b42f2ad1790ccb980ed'
|
||||
export const url = `https://raw.githubusercontent.com/pnpm/self-installer/${ref}/install.js`
|
||||
export default url
|
||||
@@ -1,8 +1,10 @@
|
||||
import process from 'process'
|
||||
import path from 'path'
|
||||
import process from 'process'
|
||||
import { Inputs } from '../inputs'
|
||||
|
||||
export const getBinDest = (inputs: Inputs): string => path.join(inputs.dest, 'node_modules', '.bin')
|
||||
|
||||
export const patchPnpmEnv = (inputs: Inputs): NodeJS.ProcessEnv => ({
|
||||
...process.env,
|
||||
PATH: inputs.binDest + path.delimiter + process.env.PATH
|
||||
PATH: getBinDest(inputs) + path.delimiter + process.env.PATH,
|
||||
})
|
||||
|
||||
@@ -1,30 +1,19 @@
|
||||
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2018",
|
||||
"module": "CommonJS",
|
||||
"moduleResolution": "Node",
|
||||
"target": "ES2022",
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "bundler",
|
||||
"resolveJsonModule": true,
|
||||
"lib": [
|
||||
"ES2018",
|
||||
"ES2019",
|
||||
"ES2020",
|
||||
"ESNext"
|
||||
"ES2023"
|
||||
],
|
||||
"outDir": "./dist/tsc",
|
||||
"preserveConstEnums": true,
|
||||
"incremental": false,
|
||||
"declaration": true,
|
||||
"sourceMap": true,
|
||||
"importHelpers": false,
|
||||
"noEmit": true,
|
||||
"strict": true,
|
||||
"pretty": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"noImplicitReturns": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"esModuleInterop": true,
|
||||
"experimentalDecorators": true,
|
||||
"emitDecoratorMetadata": true
|
||||
"esModuleInterop": true
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user