mirror of
https://github.com/pnpm/action-setup.git
synced 2025-07-08 22:59:22 +08:00
Compare commits
39 Commits
Author | SHA1 | Date | |
---|---|---|---|
187ace9a18 | |||
7f8a57faa8 | |||
268b4179de | |||
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 |
10
.github/dependabot.yml
vendored
Normal file
10
.github/dependabot.yml
vendored
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
version: 2
|
||||||
|
updates:
|
||||||
|
- package-ecosystem: github-actions
|
||||||
|
directory: "/"
|
||||||
|
schedule:
|
||||||
|
interval: weekly
|
||||||
|
open-pull-requests-limit: 10
|
||||||
|
labels:
|
||||||
|
- dependabot
|
||||||
|
- github-actions
|
20
.github/workflows/test.yaml
vendored
20
.github/workflows/test.yaml
vendored
@ -15,7 +15,7 @@ jobs:
|
|||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
pnpm:
|
pnpm:
|
||||||
- 4.11.1
|
- 6.17.1
|
||||||
os:
|
os:
|
||||||
- ubuntu-latest
|
- ubuntu-latest
|
||||||
- macos-latest
|
- macos-latest
|
||||||
@ -27,10 +27,10 @@ jobs:
|
|||||||
- name: Run the action
|
- name: Run the action
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
version: 4.11.1
|
version: 6.17.1
|
||||||
|
|
||||||
- name: 'Test: which'
|
- name: 'Test: which'
|
||||||
run: which pnpm; which pnpx
|
run: which pnpm
|
||||||
|
|
||||||
- name: 'Test: install'
|
- name: 'Test: install'
|
||||||
run: pnpm install
|
run: pnpm install
|
||||||
@ -44,7 +44,7 @@ jobs:
|
|||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
pnpm:
|
pnpm:
|
||||||
- 4.11.1
|
- 6.17.1
|
||||||
os:
|
os:
|
||||||
- ubuntu-latest
|
- ubuntu-latest
|
||||||
- macos-latest
|
- macos-latest
|
||||||
@ -56,13 +56,11 @@ jobs:
|
|||||||
- name: Run the action
|
- name: Run the action
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
version: 4.11.1
|
version: 6.17.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
|
||||||
|
|
||||||
- name: 'Test: install'
|
- name: 'Test: install'
|
||||||
run: pnpm install
|
run: pnpm install
|
||||||
@ -76,7 +74,7 @@ jobs:
|
|||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
pnpm:
|
pnpm:
|
||||||
- 4.11.1
|
- 6.17.1
|
||||||
os:
|
os:
|
||||||
- ubuntu-latest
|
- ubuntu-latest
|
||||||
- macos-latest
|
- macos-latest
|
||||||
@ -114,11 +112,11 @@ jobs:
|
|||||||
- name: Run the action
|
- name: Run the action
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
version: 4.11.1
|
version: 6.17.1
|
||||||
run_install: ${{ matrix.run_install.value }}
|
run_install: ${{ matrix.run_install.value }}
|
||||||
|
|
||||||
- name: 'Test: which'
|
- name: 'Test: which'
|
||||||
run: which pnpm; which pnpx
|
run: which pnpm
|
||||||
|
|
||||||
- name: 'Test: install'
|
- name: 'Test: install'
|
||||||
run: pnpm install
|
run: pnpm install
|
||||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -8,3 +8,4 @@ temp
|
|||||||
*.temp
|
*.temp
|
||||||
tmp.*
|
tmp.*
|
||||||
temp.*
|
temp.*
|
||||||
|
.pnpm-store
|
||||||
|
63
README.md
63
README.md
@ -1,24 +1,16 @@
|
|||||||
# Setup PNPM
|
# Setup pnpm
|
||||||
|
|
||||||
Install PNPM package manager.
|
Install pnpm package manager.
|
||||||
|
|
||||||
## Inputs
|
## Inputs
|
||||||
|
|
||||||
### `version`
|
### `version`
|
||||||
|
|
||||||
**Required** Version of PNPM to install.
|
**Required** Version of pnpm to install. 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.
|
||||||
|
|
||||||
### `bin_dest`
|
|
||||||
|
|
||||||
**Optional** Where to store executables (`pnpm` and `pnpx` commands).
|
|
||||||
|
|
||||||
### `registry`
|
|
||||||
|
|
||||||
**Optional** (_default:_ `https://registry.npmjs.com`) Registry to download PNPM from.
|
|
||||||
|
|
||||||
### `run_install`
|
### `run_install`
|
||||||
|
|
||||||
@ -50,11 +42,11 @@ Expanded path of inputs#dest.
|
|||||||
|
|
||||||
### `bin_dest`
|
### `bin_dest`
|
||||||
|
|
||||||
Expanded path of inputs#bin_dest.
|
Location of `pnpm` and `pnpx` command.
|
||||||
|
|
||||||
## Usage example
|
## Usage example
|
||||||
|
|
||||||
### Just install PNPM
|
### Just install pnpm
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
on:
|
on:
|
||||||
@ -62,15 +54,16 @@ on:
|
|||||||
- pull_request
|
- pull_request
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
install:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: pnpm/action-setup@v1.2.0
|
- uses: pnpm/action-setup@v2.1.0
|
||||||
with:
|
with:
|
||||||
version: 4.11.1
|
version: 6.0.2
|
||||||
```
|
```
|
||||||
|
|
||||||
### Install PNPM and a few NPM packages
|
### Install pnpm and a few npm packages
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
on:
|
on:
|
||||||
@ -78,20 +71,52 @@ on:
|
|||||||
- pull_request
|
- pull_request
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
install:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
- uses: pnpm/action-setup@v1.2.0
|
- uses: pnpm/action-setup@v2.1.0
|
||||||
with:
|
with:
|
||||||
version: 4.11.1
|
version: 6.0.2
|
||||||
run_install: |
|
run_install: |
|
||||||
- recursive: true
|
- recursive: true
|
||||||
args: [--frozen-lockfile, --strict-peer-dependencies]
|
args: [--frozen-lockfile, --strict-peer-dependencies]
|
||||||
- args: [--global, gulp, prettier, typescript]
|
- 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:
|
||||||
|
build:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Cache pnpm modules
|
||||||
|
uses: actions/cache@v2
|
||||||
|
with:
|
||||||
|
path: ~/.pnpm-store
|
||||||
|
key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-
|
||||||
|
|
||||||
|
- uses: pnpm/action-setup@v2.1.0
|
||||||
|
with:
|
||||||
|
version: 6.0.2
|
||||||
|
run_install: true
|
||||||
|
```
|
||||||
|
|
||||||
|
**Note:** You don't need to run `pnpm store prune` at the end; post-action has already taken care of that.
|
||||||
|
|
||||||
## 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.
|
||||||
|
@ -11,14 +11,6 @@ inputs:
|
|||||||
description: Where to store PNPM files
|
description: Where to store PNPM files
|
||||||
required: false
|
required: false
|
||||||
default: ~/setup-pnpm
|
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:
|
run_install:
|
||||||
description: If specified, run `pnpm install`
|
description: If specified, run `pnpm install`
|
||||||
required: false
|
required: false
|
||||||
|
2
dist/index.js
vendored
2
dist/index.js
vendored
File diff suppressed because one or more lines are too long
22
package.json
22
package.json
@ -7,19 +7,21 @@
|
|||||||
"start": "pnpm run build && sh ./run.sh"
|
"start": "pnpm run build && sh ./run.sh"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"node-fetch": "^2.6.1",
|
"@actions/core": "^1.6.0",
|
||||||
"expand-tilde": "^2.0.2",
|
|
||||||
"js-yaml": "^3.14.0",
|
|
||||||
"ajv": "^6.12.5",
|
|
||||||
"@actions/core": "^1.2.6",
|
|
||||||
"@types/expand-tilde": "^2.0.0",
|
"@types/expand-tilde": "^2.0.0",
|
||||||
"@types/node-fetch": "^2.5.7",
|
"@types/fs-extra": "^9.0.13",
|
||||||
"@types/js-yaml": "^3.12.5",
|
"@types/js-yaml": "^4.0.5",
|
||||||
"@types/node": "^14.11.2"
|
"@types/node": "^14.18.10",
|
||||||
|
"@types/node-fetch": "^2.5.12",
|
||||||
|
"ajv": "^6.12.6",
|
||||||
|
"expand-tilde": "^2.0.2",
|
||||||
|
"fs-extra": "^9.1.0",
|
||||||
|
"js-yaml": "^4.1.0",
|
||||||
|
"node-fetch": "^2.6.7"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"typescript": "^4.0.3",
|
|
||||||
"@ts-schema-autogen/cli": "^0.1.2",
|
"@ts-schema-autogen/cli": "^0.1.2",
|
||||||
"@zeit/ncc": "^0.22.3"
|
"@vercel/ncc": "^0.27.0",
|
||||||
|
"typescript": "^4.5.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
991
pnpm-lock.yaml
generated
991
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,
|
"pinVersions": false,
|
||||||
"extends": [
|
"extends": [
|
||||||
"config:base"
|
"config:base"
|
||||||
|
],
|
||||||
|
"ignoreDeps": [
|
||||||
|
"ajv"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
2
run.sh
2
run.sh
@ -3,7 +3,5 @@
|
|||||||
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_BIN_DEST='~/pnpm.temp/.bin'
|
|
||||||
export INPUT_REGISTRY=https://registry.npmjs.com
|
|
||||||
export INPUT_RUN_INSTALL=null
|
export INPUT_RUN_INSTALL=null
|
||||||
exec node dist/index.js
|
exec node dist/index.js
|
||||||
|
@ -5,8 +5,6 @@ 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 binDest: string
|
|
||||||
readonly registry: string
|
|
||||||
readonly runInstall: RunInstall[]
|
readonly runInstall: RunInstall[]
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -19,8 +17,6 @@ const parseInputPath = (name: string) => expandTilde(getInput(name, options))
|
|||||||
export const getInputs = (): Inputs => ({
|
export const getInputs = (): Inputs => ({
|
||||||
version: getInput('version', options),
|
version: getInput('version', options),
|
||||||
dest: parseInputPath('dest'),
|
dest: parseInputPath('dest'),
|
||||||
binDest: parseInputPath('bin_dest'),
|
|
||||||
registry: getInput('registry', options),
|
|
||||||
runInstall: parseRunInstall('run_install'),
|
runInstall: parseRunInstall('run_install'),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import process from 'process'
|
import process from 'process'
|
||||||
import { safeLoad } from 'js-yaml'
|
import { load } from 'js-yaml'
|
||||||
import Ajv from 'ajv'
|
import Ajv from 'ajv'
|
||||||
import { getInput, error, InputOptions } from '@actions/core'
|
import { getInput, error, InputOptions } from '@actions/core'
|
||||||
import runInstallSchema from './run-install-input.schema.json'
|
import runInstallSchema from './run-install-input.schema.json'
|
||||||
@ -21,10 +21,9 @@ const options: InputOptions = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function parseRunInstall(name: string): RunInstall[] {
|
export function parseRunInstall(name: string): RunInstall[] {
|
||||||
const result: RunInstallInput = safeLoad(getInput(name, options)) as any
|
const result: RunInstallInput = load(getInput(name, options)) as any
|
||||||
const ajv = new Ajv({
|
const ajv = new Ajv({
|
||||||
allErrors: true,
|
allErrors: true,
|
||||||
async: false,
|
|
||||||
})
|
})
|
||||||
const validate = ajv.compile(runInstallSchema)
|
const validate = ajv.compile(runInstallSchema)
|
||||||
if (!validate(result)) {
|
if (!validate(result)) {
|
||||||
|
@ -9,7 +9,7 @@ export async function install(inputs: Inputs) {
|
|||||||
const status = await runSelfInstaller(inputs)
|
const status = await runSelfInstaller(inputs)
|
||||||
endGroup()
|
endGroup()
|
||||||
if (status) {
|
if (status) {
|
||||||
return setFailed(`Something does wrong, self-installer exits with code ${status}`)
|
return setFailed(`Something went wrong, self-installer exits with code ${status}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,26 +1,38 @@
|
|||||||
|
import { addPath, exportVariable } from '@actions/core'
|
||||||
import { spawn } from 'child_process'
|
import { spawn } from 'child_process'
|
||||||
import { execPath } from 'process'
|
import { execPath } from 'process'
|
||||||
import { downloadSelfInstaller } from '../self-installer'
|
import path from 'path'
|
||||||
|
import { remove, ensureFile, writeFile } from 'fs-extra'
|
||||||
|
import fetch from 'node-fetch'
|
||||||
import { Inputs } from '../inputs'
|
import { Inputs } from '../inputs'
|
||||||
|
|
||||||
export async function runSelfInstaller(inputs: Inputs): Promise<number> {
|
export async function runSelfInstaller(inputs: Inputs): Promise<number> {
|
||||||
const cp = spawn(execPath, {
|
const { version, dest } = inputs
|
||||||
env: {
|
const target = version ? `@pnpm/exe@${version}` : '@pnpm/exe'
|
||||||
PNPM_VERSION: inputs.version,
|
const pkgJson = path.join(dest, 'package.json')
|
||||||
PNPM_DEST: inputs.dest,
|
|
||||||
PNPM_BIN_DEST: inputs.binDest,
|
await remove(dest)
|
||||||
PNPM_REGISTRY: inputs.registry,
|
await ensureFile(pkgJson)
|
||||||
},
|
await writeFile(pkgJson, JSON.stringify({ private: true }))
|
||||||
|
|
||||||
|
const cp = spawn(execPath, ['-', 'install', target, '--no-lockfile'], {
|
||||||
|
cwd: dest,
|
||||||
stdio: ['pipe', 'inherit', 'inherit'],
|
stdio: ['pipe', 'inherit', 'inherit'],
|
||||||
})
|
})
|
||||||
|
|
||||||
const response = await downloadSelfInstaller()
|
const response = await fetch('https://get.pnpm.io/v6.16.js')
|
||||||
response.body.pipe(cp.stdin)
|
response.body.pipe(cp.stdin)
|
||||||
|
|
||||||
return new Promise((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)
|
||||||
})
|
})
|
||||||
|
if (exitCode === 0) {
|
||||||
|
const pnpmHome = path.join(dest, 'node_modules/.bin')
|
||||||
|
addPath(pnpmHome)
|
||||||
|
exportVariable('PNPM_HOME', pnpmHome)
|
||||||
|
}
|
||||||
|
return exitCode
|
||||||
}
|
}
|
||||||
|
|
||||||
export default runSelfInstaller
|
export default runSelfInstaller
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
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) {
|
||||||
addPath(inputs.binDest)
|
const binDest = getBinDest(inputs)
|
||||||
|
addPath(binDest)
|
||||||
setOutput('dest', inputs.dest)
|
setOutput('dest', inputs.dest)
|
||||||
setOutput('bin_dest', inputs.binDest)
|
setOutput('bin_dest', binDest)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default setOutputs
|
export default setOutputs
|
||||||
|
@ -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
|
|
@ -2,7 +2,9 @@ import process from 'process'
|
|||||||
import path from 'path'
|
import path from 'path'
|
||||||
import { Inputs } from '../inputs'
|
import { Inputs } from '../inputs'
|
||||||
|
|
||||||
|
export const getBinDest = (inputs: Inputs): string => path.join(inputs.dest, 'node_modules', '.bin')
|
||||||
|
|
||||||
export const patchPnpmEnv = (inputs: Inputs): NodeJS.ProcessEnv => ({
|
export const patchPnpmEnv = (inputs: Inputs): NodeJS.ProcessEnv => ({
|
||||||
...process.env,
|
...process.env,
|
||||||
PATH: inputs.binDest + path.delimiter + process.env.PATH
|
PATH: getBinDest(inputs) + path.delimiter + process.env.PATH
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user