mirror of
https://github.com/pnpm/action-setup.git
synced 2025-07-08 00:49:13 +08:00
Compare commits
73 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 | |||
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 | |||
8925cc44da | |||
7574328996 |
2
.gitattributes
vendored
2
.gitattributes
vendored
@ -1,2 +1,2 @@
|
||||
* text=auto
|
||||
dist/index.js -text
|
||||
/dist/index.js binary
|
||||
|
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
|
71
.github/workflows/test.yaml
vendored
71
.github/workflows/test.yaml
vendored
@ -3,6 +3,7 @@ name: Test Action
|
||||
on:
|
||||
- push
|
||||
- pull_request
|
||||
- workflow_dispatch
|
||||
|
||||
jobs:
|
||||
test_default_inputs:
|
||||
@ -14,7 +15,7 @@ jobs:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
pnpm:
|
||||
- 4.11.1
|
||||
- 6.17.1
|
||||
os:
|
||||
- ubuntu-latest
|
||||
- macos-latest
|
||||
@ -26,10 +27,10 @@ jobs:
|
||||
- name: Run the action
|
||||
uses: ./
|
||||
with:
|
||||
version: 4.11.1
|
||||
version: 6.17.1
|
||||
|
||||
- name: 'Test: which'
|
||||
run: which pnpm; which pnpx
|
||||
run: which pnpm
|
||||
|
||||
- name: 'Test: install'
|
||||
run: pnpm install
|
||||
@ -43,7 +44,7 @@ jobs:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
pnpm:
|
||||
- 4.11.1
|
||||
- 6.17.1
|
||||
os:
|
||||
- ubuntu-latest
|
||||
- macos-latest
|
||||
@ -55,13 +56,67 @@ jobs:
|
||||
- name: Run the action
|
||||
uses: ./
|
||||
with:
|
||||
version: 4.11.1
|
||||
version: 6.17.1
|
||||
dest: ~/test/pnpm
|
||||
bin_dest: ~/test/pnpm/.bin
|
||||
registry: http://registry.yarnpkg.com/
|
||||
|
||||
- name: 'Test: which'
|
||||
run: which pnpm && which pnpx
|
||||
run: which pnpm
|
||||
|
||||
- name: 'Test: 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:
|
||||
- 6.17.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: 6.17.1
|
||||
run_install: ${{ matrix.run_install.value }}
|
||||
|
||||
- name: 'Test: which'
|
||||
run: which pnpm
|
||||
|
||||
- name: 'Test: install'
|
||||
run: pnpm install
|
||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -8,3 +8,4 @@ temp
|
||||
*.temp
|
||||
tmp.*
|
||||
temp.*
|
||||
.pnpm-store
|
||||
|
104
README.md
104
README.md
@ -1,24 +1,38 @@
|
||||
# Setup PNPM
|
||||
# Setup pnpm
|
||||
|
||||
Install PNPM package manager.
|
||||
Install pnpm package manager.
|
||||
|
||||
## Inputs
|
||||
|
||||
### `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`
|
||||
|
||||
**Optional** Where to store PNPM files.
|
||||
**Optional** Where to store pnpm files.
|
||||
|
||||
### `bin_dest`
|
||||
### `run_install`
|
||||
|
||||
**Optional** Where to store executables (`pnpm` and `pnpx` commands).
|
||||
**Optional** (_default:_ `null`) If specified, run `pnpm install`.
|
||||
|
||||
### `registry`
|
||||
If `run_install` is either `null` or `false`, pnpm will not install any npm package.
|
||||
|
||||
**Optional** Registry to download PNPM from.
|
||||
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
|
||||
|
||||
@ -28,29 +42,81 @@ Expanded path of inputs#dest.
|
||||
|
||||
### `bin_dest`
|
||||
|
||||
Expanded path of inputs@bin_dest.
|
||||
Location of `pnpm` and `pnpx` command.
|
||||
|
||||
## Usage example
|
||||
|
||||
### Just install pnpm
|
||||
|
||||
```yaml
|
||||
on:
|
||||
- push
|
||||
- pull_request
|
||||
|
||||
jobs:
|
||||
runs-on: ubuntu-latest
|
||||
install:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- uses: pnpm/action-setup@v1
|
||||
with:
|
||||
version: 4.11.1
|
||||
|
||||
- name: Install dependencies
|
||||
run: pnpm install
|
||||
steps:
|
||||
- uses: pnpm/action-setup@v2.1.0
|
||||
with:
|
||||
version: 6.0.2
|
||||
```
|
||||
|
||||
### Install pnpm and a few npm packages
|
||||
|
||||
```yaml
|
||||
on:
|
||||
- push
|
||||
- pull_request
|
||||
|
||||
jobs:
|
||||
install:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- uses: pnpm/action-setup@v2.1.0
|
||||
with:
|
||||
version: 6.0.2
|
||||
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:
|
||||
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
|
||||
|
||||
This action does not setup Node.js for you, use [actions/setup-node](https://github.com/actions/setup-node) yourself.
|
||||
|
11
action.yml
11
action.yml
@ -11,14 +11,11 @@ inputs:
|
||||
description: Where to store PNPM files
|
||||
required: false
|
||||
default: ~/setup-pnpm
|
||||
bin_dest:
|
||||
description: Where to store executables (pnpm and pnpx commands)
|
||||
run_install:
|
||||
description: If specified, run `pnpm install`
|
||||
required: false
|
||||
default: ~/setup-pnpm/.bin
|
||||
registry:
|
||||
description: Registry to download PNPM from
|
||||
required: false
|
||||
default: https://registry.npmjs.com
|
||||
default: 'null'
|
||||
runs:
|
||||
using: node12
|
||||
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
23
package.json
23
package.json
@ -1,20 +1,27 @@
|
||||
{
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"build:schemas": "ts-schema-autogen generate",
|
||||
"build:ncc": "ncc build --minify --no-source-map-register --no-cache dist/tsc/index.js --out dist/",
|
||||
"build": "tsc && pnpm run build:ncc",
|
||||
"build": "pnpm run build:schemas && tsc && pnpm run build:ncc",
|
||||
"start": "pnpm run build && sh ./run.sh"
|
||||
},
|
||||
"dependencies": {
|
||||
"download": "^8.0.0",
|
||||
"expand-tilde": "^2.0.2",
|
||||
"@actions/core": "^1.2.4",
|
||||
"@types/download": "^6.2.4",
|
||||
"@actions/core": "^1.6.0",
|
||||
"@types/expand-tilde": "^2.0.0",
|
||||
"@types/node": "^13.13.5"
|
||||
"@types/fs-extra": "^9.0.13",
|
||||
"@types/js-yaml": "^4.0.5",
|
||||
"@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": {
|
||||
"typescript": "^3.8.3",
|
||||
"@zeit/ncc": "^0.22.1"
|
||||
"@ts-schema-autogen/cli": "^0.1.2",
|
||||
"@vercel/ncc": "^0.27.0",
|
||||
"typescript": "^4.5.5"
|
||||
}
|
||||
}
|
||||
|
1546
pnpm-lock.yaml
generated
1546
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,10 @@
|
||||
{
|
||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||
"pinVersions": false,
|
||||
"extends": [
|
||||
"config:base"
|
||||
],
|
||||
"ignoreDeps": [
|
||||
"ajv"
|
||||
]
|
||||
}
|
||||
|
3
run.sh
3
run.sh
@ -3,6 +3,5 @@
|
||||
export HOME="$(pwd)"
|
||||
export INPUT_VERSION=4.11.1
|
||||
export INPUT_DEST='~/pnpm.temp'
|
||||
export INPUT_BIN_DEST='~/pnpm.temp/.bin'
|
||||
export INPUT_REGISTRY=https://registry.npmjs.com
|
||||
export INPUT_RUN_INSTALL=null
|
||||
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 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() {
|
||||
const inputs = getInputs()
|
||||
await install(inputs).then(() => {
|
||||
console.log('Installation Completed!')
|
||||
setOutputs(inputs)
|
||||
})
|
||||
const isPost = getState('is_post')
|
||||
if (isPost === 'true') return pruneStore(inputs)
|
||||
saveState('is_post', 'true')
|
||||
await installPnpm(inputs)
|
||||
console.log('Installation Completed!')
|
||||
setOutputs(inputs)
|
||||
pnpmInstall(inputs)
|
||||
}
|
||||
|
||||
main().catch(error => {
|
||||
|
@ -1,11 +1,11 @@
|
||||
import { getInput, InputOptions } from '@actions/core'
|
||||
import expandTilde from 'expand-tilde'
|
||||
import { RunInstall, parseRunInstall } from './run-install'
|
||||
|
||||
export interface Inputs {
|
||||
readonly version: string
|
||||
readonly dest: string
|
||||
readonly binDest: string
|
||||
readonly registry: string
|
||||
readonly runInstall: RunInstall[]
|
||||
}
|
||||
|
||||
const options: InputOptions = {
|
||||
@ -17,8 +17,7 @@ const parseInputPath = (name: string) => expandTilde(getInput(name, options))
|
||||
export const getInputs = (): Inputs => ({
|
||||
version: getInput('version', options),
|
||||
dest: parseInputPath('dest'),
|
||||
binDest: parseInputPath('bin_dest'),
|
||||
registry: getInput('registry', options),
|
||||
runInstall: parseRunInstall('run_install'),
|
||||
})
|
||||
|
||||
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#"
|
||||
}
|
39
src/inputs/run-install.ts
Normal file
39
src/inputs/run-install.ts
Normal file
@ -0,0 +1,39 @@
|
||||
import process from 'process'
|
||||
import { load } 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 = load(getInput(name, options)) as any
|
||||
const ajv = new Ajv({
|
||||
allErrors: true,
|
||||
})
|
||||
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,13 +1,15 @@
|
||||
import { setFailed } from '@actions/core'
|
||||
import { setFailed, startGroup, endGroup } from '@actions/core'
|
||||
import { Inputs } from '../inputs'
|
||||
import runSelfInstaller from './run'
|
||||
|
||||
export { runSelfInstaller }
|
||||
|
||||
export async function install(inputs: Inputs) {
|
||||
startGroup('Running self-installer...')
|
||||
const status = await runSelfInstaller(inputs)
|
||||
endGroup()
|
||||
if (status) {
|
||||
return setFailed(`Something does wrong, self-installer exits with code ${status}`)
|
||||
return setFailed(`Something went wrong, self-installer exits with code ${status}`)
|
||||
}
|
||||
}
|
||||
|
38
src/install-pnpm/run.ts
Normal file
38
src/install-pnpm/run.ts
Normal file
@ -0,0 +1,38 @@
|
||||
import { addPath, exportVariable } from '@actions/core'
|
||||
import { spawn } from 'child_process'
|
||||
import { execPath } from 'process'
|
||||
import path from 'path'
|
||||
import { remove, ensureFile, writeFile } from 'fs-extra'
|
||||
import fetch from 'node-fetch'
|
||||
import { Inputs } from '../inputs'
|
||||
|
||||
export async function runSelfInstaller(inputs: Inputs): Promise<number> {
|
||||
const { version, dest } = inputs
|
||||
const target = version ? `@pnpm/exe@${version}` : '@pnpm/exe'
|
||||
const pkgJson = path.join(dest, 'package.json')
|
||||
|
||||
await remove(dest)
|
||||
await ensureFile(pkgJson)
|
||||
await writeFile(pkgJson, JSON.stringify({ private: true }))
|
||||
|
||||
const cp = spawn(execPath, ['-', 'install', target, '--no-lockfile'], {
|
||||
cwd: dest,
|
||||
stdio: ['pipe', 'inherit', 'inherit'],
|
||||
})
|
||||
|
||||
const response = await fetch('https://get.pnpm.io/v6.16.js')
|
||||
response.body.pipe(cp.stdin)
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
export default runSelfInstaller
|
@ -1,25 +0,0 @@
|
||||
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,10 +1,12 @@
|
||||
import { setOutput, addPath } from '@actions/core'
|
||||
import { Inputs } from '../inputs'
|
||||
import { getBinDest } from '../utils'
|
||||
|
||||
export function setOutputs(inputs: Inputs) {
|
||||
addPath(inputs.binDest)
|
||||
const binDest = getBinDest(inputs)
|
||||
addPath(binDest)
|
||||
setOutput('dest', inputs.dest)
|
||||
setOutput('bin_dest', inputs.binDest)
|
||||
setOutput('bin_dest', binDest)
|
||||
}
|
||||
|
||||
export default setOutputs
|
||||
|
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 +0,0 @@
|
||||
import download from 'download'
|
||||
import url from './url'
|
||||
export const downloadSelfInstaller = () => download(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
|
10
src/utils/index.ts
Normal file
10
src/utils/index.ts
Normal file
@ -0,0 +1,10 @@
|
||||
import process from 'process'
|
||||
import path from 'path'
|
||||
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
|
||||
})
|
Reference in New Issue
Block a user