mirror of
https://github.com/pnpm/action-setup.git
synced 2025-07-08 04:20:06 +08:00
Compare commits
5 Commits
install-co
...
inspect-is
Author | SHA1 | Date | |
---|---|---|---|
271a9df5fb | |||
3b5e8836ec | |||
0fa2b7d3a5 | |||
c3e0d9f20f | |||
d2316507fd |
56
.github/workflows/test.yaml
vendored
56
.github/workflows/test.yaml
vendored
@ -65,59 +65,3 @@ jobs:
|
||||
|
||||
- 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:
|
||||
- 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
|
||||
|
47
README.md
47
README.md
@ -18,29 +18,11 @@ Install PNPM package manager.
|
||||
|
||||
### `registry`
|
||||
|
||||
**Optional** (_default:_ `https://registry.npmjs.com`) Registry to download PNPM from.
|
||||
**Optional** 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]`.
|
||||
**Optional** If specified, run `pnpm install`.
|
||||
|
||||
## Outputs
|
||||
|
||||
@ -54,24 +36,6 @@ Expanded path of inputs#bin_dest.
|
||||
|
||||
## Usage example
|
||||
|
||||
### Just install PNPM
|
||||
|
||||
```yaml
|
||||
on:
|
||||
- push
|
||||
- pull_request
|
||||
|
||||
jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: pnpm/action-setup@v1.1.0
|
||||
with:
|
||||
version: 4.11.1
|
||||
```
|
||||
|
||||
### Install PNPM and a few NPM packages
|
||||
|
||||
```yaml
|
||||
on:
|
||||
- push
|
||||
@ -86,10 +50,9 @@ jobs:
|
||||
- uses: pnpm/action-setup@v1.1.0
|
||||
with:
|
||||
version: 4.11.1
|
||||
run_install: |
|
||||
- recursive: true
|
||||
args: [--frozen-lockfile, --strict-peer-dependencies]
|
||||
- args: [--global, gulp, prettier, typescript]
|
||||
|
||||
- name: Install dependencies
|
||||
run: pnpm install
|
||||
```
|
||||
|
||||
## Notes
|
||||
|
2
dist/index.js
vendored
2
dist/index.js
vendored
File diff suppressed because one or more lines are too long
15
src/index.ts
15
src/index.ts
@ -1,15 +1,20 @@
|
||||
import { setFailed, saveState, getState } from '@actions/core'
|
||||
import { setFailed, getState } from '@actions/core'
|
||||
import getInputs from './inputs'
|
||||
import setOutputs from './outputs'
|
||||
import installPnpm from './install-pnpm'
|
||||
import pnpmInstall from './pnpm-install'
|
||||
import pruneStore from './pnpm-store-prune'
|
||||
|
||||
async function main() {
|
||||
const isPost = getState('isPost')
|
||||
console.log({
|
||||
is_post: getState('is_post'),
|
||||
isPost: getState('isPost'),
|
||||
STATE_isPost: process.env['STATE_isPost'],
|
||||
})
|
||||
if (isPost) {
|
||||
return
|
||||
}
|
||||
const inputs = getInputs()
|
||||
const isPost = getState('is_post')
|
||||
if (isPost === 'true') return pruneStore(inputs)
|
||||
saveState('is_post', 'true')
|
||||
await installPnpm(inputs)
|
||||
console.log('Installation Completed!')
|
||||
setOutputs(inputs)
|
||||
|
@ -1,13 +1,11 @@
|
||||
import { setFailed, startGroup, endGroup } from '@actions/core'
|
||||
import { setFailed } 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}`)
|
||||
}
|
||||
|
@ -1,10 +1,14 @@
|
||||
import process from 'process'
|
||||
import path from 'path'
|
||||
import { spawnSync } from 'child_process'
|
||||
import { setFailed, startGroup, endGroup } from '@actions/core'
|
||||
import { setFailed } from '@actions/core'
|
||||
import { Inputs } from '../inputs'
|
||||
import { patchPnpmEnv } from '../utils'
|
||||
|
||||
export function runPnpmInstall(inputs: Inputs) {
|
||||
const env = patchPnpmEnv(inputs)
|
||||
const env = {
|
||||
...process.env,
|
||||
PATH: inputs.binDest + path.delimiter + process.env.PATH
|
||||
}
|
||||
|
||||
for (const options of inputs.runInstall) {
|
||||
const args = ['install']
|
||||
@ -12,7 +16,7 @@ export function runPnpmInstall(inputs: Inputs) {
|
||||
if (options.args) args.push(...options.args)
|
||||
|
||||
const cmdStr = ['pnpm', ...args].join(' ')
|
||||
startGroup(`Running ${cmdStr}...`)
|
||||
console.log('Running', cmdStr)
|
||||
|
||||
const { error, status } = spawnSync('pnpm', args, {
|
||||
stdio: 'inherit',
|
||||
@ -21,8 +25,6 @@ export function runPnpmInstall(inputs: Inputs) {
|
||||
env,
|
||||
})
|
||||
|
||||
endGroup()
|
||||
|
||||
if (error) {
|
||||
setFailed(error)
|
||||
continue
|
||||
|
@ -1,31 +0,0 @@
|
||||
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,8 +0,0 @@
|
||||
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