mirror of
https://github.com/pnpm/action-setup.git
synced 2025-04-18 18:12:51 +08:00
Compare commits
No commits in common. "master" and "v2.2.1" have entirely different histories.
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']
|
||||||
|
3
.github/dependabot.yml
vendored
3
.github/dependabot.yml
vendored
@ -5,3 +5,6 @@ updates:
|
|||||||
schedule:
|
schedule:
|
||||||
interval: weekly
|
interval: weekly
|
||||||
open-pull-requests-limit: 10
|
open-pull-requests-limit: 10
|
||||||
|
labels:
|
||||||
|
- dependabot
|
||||||
|
- github-actions
|
||||||
|
79
.github/workflows/test.yaml
vendored
79
.github/workflows/test.yaml
vendored
@ -15,19 +15,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 +35,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,19 +44,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
|
||||||
dest: ~/test/pnpm
|
dest: ~/test/pnpm
|
||||||
|
|
||||||
- name: 'Test: which'
|
- name: 'Test: which'
|
||||||
@ -65,61 +65,6 @@ jobs:
|
|||||||
- 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:
|
test_run_install:
|
||||||
name: 'Test with run_install (${{ matrix.run_install.name }}, ${{ matrix.os }})'
|
name: 'Test with run_install (${{ matrix.run_install.name }}, ${{ matrix.os }})'
|
||||||
|
|
||||||
@ -129,7 +74,7 @@ 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
|
||||||
@ -149,6 +94,7 @@ jobs:
|
|||||||
- --global-dir=./pnpm-global
|
- --global-dir=./pnpm-global
|
||||||
- npm
|
- npm
|
||||||
- yarn
|
- yarn
|
||||||
|
- pnpm
|
||||||
- name: 'array'
|
- name: 'array'
|
||||||
value: |
|
value: |
|
||||||
- {}
|
- {}
|
||||||
@ -158,14 +104,15 @@ jobs:
|
|||||||
- --global-dir=./pnpm-global
|
- --global-dir=./pnpm-global
|
||||||
- npm
|
- npm
|
||||||
- yarn
|
- yarn
|
||||||
|
- pnpm
|
||||||
|
|
||||||
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
|
||||||
run_install: ${{ matrix.run_install.value }}
|
run_install: ${{ matrix.run_install.value }}
|
||||||
|
|
||||||
- name: 'Test: which'
|
- name: 'Test: which'
|
||||||
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -2,8 +2,6 @@ node_modules
|
|||||||
*.log
|
*.log
|
||||||
/dist/*
|
/dist/*
|
||||||
!/dist/index.js
|
!/dist/index.js
|
||||||
!/dist/pnpm.cjs
|
|
||||||
!/dist/worker.js
|
|
||||||
tmp
|
tmp
|
||||||
temp
|
temp
|
||||||
*.tmp
|
*.tmp
|
||||||
|
75
README.md
75
README.md
@ -1,7 +1,3 @@
|
|||||||
> ## :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
|
# Setup pnpm
|
||||||
|
|
||||||
Install pnpm package manager.
|
Install pnpm package manager.
|
||||||
@ -42,16 +38,6 @@ 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]`.
|
**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
|
||||||
|
|
||||||
### `dest`
|
### `dest`
|
||||||
@ -64,9 +50,7 @@ Location of `pnpm` and `pnpx` command.
|
|||||||
|
|
||||||
## Usage example
|
## Usage example
|
||||||
|
|
||||||
### Install only pnpm without `packageManager`
|
### Just install pnpm
|
||||||
|
|
||||||
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:
|
||||||
@ -78,26 +62,9 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: pnpm/action-setup@v4
|
- uses: pnpm/action-setup@v2.1.0
|
||||||
with:
|
with:
|
||||||
version: 10
|
version: 6.0.2
|
||||||
```
|
|
||||||
|
|
||||||
### 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
|
### Install pnpm and a few npm packages
|
||||||
@ -112,11 +79,11 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
- uses: pnpm/action-setup@v4
|
- uses: pnpm/action-setup@v2.1.0
|
||||||
with:
|
with:
|
||||||
version: 10
|
version: 6.0.2
|
||||||
run_install: |
|
run_install: |
|
||||||
- recursive: true
|
- recursive: true
|
||||||
args: [--frozen-lockfile, --strict-peer-dependencies]
|
args: [--frozen-lockfile, --strict-peer-dependencies]
|
||||||
@ -135,23 +102,21 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
build:
|
||||||
uses: actions/checkout@v4
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
- uses: pnpm/action-setup@v4
|
- name: Cache pnpm modules
|
||||||
name: Install pnpm
|
uses: actions/cache@v2
|
||||||
with:
|
with:
|
||||||
version: 10
|
path: ~/.pnpm-store
|
||||||
run_install: false
|
key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-
|
||||||
|
|
||||||
- name: Install Node.js
|
- uses: pnpm/action-setup@v2.1.0
|
||||||
uses: actions/setup-node@v4
|
with:
|
||||||
with:
|
version: 6.0.2
|
||||||
node-version: 20
|
run_install: true
|
||||||
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.
|
**Note:** You don't need to run `pnpm store prune` at the end; post-action has already taken care of that.
|
||||||
@ -162,4 +127,4 @@ This action does not setup Node.js for you, use [actions/setup-node](https://git
|
|||||||
|
|
||||||
## 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/)
|
||||||
|
24
action.yml
24
action.yml
@ -1,34 +1,20 @@
|
|||||||
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
|
|
||||||
dest:
|
dest:
|
||||||
description: Where to store pnpm files
|
description: Where to store PNPM files
|
||||||
required: false
|
required: false
|
||||||
default: ~/setup-pnpm
|
default: ~/setup-pnpm
|
||||||
run_install:
|
run_install:
|
||||||
description: If specified, run `pnpm install`
|
description: If specified, run `pnpm install`
|
||||||
required: false
|
required: false
|
||||||
default: 'null'
|
default: 'null'
|
||||||
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:
|
runs:
|
||||||
using: node20
|
using: node12
|
||||||
main: dist/index.js
|
main: dist/index.js
|
||||||
post: dist/index.js
|
post: dist/index.js
|
||||||
|
34
dist/index.js
vendored
34
dist/index.js
vendored
File diff suppressed because one or more lines are too long
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
29
package.json
29
package.json
@ -1,23 +1,28 @@
|
|||||||
{
|
{
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"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:ncc": "ncc build --minify --no-source-map-register --no-cache dist/tsc/index.js --out dist/",
|
||||||
"build": "tsc && pnpm run build:ncc",
|
"build": "pnpm run build:schemas && 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",
|
"@actions/core": "^1.6.0",
|
||||||
"@types/expand-tilde": "^2.0.2",
|
"@pnpm/fetch": "^4.2.5",
|
||||||
"@types/node": "^20.11.5",
|
"@pnpm/logger": "^4.0.0",
|
||||||
"@types/node-fetch": "^2.6.11",
|
"@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",
|
||||||
"expand-tilde": "^2.0.2",
|
"expand-tilde": "^2.0.2",
|
||||||
"yaml": "^2.3.4",
|
"fs-extra": "^10.0.0",
|
||||||
"zod": "^3.22.4"
|
"js-yaml": "^4.1.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@vercel/ncc": "^0.38.1",
|
"@ts-schema-autogen/cli": "^0.1.2",
|
||||||
"pnpm": "^8.14.3",
|
"@vercel/ncc": "^0.33.3",
|
||||||
"typescript": "^5.3.3"
|
"typescript": "^4.5.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
1223
pnpm-lock.yaml
generated
1223
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
1
run.sh
1
run.sh
@ -4,5 +4,4 @@ export HOME="$(pwd)"
|
|||||||
export INPUT_VERSION=4.11.1
|
export INPUT_VERSION=4.11.1
|
||||||
export INPUT_DEST='~/pnpm.temp'
|
export INPUT_DEST='~/pnpm.temp'
|
||||||
export INPUT_RUN_INSTALL=null
|
export INPUT_RUN_INSTALL=null
|
||||||
export INPUT_standalone=false
|
|
||||||
exec node dist/index.js
|
exec node dist/index.js
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
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'
|
import { RunInstall, parseRunInstall } from './run-install'
|
||||||
|
|
||||||
@ -6,8 +6,6 @@ export interface Inputs {
|
|||||||
readonly version?: string
|
readonly version?: string
|
||||||
readonly dest: string
|
readonly dest: string
|
||||||
readonly runInstall: RunInstall[]
|
readonly runInstall: RunInstall[]
|
||||||
readonly packageJsonFile: string
|
|
||||||
readonly standalone: boolean
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const options: InputOptions = {
|
const options: InputOptions = {
|
||||||
@ -20,8 +18,6 @@ export const getInputs = (): Inputs => ({
|
|||||||
version: getInput('version'),
|
version: getInput('version'),
|
||||||
dest: parseInputPath('dest'),
|
dest: parseInputPath('dest'),
|
||||||
runInstall: parseRunInstall('run_install'),
|
runInstall: parseRunInstall('run_install'),
|
||||||
packageJsonFile: parseInputPath('package_json_file'),
|
|
||||||
standalone: getBooleanInput('standalone'),
|
|
||||||
})
|
})
|
||||||
|
|
||||||
export default getInputs
|
export default getInputs
|
||||||
|
21
src/inputs/run-install-input.schema.autogen.json
Normal file
21
src/inputs/run-install-input.schema.autogen.json
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"$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"
|
||||||
|
}
|
||||||
|
}
|
39
src/inputs/run-install-input.schema.json
Normal file
39
src/inputs/run-install-input.schema.json
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
{
|
||||||
|
"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,41 +1,39 @@
|
|||||||
import { getInput, error } from '@actions/core'
|
import { getInput, error, InputOptions } from '@actions/core'
|
||||||
import * as yaml from 'yaml'
|
import Ajv from 'ajv'
|
||||||
import { z, ZodError } from 'zod'
|
import { load } from 'js-yaml'
|
||||||
|
import process from 'process'
|
||||||
|
import runInstallSchema from './run-install-input.schema.json'
|
||||||
|
|
||||||
const RunInstallSchema = z.object({
|
export interface RunInstall {
|
||||||
recursive: z.boolean().optional(),
|
readonly recursive?: boolean
|
||||||
cwd: z.string().optional(),
|
readonly cwd?: string
|
||||||
args: z.array(z.string()).optional(),
|
readonly args?: readonly string[]
|
||||||
})
|
}
|
||||||
|
|
||||||
const RunInstallInputSchema = z.union([
|
export type RunInstallInput =
|
||||||
z.null(),
|
| null
|
||||||
z.boolean(),
|
| boolean
|
||||||
RunInstallSchema,
|
| RunInstall
|
||||||
z.array(RunInstallSchema),
|
| RunInstall[]
|
||||||
])
|
|
||||||
|
const options: InputOptions = {
|
||||||
export type RunInstallInput = z.infer<typeof RunInstallInputSchema>
|
required: true,
|
||||||
export type RunInstall = z.infer<typeof RunInstallSchema>
|
}
|
||||||
|
|
||||||
export function parseRunInstall(inputName: string): RunInstall[] {
|
export function parseRunInstall(name: string): RunInstall[] {
|
||||||
const input = getInput(inputName, { required: true })
|
const result: RunInstallInput = load(getInput(name, options)) as any
|
||||||
const parsedInput: unknown = yaml.parse(input)
|
const ajv = new Ajv({
|
||||||
|
allErrors: true,
|
||||||
try {
|
})
|
||||||
const result: RunInstallInput = RunInstallInputSchema.parse(parsedInput)
|
const validate = ajv.compile(runInstallSchema)
|
||||||
if (!result) return []
|
if (!validate(result)) {
|
||||||
if (result === true) return [{ recursive: true }]
|
for (const errorItem of validate.errors!) {
|
||||||
if (Array.isArray(result)) return result
|
error(`with.run_install${errorItem.dataPath}: ${errorItem.message}`)
|
||||||
return [result]
|
}
|
||||||
} catch (exception: unknown) {
|
return process.exit(1)
|
||||||
error(`Error for input "${inputName}" = ${input}`)
|
}
|
||||||
|
if (!result) return []
|
||||||
if (exception instanceof ZodError) {
|
if (result === true) return [{ recursive: true }]
|
||||||
error(`Errors: ${exception.errors}`)
|
if (Array.isArray(result)) return result
|
||||||
} else {
|
return [result]
|
||||||
error(`Exception: ${exception}`)
|
|
||||||
}
|
|
||||||
process.exit(1)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,31 +1,31 @@
|
|||||||
import { addPath, exportVariable } from '@actions/core'
|
import { addPath, exportVariable } from '@actions/core'
|
||||||
|
import fetch from '@pnpm/fetch'
|
||||||
import { spawn } from 'child_process'
|
import { spawn } from 'child_process'
|
||||||
import { rm, writeFile, mkdir } from 'fs/promises'
|
import { remove, ensureFile, writeFile, readFile } from 'fs-extra'
|
||||||
import { readFileSync } from 'fs'
|
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
import { execPath } from 'process'
|
import { execPath } from 'process'
|
||||||
import util from 'util'
|
|
||||||
import { Inputs } from '../inputs'
|
import { Inputs } from '../inputs'
|
||||||
import YAML from 'yaml'
|
|
||||||
|
|
||||||
export async function runSelfInstaller(inputs: Inputs): Promise<number> {
|
export async function runSelfInstaller(inputs: Inputs): Promise<number> {
|
||||||
const { version, dest, packageJsonFile, standalone } = inputs
|
const { version, dest } = inputs
|
||||||
|
|
||||||
// prepare self install
|
// prepare self install
|
||||||
await rm(dest, { recursive: true, force: true })
|
await remove(dest)
|
||||||
// create dest directory after removal
|
|
||||||
await mkdir(dest, { recursive: true })
|
|
||||||
const pkgJson = path.join(dest, 'package.json')
|
const pkgJson = path.join(dest, 'package.json')
|
||||||
// we have ensured the dest directory exists, we can write the file directly
|
await ensureFile(pkgJson)
|
||||||
await writeFile(pkgJson, JSON.stringify({ private: true }))
|
await writeFile(pkgJson, JSON.stringify({ private: true }))
|
||||||
|
|
||||||
// prepare target pnpm
|
// prepare target pnpm
|
||||||
const target = await readTarget({ version, packageJsonFile, standalone })
|
const target = await readTarget(version)
|
||||||
const cp = spawn(execPath, [path.join(__dirname, 'pnpm.cjs'), 'install', target, '--no-lockfile'], {
|
const cp = spawn(execPath, ['-', 'install', target, '--no-lockfile'], {
|
||||||
cwd: dest,
|
cwd: dest,
|
||||||
stdio: ['pipe', 'inherit', 'inherit'],
|
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) => {
|
const exitCode = await new Promise<number>((resolve, reject) => {
|
||||||
cp.on('error', reject)
|
cp.on('error', reject)
|
||||||
cp.on('close', resolve)
|
cp.on('close', resolve)
|
||||||
@ -38,66 +38,28 @@ export async function runSelfInstaller(inputs: Inputs): Promise<number> {
|
|||||||
return exitCode
|
return exitCode
|
||||||
}
|
}
|
||||||
|
|
||||||
async function readTarget(opts: {
|
async function readTarget(version?: string | undefined) {
|
||||||
readonly version?: string | undefined
|
if (version) return `pnpm@${version}`
|
||||||
readonly packageJsonFile: string
|
|
||||||
readonly standalone: boolean
|
|
||||||
}) {
|
|
||||||
const { version, packageJsonFile, standalone } = opts
|
|
||||||
const { GITHUB_WORKSPACE } = process.env
|
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) {
|
if (!GITHUB_WORKSPACE) {
|
||||||
throw new Error(`No workspace is found.
|
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,
|
If you're 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.
|
please run the actions/checkout before pnpm/action-setup.
|
||||||
Otherwise, please specify the pnpm version in the action configuration.`)
|
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') {
|
if (typeof packageManager !== 'string') {
|
||||||
throw new Error(`No pnpm version is specified.
|
throw new Error(`No pnpm version is specified.
|
||||||
Please specify it by one of the following ways:
|
Please specify it by one of the following ways:
|
||||||
- in the GitHub Action config with the key "version"
|
- in the GitHub Action config with the key "version"
|
||||||
- in the package.json with the key "packageManager"`)
|
- in the package.json with the key "packageManager" (See https://nodejs.org/api/corepack.html)`)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!packageManager.startsWith('pnpm@')) {
|
if (!packageManager.startsWith('pnpm@')) {
|
||||||
throw new Error('Invalid packageManager field in package.json')
|
throw new Error('Invalid packageManager field in package.json')
|
||||||
}
|
}
|
||||||
|
|
||||||
if (standalone) {
|
|
||||||
return packageManager.replace('pnpm@', '@pnpm/exe@')
|
|
||||||
}
|
|
||||||
|
|
||||||
return packageManager
|
return packageManager
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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…
x
Reference in New Issue
Block a user