mirror of
https://github.com/pnpm/action-setup.git
synced 2025-07-08 14:49:16 +08:00
Compare commits
13 Commits
inspect-is
...
v1.2.0
Author | SHA1 | Date | |
---|---|---|---|
935101478d | |||
4abca36d2a | |||
56013f801f | |||
fb99aeb8e3 | |||
b78eaea668 | |||
83681c63a7 | |||
6eb237a86d | |||
b1febf84ed | |||
2546768411 | |||
8cdddb18c5 | |||
4457a83971 | |||
c8fc1974e1 | |||
291e58ad85 |
56
.github/workflows/test.yaml
vendored
56
.github/workflows/test.yaml
vendored
@ -65,3 +65,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
|
||||||
|
49
README.md
49
README.md
@ -18,11 +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`
|
### `run_install`
|
||||||
|
|
||||||
**Optional** If specified, run `pnpm 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
|
||||||
|
|
||||||
@ -36,6 +54,24 @@ 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
|
||||||
@ -47,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
|
||||||
|
@ -26,3 +26,4 @@ inputs:
|
|||||||
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
@ -1,11 +1,15 @@
|
|||||||
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 installPnpm from './install-pnpm'
|
import installPnpm from './install-pnpm'
|
||||||
import pnpmInstall from './pnpm-install'
|
import pnpmInstall from './pnpm-install'
|
||||||
|
import pruneStore from './pnpm-store-prune'
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
const inputs = getInputs()
|
const inputs = getInputs()
|
||||||
|
const isPost = getState('is_post')
|
||||||
|
if (isPost === 'true') return pruneStore(inputs)
|
||||||
|
saveState('is_post', 'true')
|
||||||
await installPnpm(inputs)
|
await installPnpm(inputs)
|
||||||
console.log('Installation Completed!')
|
console.log('Installation Completed!')
|
||||||
setOutputs(inputs)
|
setOutputs(inputs)
|
||||||
|
@ -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}`)
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,10 @@
|
|||||||
import process from 'process'
|
|
||||||
import path from 'path'
|
|
||||||
import { spawnSync } from 'child_process'
|
import { spawnSync } from 'child_process'
|
||||||
import { setFailed } from '@actions/core'
|
import { setFailed, startGroup, endGroup } from '@actions/core'
|
||||||
import { Inputs } from '../inputs'
|
import { Inputs } from '../inputs'
|
||||||
|
import { patchPnpmEnv } from '../utils'
|
||||||
|
|
||||||
export function runPnpmInstall(inputs: Inputs) {
|
export function runPnpmInstall(inputs: Inputs) {
|
||||||
const env = {
|
const env = patchPnpmEnv(inputs)
|
||||||
...process.env,
|
|
||||||
PATH: inputs.binDest + path.delimiter + process.env.PATH
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const options of inputs.runInstall) {
|
for (const options of inputs.runInstall) {
|
||||||
const args = ['install']
|
const args = ['install']
|
||||||
@ -16,7 +12,7 @@ export function runPnpmInstall(inputs: Inputs) {
|
|||||||
if (options.args) args.push(...options.args)
|
if (options.args) args.push(...options.args)
|
||||||
|
|
||||||
const cmdStr = ['pnpm', ...args].join(' ')
|
const cmdStr = ['pnpm', ...args].join(' ')
|
||||||
console.log('Running', cmdStr)
|
startGroup(`Running ${cmdStr}...`)
|
||||||
|
|
||||||
const { error, status } = spawnSync('pnpm', args, {
|
const { error, status } = spawnSync('pnpm', args, {
|
||||||
stdio: 'inherit',
|
stdio: 'inherit',
|
||||||
@ -25,6 +21,8 @@ export function runPnpmInstall(inputs: Inputs) {
|
|||||||
env,
|
env,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
endGroup()
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
setFailed(error)
|
setFailed(error)
|
||||||
continue
|
continue
|
||||||
|
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
|
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