mirror of
https://github.com/pnpm/action-setup.git
synced 2025-04-20 10:29:59 +08:00
Compare commits
No commits in common. "master" and "v1.1.0" have entirely different histories.
2
.gitattributes
vendored
2
.gitattributes
vendored
|
@ -1,2 +1,2 @@
|
||||||
* text=auto
|
* text=auto
|
||||||
/dist/index.js binary
|
dist/index.js -text
|
||||||
|
|
14
.github/FUNDING.yml
vendored
14
.github/FUNDING.yml
vendored
|
@ -1,2 +1,12 @@
|
||||||
custom:
|
# These are supported funding model platforms
|
||||||
- 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']
|
||||||
|
|
7
.github/dependabot.yml
vendored
7
.github/dependabot.yml
vendored
|
@ -1,7 +0,0 @@
|
||||||
version: 2
|
|
||||||
updates:
|
|
||||||
- package-ecosystem: github-actions
|
|
||||||
directory: "/"
|
|
||||||
schedule:
|
|
||||||
interval: weekly
|
|
||||||
open-pull-requests-limit: 10
|
|
128
.github/workflows/test.yaml
vendored
128
.github/workflows/test.yaml
vendored
|
@ -3,7 +3,6 @@ name: Test Action
|
||||||
on:
|
on:
|
||||||
- push
|
- push
|
||||||
- pull_request
|
- pull_request
|
||||||
- workflow_dispatch
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test_default_inputs:
|
test_default_inputs:
|
||||||
|
@ -15,19 +14,19 @@ jobs:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
pnpm:
|
pnpm:
|
||||||
- 9.15.5
|
- 4.11.1
|
||||||
os:
|
os:
|
||||||
- ubuntu-latest
|
- ubuntu-latest
|
||||||
- macos-latest
|
- macos-latest
|
||||||
- windows-latest
|
- windows-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Run the action
|
- name: Run the action
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
version: 9.15.5
|
version: 4.11.1
|
||||||
|
|
||||||
- name: 'Test: which'
|
- name: 'Test: which'
|
||||||
run: which pnpm; which pnpx
|
run: which pnpm; which pnpx
|
||||||
|
@ -35,8 +34,8 @@ jobs:
|
||||||
- name: 'Test: install'
|
- name: 'Test: install'
|
||||||
run: pnpm install
|
run: pnpm install
|
||||||
|
|
||||||
test_dest:
|
test_explicit_inputs:
|
||||||
name: Test with dest
|
name: Test with explicit inputs
|
||||||
|
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
|
|
||||||
|
@ -44,132 +43,25 @@ jobs:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
pnpm:
|
pnpm:
|
||||||
- 9.15.5
|
- 4.11.1
|
||||||
os:
|
os:
|
||||||
- ubuntu-latest
|
- ubuntu-latest
|
||||||
- macos-latest
|
- macos-latest
|
||||||
- windows-latest
|
- windows-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Run the action
|
- name: Run the action
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
version: 9.15.5
|
version: 4.11.1
|
||||||
dest: ~/test/pnpm
|
dest: ~/test/pnpm
|
||||||
|
bin_dest: ~/test/pnpm/.bin
|
||||||
|
registry: http://registry.yarnpkg.com/
|
||||||
|
|
||||||
- name: 'Test: which'
|
- name: 'Test: which'
|
||||||
run: which pnpm && which pnpx
|
run: which pnpm && which pnpx
|
||||||
|
|
||||||
- name: 'Test: install'
|
- name: 'Test: install'
|
||||||
run: pnpm 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 }})'
|
|
||||||
|
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
pnpm:
|
|
||||||
- 9.15.5
|
|
||||||
os:
|
|
||||||
- ubuntu-latest
|
|
||||||
- macos-latest
|
|
||||||
- windows-latest
|
|
||||||
run_install:
|
|
||||||
- name: 'null'
|
|
||||||
value: 'null'
|
|
||||||
- name: 'empty object'
|
|
||||||
value: '{}'
|
|
||||||
- name: 'recursive'
|
|
||||||
value: |
|
|
||||||
recursive: true
|
|
||||||
- name: 'global'
|
|
||||||
value: |
|
|
||||||
args:
|
|
||||||
- --global
|
|
||||||
- --global-dir=./pnpm-global
|
|
||||||
- npm
|
|
||||||
- yarn
|
|
||||||
- name: 'array'
|
|
||||||
value: |
|
|
||||||
- {}
|
|
||||||
- recursive: true
|
|
||||||
- args:
|
|
||||||
- --global
|
|
||||||
- --global-dir=./pnpm-global
|
|
||||||
- npm
|
|
||||||
- yarn
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Run the action
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
version: 9.15.5
|
|
||||||
run_install: ${{ matrix.run_install.value }}
|
|
||||||
|
|
||||||
- name: 'Test: which'
|
|
||||||
run: which pnpm; which pnpx
|
|
||||||
|
|
||||||
- name: 'Test: install'
|
|
||||||
run: pnpm install
|
|
||||||
|
|
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -2,12 +2,9 @@ node_modules
|
||||||
*.log
|
*.log
|
||||||
/dist/*
|
/dist/*
|
||||||
!/dist/index.js
|
!/dist/index.js
|
||||||
!/dist/pnpm.cjs
|
|
||||||
!/dist/worker.js
|
|
||||||
tmp
|
tmp
|
||||||
temp
|
temp
|
||||||
*.tmp
|
*.tmp
|
||||||
*.temp
|
*.temp
|
||||||
tmp.*
|
tmp.*
|
||||||
temp.*
|
temp.*
|
||||||
.pnpm-store
|
|
||||||
|
|
133
README.md
133
README.md
|
@ -1,56 +1,24 @@
|
||||||
> ## :warning: Upgrade from v2!
|
# Setup PNPM
|
||||||
>
|
|
||||||
> 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.
|
||||||
|
|
||||||
Install pnpm package manager.
|
|
||||||
|
|
||||||
## Inputs
|
## Inputs
|
||||||
|
|
||||||
### `version`
|
### `version`
|
||||||
|
|
||||||
Version of pnpm to install.
|
**Required** 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`
|
### `bin_dest`
|
||||||
|
|
||||||
**Optional** (_default:_ `null`) If specified, run `pnpm install`.
|
**Optional** Where to store executables (`pnpm` and `pnpx` commands).
|
||||||
|
|
||||||
If `run_install` is either `null` or `false`, pnpm will not install any npm package.
|
### `registry`
|
||||||
|
|
||||||
If `run_install` is `true`, pnpm will install dependencies recursively.
|
**Optional** Registry to download PNPM from.
|
||||||
|
|
||||||
If `run_install` is a YAML string representation of either an object or an array, pnpm will execute every install commands.
|
|
||||||
|
|
||||||
#### `run_install.recursive`
|
|
||||||
|
|
||||||
**Optional** (_type:_ `boolean`, _default:_ `false`) Whether to use `pnpm recursive install`.
|
|
||||||
|
|
||||||
#### `run_install.cwd`
|
|
||||||
|
|
||||||
**Optional** (_type:_ `string`) Working directory when run `pnpm [recursive] install`.
|
|
||||||
|
|
||||||
#### `run_install.args`
|
|
||||||
|
|
||||||
**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
|
## Outputs
|
||||||
|
|
||||||
|
@ -60,106 +28,33 @@ Expanded path of inputs#dest.
|
||||||
|
|
||||||
### `bin_dest`
|
### `bin_dest`
|
||||||
|
|
||||||
Location of `pnpm` and `pnpx` command.
|
Expanded path of inputs@bin_dest.
|
||||||
|
|
||||||
## Usage example
|
## Usage example
|
||||||
|
|
||||||
### 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:
|
||||||
- push
|
- push
|
||||||
- pull_request
|
- pull_request
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
install:
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: pnpm/action-setup@v4
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- uses: pnpm/action-setup@v1.1.0
|
||||||
with:
|
with:
|
||||||
version: 10
|
version: 4.11.1
|
||||||
```
|
|
||||||
|
|
||||||
### 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
|
|
||||||
|
|
||||||
```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: [--frozen-lockfile, --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
|
|
||||||
run_install: false
|
|
||||||
|
|
||||||
- name: Install Node.js
|
|
||||||
uses: actions/setup-node@v4
|
|
||||||
with:
|
|
||||||
node-version: 20
|
|
||||||
cache: 'pnpm'
|
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: pnpm install
|
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
|
## Notes
|
||||||
|
|
||||||
This action does not setup Node.js for you, use [actions/setup-node](https://github.com/actions/setup-node) yourself.
|
This action does not setup Node.js for you, use [actions/setup-node](https://github.com/actions/setup-node) yourself.
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
[MIT](https://github.com/pnpm/action-setup/blob/master/LICENSE.md) © [Hoàng Văn Khải](https://github.com/KSXGitHub/)
|
[MIT](https://git.io/JfclH) © [Hoàng Văn Khải](https://github.com/KSXGitHub/)
|
||||||
|
|
36
action.yml
36
action.yml
|
@ -1,34 +1,24 @@
|
||||||
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: false
|
required: true
|
||||||
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:
|
|
||||||
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:
|
bin_dest:
|
||||||
description: Location of `pnpm` and `pnpx` command
|
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
|
||||||
runs:
|
runs:
|
||||||
using: node20
|
using: node12
|
||||||
main: dist/index.js
|
main: dist/index.js
|
||||||
post: dist/index.js
|
|
||||||
|
|
BIN
dist/index.js
vendored
BIN
dist/index.js
vendored
Binary file not shown.
220780
dist/pnpm.cjs
vendored
220780
dist/pnpm.cjs
vendored
File diff suppressed because one or more lines are too long
16625
dist/worker.js
vendored
16625
dist/worker.js
vendored
File diff suppressed because it is too large
Load Diff
19
package.json
19
package.json
|
@ -3,21 +3,18 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build:ncc": "ncc build --minify --no-source-map-register --no-cache dist/tsc/index.js --out dist/",
|
"build:ncc": "ncc build --minify --no-source-map-register --no-cache dist/tsc/index.js --out dist/",
|
||||||
"build": "tsc && pnpm run build:ncc",
|
"build": "tsc && pnpm run build:ncc",
|
||||||
"start": "pnpm run build && sh ./run.sh",
|
"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": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.10.1",
|
"download": "^8.0.0",
|
||||||
"@types/expand-tilde": "^2.0.2",
|
|
||||||
"@types/node": "^20.11.5",
|
|
||||||
"@types/node-fetch": "^2.6.11",
|
|
||||||
"expand-tilde": "^2.0.2",
|
"expand-tilde": "^2.0.2",
|
||||||
"yaml": "^2.3.4",
|
"@actions/core": "^1.2.4",
|
||||||
"zod": "^3.22.4"
|
"@types/download": "^6.2.4",
|
||||||
|
"@types/expand-tilde": "^2.0.0",
|
||||||
|
"@types/node": "^13.13.5"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@vercel/ncc": "^0.38.1",
|
"typescript": "^3.8.3",
|
||||||
"pnpm": "^8.14.3",
|
"@zeit/ncc": "^0.22.1"
|
||||||
"typescript": "^5.3.3"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
998
pnpm-lock.yaml
998
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
|
@ -1,10 +1,6 @@
|
||||||
{
|
{
|
||||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
|
||||||
"pinVersions": false,
|
"pinVersions": false,
|
||||||
"extends": [
|
"extends": [
|
||||||
"config:base"
|
"config:base"
|
||||||
],
|
|
||||||
"ignoreDeps": [
|
|
||||||
"ajv"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
4
run.sh
4
run.sh
|
@ -3,6 +3,6 @@
|
||||||
export HOME="$(pwd)"
|
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_BIN_DEST='~/pnpm.temp/.bin'
|
||||||
export INPUT_standalone=false
|
export INPUT_REGISTRY=https://registry.npmjs.com
|
||||||
exec node dist/index.js
|
exec node dist/index.js
|
||||||
|
|
13
src/index.ts
13
src/index.ts
|
@ -1,19 +1,14 @@
|
||||||
import { setFailed, saveState, getState } from '@actions/core'
|
import { setFailed } from '@actions/core'
|
||||||
import getInputs from './inputs'
|
import getInputs from './inputs'
|
||||||
import installPnpm from './install-pnpm'
|
|
||||||
import setOutputs from './outputs'
|
import setOutputs from './outputs'
|
||||||
import pnpmInstall from './pnpm-install'
|
import install from './install'
|
||||||
import pruneStore from './pnpm-store-prune'
|
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
const inputs = getInputs()
|
const inputs = getInputs()
|
||||||
const isPost = getState('is_post')
|
await install(inputs).then(() => {
|
||||||
if (isPost === 'true') return pruneStore(inputs)
|
|
||||||
saveState('is_post', 'true')
|
|
||||||
await installPnpm(inputs)
|
|
||||||
console.log('Installation Completed!')
|
console.log('Installation Completed!')
|
||||||
setOutputs(inputs)
|
setOutputs(inputs)
|
||||||
pnpmInstall(inputs)
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
main().catch(error => {
|
main().catch(error => {
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
import { getBooleanInput, getInput, InputOptions } from '@actions/core'
|
import { getInput, InputOptions } from '@actions/core'
|
||||||
import expandTilde from 'expand-tilde'
|
import expandTilde from 'expand-tilde'
|
||||||
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 runInstall: RunInstall[]
|
readonly binDest: string
|
||||||
readonly packageJsonFile: string
|
readonly registry: string
|
||||||
readonly standalone: boolean
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const options: InputOptions = {
|
const options: InputOptions = {
|
||||||
|
@ -17,11 +15,10 @@ 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'),
|
version: getInput('version', options),
|
||||||
dest: parseInputPath('dest'),
|
dest: parseInputPath('dest'),
|
||||||
runInstall: parseRunInstall('run_install'),
|
binDest: parseInputPath('bin_dest'),
|
||||||
packageJsonFile: parseInputPath('package_json_file'),
|
registry: getInput('registry', options),
|
||||||
standalone: getBooleanInput('standalone'),
|
|
||||||
})
|
})
|
||||||
|
|
||||||
export default getInputs
|
export default getInputs
|
||||||
|
|
|
@ -1,41 +0,0 @@
|
||||||
import { getInput, error } from '@actions/core'
|
|
||||||
import * as yaml from 'yaml'
|
|
||||||
import { z, ZodError } from 'zod'
|
|
||||||
|
|
||||||
const RunInstallSchema = z.object({
|
|
||||||
recursive: z.boolean().optional(),
|
|
||||||
cwd: z.string().optional(),
|
|
||||||
args: z.array(z.string()).optional(),
|
|
||||||
})
|
|
||||||
|
|
||||||
const RunInstallInputSchema = z.union([
|
|
||||||
z.null(),
|
|
||||||
z.boolean(),
|
|
||||||
RunInstallSchema,
|
|
||||||
z.array(RunInstallSchema),
|
|
||||||
])
|
|
||||||
|
|
||||||
export type RunInstallInput = z.infer<typeof RunInstallInputSchema>
|
|
||||||
export type RunInstall = z.infer<typeof RunInstallSchema>
|
|
||||||
|
|
||||||
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}`)
|
|
||||||
}
|
|
||||||
process.exit(1)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,104 +0,0 @@
|
||||||
import { addPath, exportVariable } from '@actions/core'
|
|
||||||
import { spawn } from 'child_process'
|
|
||||||
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, packageJsonFile, standalone } = inputs
|
|
||||||
|
|
||||||
// prepare self install
|
|
||||||
await rm(dest, { recursive: true, force: true })
|
|
||||||
// create dest directory after removal
|
|
||||||
await mkdir(dest, { recursive: true })
|
|
||||||
const pkgJson = path.join(dest, 'package.json')
|
|
||||||
// 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, packageJsonFile, standalone })
|
|
||||||
const cp = spawn(execPath, [path.join(__dirname, 'pnpm.cjs'), 'install', target, '--no-lockfile'], {
|
|
||||||
cwd: dest,
|
|
||||||
stdio: ['pipe', 'inherit', 'inherit'],
|
|
||||||
})
|
|
||||||
|
|
||||||
const exitCode = await new Promise<number>((resolve, reject) => {
|
|
||||||
cp.on('error', reject)
|
|
||||||
cp.on('close', resolve)
|
|
||||||
})
|
|
||||||
if (exitCode === 0) {
|
|
||||||
const pnpmHome = path.join(dest, 'node_modules/.bin')
|
|
||||||
addPath(pnpmHome)
|
|
||||||
exportVariable('PNPM_HOME', pnpmHome)
|
|
||||||
}
|
|
||||||
return exitCode
|
|
||||||
}
|
|
||||||
|
|
||||||
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'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.`)
|
|
||||||
}
|
|
||||||
|
|
||||||
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"`)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!packageManager.startsWith('pnpm@')) {
|
|
||||||
throw new Error('Invalid packageManager field in package.json')
|
|
||||||
}
|
|
||||||
|
|
||||||
if (standalone) {
|
|
||||||
return packageManager.replace('pnpm@', '@pnpm/exe@')
|
|
||||||
}
|
|
||||||
|
|
||||||
return packageManager
|
|
||||||
}
|
|
||||||
|
|
||||||
export default runSelfInstaller
|
|
|
@ -1,15 +1,13 @@
|
||||||
import { setFailed, startGroup, endGroup } from '@actions/core'
|
import { setFailed } from '@actions/core'
|
||||||
import { Inputs } from '../inputs'
|
import { Inputs } from '../inputs'
|
||||||
import runSelfInstaller from './run'
|
import runSelfInstaller from './run'
|
||||||
|
|
||||||
export { runSelfInstaller }
|
export { runSelfInstaller }
|
||||||
|
|
||||||
export async function install(inputs: Inputs) {
|
export async function install(inputs: Inputs) {
|
||||||
startGroup('Running self-installer...')
|
|
||||||
const status = await runSelfInstaller(inputs)
|
const status = await runSelfInstaller(inputs)
|
||||||
endGroup()
|
|
||||||
if (status) {
|
if (status) {
|
||||||
return setFailed(`Something went wrong, self-installer exits with code ${status}`)
|
return setFailed(`Something does wrong, self-installer exits with code ${status}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
25
src/install/run.ts
Normal file
25
src/install/run.ts
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
import { spawn } from 'child_process'
|
||||||
|
import { execPath } from 'process'
|
||||||
|
import { downloadSelfInstaller } from '../self-installer'
|
||||||
|
import { Inputs } from '../inputs'
|
||||||
|
|
||||||
|
export 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'],
|
||||||
|
})
|
||||||
|
|
||||||
|
downloadSelfInstaller().pipe(cp.stdin)
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
cp.on('error', reject)
|
||||||
|
cp.on('close', resolve)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export default runSelfInstaller
|
|
@ -1,12 +1,10 @@
|
||||||
import { setOutput, addPath } from '@actions/core'
|
import { setOutput, addPath } from '@actions/core'
|
||||||
import { Inputs } from '../inputs'
|
import { Inputs } from '../inputs'
|
||||||
import { getBinDest } from '../utils'
|
|
||||||
|
|
||||||
export function setOutputs(inputs: Inputs) {
|
export function setOutputs(inputs: Inputs) {
|
||||||
const binDest = getBinDest(inputs)
|
addPath(inputs.binDest)
|
||||||
addPath(binDest)
|
|
||||||
setOutput('dest', inputs.dest)
|
setOutput('dest', inputs.dest)
|
||||||
setOutput('bin_dest', binDest)
|
setOutput('bin_dest', inputs.binDest)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default setOutputs
|
export default setOutputs
|
||||||
|
|
|
@ -1,38 +0,0 @@
|
||||||
import { setFailed, startGroup, endGroup } from '@actions/core'
|
|
||||||
import { spawnSync } from 'child_process'
|
|
||||||
import { Inputs } from '../inputs'
|
|
||||||
import { patchPnpmEnv } from '../utils'
|
|
||||||
|
|
||||||
export function runPnpmInstall(inputs: Inputs) {
|
|
||||||
const env = patchPnpmEnv(inputs)
|
|
||||||
|
|
||||||
for (const options of inputs.runInstall) {
|
|
||||||
const args = ['install']
|
|
||||||
if (options.recursive) args.unshift('recursive')
|
|
||||||
if (options.args) args.push(...options.args)
|
|
||||||
|
|
||||||
const cmdStr = ['pnpm', ...args].join(' ')
|
|
||||||
startGroup(`Running ${cmdStr}...`)
|
|
||||||
|
|
||||||
const { error, status } = spawnSync('pnpm', args, {
|
|
||||||
stdio: 'inherit',
|
|
||||||
cwd: options.cwd,
|
|
||||||
shell: true,
|
|
||||||
env,
|
|
||||||
})
|
|
||||||
|
|
||||||
endGroup()
|
|
||||||
|
|
||||||
if (error) {
|
|
||||||
setFailed(error)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if (status) {
|
|
||||||
setFailed(`Command ${cmdStr} (cwd: ${options.cwd}) exits with status ${status}`)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default runPnpmInstall
|
|
|
@ -1,31 +0,0 @@
|
||||||
import { warning, startGroup, endGroup } from '@actions/core'
|
|
||||||
import { spawnSync } from 'child_process'
|
|
||||||
import { Inputs } from '../inputs'
|
|
||||||
import { patchPnpmEnv } from '../utils'
|
|
||||||
|
|
||||||
export function pruneStore(inputs: Inputs) {
|
|
||||||
if (inputs.runInstall.length === 0) {
|
|
||||||
console.log('Pruning is unnecessary.')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
startGroup('Running pnpm store prune...')
|
|
||||||
const { error, status } = spawnSync('pnpm', ['store', 'prune'], {
|
|
||||||
stdio: 'inherit',
|
|
||||||
shell: true,
|
|
||||||
env: patchPnpmEnv(inputs),
|
|
||||||
})
|
|
||||||
endGroup()
|
|
||||||
|
|
||||||
if (error) {
|
|
||||||
warning(error)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (status) {
|
|
||||||
warning(`command pnpm store prune exits with code ${status}`)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default pruneStore
|
|
4
src/self-installer/download.ts
Normal file
4
src/self-installer/download.ts
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
import download from 'download'
|
||||||
|
import url from './url'
|
||||||
|
export const downloadSelfInstaller = () => download(url)
|
||||||
|
export default downloadSelfInstaller
|
2
src/self-installer/index.ts
Normal file
2
src/self-installer/index.ts
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
export * from './url'
|
||||||
|
export * from './download'
|
3
src/self-installer/url.ts
Normal file
3
src/self-installer/url.ts
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
export const ref = '301414cec74a2b6b63c95b42f2ad1790ccb980ed'
|
||||||
|
export const url = `https://raw.githubusercontent.com/pnpm/self-installer/${ref}/install.js`
|
||||||
|
export default url
|
|
@ -1,10 +0,0 @@
|
||||||
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: getBinDest(inputs) + path.delimiter + process.env.PATH,
|
|
||||||
})
|
|
|
@ -1,11 +1,15 @@
|
||||||
|
|
||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "ES2022",
|
"target": "ES2018",
|
||||||
"module": "Node16",
|
"module": "CommonJS",
|
||||||
|
"moduleResolution": "Node",
|
||||||
"resolveJsonModule": true,
|
"resolveJsonModule": true,
|
||||||
"lib": [
|
"lib": [
|
||||||
"ES2023"
|
"ES2018",
|
||||||
|
"ES2019",
|
||||||
|
"ES2020",
|
||||||
|
"ESNext"
|
||||||
],
|
],
|
||||||
"outDir": "./dist/tsc",
|
"outDir": "./dist/tsc",
|
||||||
"preserveConstEnums": true,
|
"preserveConstEnums": true,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user