mirror of
https://github.com/pnpm/action-setup.git
synced 2025-07-08 04:30:27 +08:00
Compare commits
32 Commits
Author | SHA1 | Date | |
---|---|---|---|
8e1abe543f | |||
af6247d08a | |||
f87c8a916e | |||
d6790970e0 | |||
fa62771e12 | |||
935101478d | |||
4abca36d2a | |||
56013f801f | |||
fb99aeb8e3 | |||
b78eaea668 | |||
83681c63a7 | |||
6eb237a86d | |||
b1febf84ed | |||
2546768411 | |||
8cdddb18c5 | |||
4457a83971 | |||
c8fc1974e1 | |||
291e58ad85 | |||
1790ca7f76 | |||
9a1617cf46 | |||
6fe65dc1af | |||
91d3d73121 | |||
7a5d08caa7 | |||
e373fffa0a | |||
bb24f595c2 | |||
d44b8c5e53 | |||
4b13327683 | |||
49ba4cbc60 | |||
9649109f2e | |||
087311f996 | |||
9979c3d928 | |||
738fb9213f |
2
.gitattributes
vendored
2
.gitattributes
vendored
@ -1,2 +1,2 @@
|
|||||||
* text=auto
|
* text=auto
|
||||||
dist/index.js -text
|
/dist/index.js binary
|
||||||
|
57
.github/workflows/test.yaml
vendored
57
.github/workflows/test.yaml
vendored
@ -3,6 +3,7 @@ name: Test Action
|
|||||||
on:
|
on:
|
||||||
- push
|
- push
|
||||||
- pull_request
|
- pull_request
|
||||||
|
- workflow_dispatch
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test_default_inputs:
|
test_default_inputs:
|
||||||
@ -65,3 +66,59 @@ jobs:
|
|||||||
|
|
||||||
- name: 'Test: install'
|
- name: 'Test: install'
|
||||||
run: pnpm install
|
run: pnpm install
|
||||||
|
|
||||||
|
test_run_install:
|
||||||
|
name: 'Test with run_install (${{ matrix.run_install.name }}, ${{ matrix.os }})'
|
||||||
|
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
pnpm:
|
||||||
|
- 4.11.1
|
||||||
|
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
|
||||||
|
- pnpm
|
||||||
|
- name: 'array'
|
||||||
|
value: |
|
||||||
|
- {}
|
||||||
|
- recursive: true
|
||||||
|
- args:
|
||||||
|
- --global
|
||||||
|
- --global-dir=./pnpm-global
|
||||||
|
- npm
|
||||||
|
- yarn
|
||||||
|
- pnpm
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Run the action
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
version: 4.11.1
|
||||||
|
run_install: ${{ matrix.run_install.value }}
|
||||||
|
|
||||||
|
- name: 'Test: which'
|
||||||
|
run: which pnpm; which pnpx
|
||||||
|
|
||||||
|
- name: 'Test: install'
|
||||||
|
run: pnpm install
|
||||||
|
53
README.md
53
README.md
@ -18,7 +18,29 @@ Install PNPM package manager.
|
|||||||
|
|
||||||
### `registry`
|
### `registry`
|
||||||
|
|
||||||
**Optional** Registry to download PNPM from.
|
**Optional** (_default:_ `https://registry.npmjs.com`) Registry to download PNPM from.
|
||||||
|
|
||||||
|
### `run_install`
|
||||||
|
|
||||||
|
**Optional** (_default:_ `null`) If specified, run `pnpm install`.
|
||||||
|
|
||||||
|
If `run_install` is either `null` or `false`, pnpm will not install any npm package.
|
||||||
|
|
||||||
|
If `run_install` is `true`, pnpm will install dependencies recursively.
|
||||||
|
|
||||||
|
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]`.
|
||||||
|
|
||||||
## Outputs
|
## Outputs
|
||||||
|
|
||||||
@ -28,10 +50,28 @@ Expanded path of inputs#dest.
|
|||||||
|
|
||||||
### `bin_dest`
|
### `bin_dest`
|
||||||
|
|
||||||
Expanded path of inputs@bin_dest.
|
Expanded path of inputs#bin_dest.
|
||||||
|
|
||||||
## Usage example
|
## Usage example
|
||||||
|
|
||||||
|
### Just install PNPM
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
on:
|
||||||
|
- push
|
||||||
|
- pull_request
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: pnpm/action-setup@v1.2.0
|
||||||
|
with:
|
||||||
|
version: 4.11.1
|
||||||
|
```
|
||||||
|
|
||||||
|
### Install PNPM and a few NPM packages
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
on:
|
on:
|
||||||
- push
|
- push
|
||||||
@ -43,12 +83,13 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
- uses: pnpm/action-setup@v1.1.0
|
- uses: pnpm/action-setup@v1.2.0
|
||||||
with:
|
with:
|
||||||
version: 4.11.1
|
version: 4.11.1
|
||||||
|
run_install: |
|
||||||
- name: Install dependencies
|
- recursive: true
|
||||||
run: pnpm install
|
args: [--frozen-lockfile, --strict-peer-dependencies]
|
||||||
|
- args: [--global, gulp, prettier, typescript]
|
||||||
```
|
```
|
||||||
|
|
||||||
## Notes
|
## Notes
|
||||||
|
@ -19,6 +19,11 @@ inputs:
|
|||||||
description: Registry to download PNPM from
|
description: Registry to download PNPM from
|
||||||
required: false
|
required: false
|
||||||
default: https://registry.npmjs.com
|
default: https://registry.npmjs.com
|
||||||
|
run_install:
|
||||||
|
description: If specified, run `pnpm install`
|
||||||
|
required: false
|
||||||
|
default: 'null'
|
||||||
runs:
|
runs:
|
||||||
using: node12
|
using: node12
|
||||||
main: dist/index.js
|
main: dist/index.js
|
||||||
|
post: dist/index.js
|
||||||
|
2
dist/index.js
vendored
2
dist/index.js
vendored
File diff suppressed because one or more lines are too long
19
package.json
19
package.json
@ -1,20 +1,25 @@
|
|||||||
{
|
{
|
||||||
"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"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"download": "^8.0.0",
|
"node-fetch": "^2.6.1",
|
||||||
"expand-tilde": "^2.0.2",
|
"expand-tilde": "^2.0.2",
|
||||||
"@actions/core": "^1.2.4",
|
"js-yaml": "^3.14.0",
|
||||||
"@types/download": "^6.2.4",
|
"ajv": "^6.12.5",
|
||||||
|
"@actions/core": "^1.2.6",
|
||||||
"@types/expand-tilde": "^2.0.0",
|
"@types/expand-tilde": "^2.0.0",
|
||||||
"@types/node": "^13.13.5"
|
"@types/node-fetch": "^2.5.7",
|
||||||
|
"@types/js-yaml": "^3.12.5",
|
||||||
|
"@types/node": "^14.11.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"typescript": "^3.8.3",
|
"typescript": "^4.0.3",
|
||||||
"@zeit/ncc": "^0.22.1"
|
"@ts-schema-autogen/cli": "^0.1.2",
|
||||||
|
"@zeit/ncc": "^0.22.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
1307
pnpm-lock.yaml
generated
1307
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
1
run.sh
1
run.sh
@ -5,4 +5,5 @@ 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_BIN_DEST='~/pnpm.temp/.bin'
|
||||||
export INPUT_REGISTRY=https://registry.npmjs.com
|
export INPUT_REGISTRY=https://registry.npmjs.com
|
||||||
|
export INPUT_RUN_INSTALL=null
|
||||||
exec node dist/index.js
|
exec node dist/index.js
|
||||||
|
17
src/index.ts
17
src/index.ts
@ -1,14 +1,19 @@
|
|||||||
import { setFailed } from '@actions/core'
|
import { setFailed, saveState, getState } from '@actions/core'
|
||||||
import getInputs from './inputs'
|
import getInputs from './inputs'
|
||||||
import setOutputs from './outputs'
|
import setOutputs from './outputs'
|
||||||
import install from './install'
|
import installPnpm from './install-pnpm'
|
||||||
|
import pnpmInstall from './pnpm-install'
|
||||||
|
import pruneStore from './pnpm-store-prune'
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
const inputs = getInputs()
|
const inputs = getInputs()
|
||||||
await install(inputs).then(() => {
|
const isPost = getState('is_post')
|
||||||
console.log('Installation Completed!')
|
if (isPost === 'true') return pruneStore(inputs)
|
||||||
setOutputs(inputs)
|
saveState('is_post', 'true')
|
||||||
})
|
await installPnpm(inputs)
|
||||||
|
console.log('Installation Completed!')
|
||||||
|
setOutputs(inputs)
|
||||||
|
pnpmInstall(inputs)
|
||||||
}
|
}
|
||||||
|
|
||||||
main().catch(error => {
|
main().catch(error => {
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
import { 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 binDest: string
|
readonly binDest: string
|
||||||
readonly registry: string
|
readonly registry: string
|
||||||
|
readonly runInstall: RunInstall[]
|
||||||
}
|
}
|
||||||
|
|
||||||
const options: InputOptions = {
|
const options: InputOptions = {
|
||||||
@ -19,6 +21,7 @@ export const getInputs = (): Inputs => ({
|
|||||||
dest: parseInputPath('dest'),
|
dest: parseInputPath('dest'),
|
||||||
binDest: parseInputPath('bin_dest'),
|
binDest: parseInputPath('bin_dest'),
|
||||||
registry: getInput('registry', options),
|
registry: getInput('registry', options),
|
||||||
|
runInstall: parseRunInstall('run_install'),
|
||||||
})
|
})
|
||||||
|
|
||||||
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#"
|
||||||
|
}
|
40
src/inputs/run-install.ts
Normal file
40
src/inputs/run-install.ts
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
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'
|
||||||
|
|
||||||
|
export interface RunInstall {
|
||||||
|
readonly recursive?: boolean
|
||||||
|
readonly cwd?: string
|
||||||
|
readonly args?: readonly string[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export type RunInstallInput =
|
||||||
|
| null
|
||||||
|
| boolean
|
||||||
|
| RunInstall
|
||||||
|
| RunInstall[]
|
||||||
|
|
||||||
|
const options: InputOptions = {
|
||||||
|
required: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
export function parseRunInstall(name: string): RunInstall[] {
|
||||||
|
const result: RunInstallInput = safeLoad(getInput(name, options)) as any
|
||||||
|
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}`)
|
||||||
|
}
|
||||||
|
return process.exit(1)
|
||||||
|
}
|
||||||
|
if (!result) return []
|
||||||
|
if (result === true) return [{ recursive: true }]
|
||||||
|
if (Array.isArray(result)) return result
|
||||||
|
return [result]
|
||||||
|
}
|
@ -1,11 +1,13 @@
|
|||||||
import { setFailed } from '@actions/core'
|
import { setFailed, startGroup, endGroup } 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 does wrong, self-installer exits with code ${status}`)
|
return setFailed(`Something does wrong, self-installer exits with code ${status}`)
|
||||||
}
|
}
|
@ -3,7 +3,7 @@ import { execPath } from 'process'
|
|||||||
import { downloadSelfInstaller } from '../self-installer'
|
import { downloadSelfInstaller } from '../self-installer'
|
||||||
import { Inputs } from '../inputs'
|
import { Inputs } from '../inputs'
|
||||||
|
|
||||||
export function runSelfInstaller(inputs: Inputs): Promise<number> {
|
export async function runSelfInstaller(inputs: Inputs): Promise<number> {
|
||||||
const cp = spawn(execPath, {
|
const cp = spawn(execPath, {
|
||||||
env: {
|
env: {
|
||||||
PNPM_VERSION: inputs.version,
|
PNPM_VERSION: inputs.version,
|
||||||
@ -14,7 +14,8 @@ export function runSelfInstaller(inputs: Inputs): Promise<number> {
|
|||||||
stdio: ['pipe', 'inherit', 'inherit'],
|
stdio: ['pipe', 'inherit', 'inherit'],
|
||||||
})
|
})
|
||||||
|
|
||||||
downloadSelfInstaller().pipe(cp.stdin)
|
const response = await downloadSelfInstaller()
|
||||||
|
response.body.pipe(cp.stdin)
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
cp.on('error', reject)
|
cp.on('error', reject)
|
38
src/pnpm-install/index.ts
Normal file
38
src/pnpm-install/index.ts
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
import { spawnSync } from 'child_process'
|
||||||
|
import { setFailed, startGroup, endGroup } from '@actions/core'
|
||||||
|
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
|
31
src/pnpm-store-prune/index.ts
Normal file
31
src/pnpm-store-prune/index.ts
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
import { spawnSync } from 'child_process'
|
||||||
|
import { warning, startGroup, endGroup } from '@actions/core'
|
||||||
|
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
|
@ -1,4 +1,4 @@
|
|||||||
import download from 'download'
|
import fetch from 'node-fetch'
|
||||||
import url from './url'
|
import url from './url'
|
||||||
export const downloadSelfInstaller = () => download(url)
|
export const downloadSelfInstaller = () => fetch(url)
|
||||||
export default downloadSelfInstaller
|
export default downloadSelfInstaller
|
||||||
|
8
src/utils/index.ts
Normal file
8
src/utils/index.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import process from 'process'
|
||||||
|
import path from 'path'
|
||||||
|
import { Inputs } from '../inputs'
|
||||||
|
|
||||||
|
export const patchPnpmEnv = (inputs: Inputs): NodeJS.ProcessEnv => ({
|
||||||
|
...process.env,
|
||||||
|
PATH: inputs.binDest + path.delimiter + process.env.PATH
|
||||||
|
})
|
Reference in New Issue
Block a user