action-setup/src/pnpm-install/index.ts

39 lines
914 B
TypeScript
Raw Normal View History

2020-05-09 21:24:52 +08:00
import { spawnSync } from 'child_process'
2020-05-09 22:50:47 +08:00
import { setFailed, startGroup, endGroup } from '@actions/core'
2020-05-09 21:24:52 +08:00
import { Inputs } from '../inputs'
2020-05-09 22:41:25 +08:00
import { patchPnpmEnv } from '../utils'
2020-05-09 21:24:52 +08:00
export function runPnpmInstall(inputs: Inputs) {
2020-05-09 22:41:25 +08:00
const env = patchPnpmEnv(inputs)
2020-05-09 21:24:52 +08:00
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(' ')
2020-05-09 22:50:47 +08:00
startGroup(`Running ${cmdStr}...`)
2020-05-09 21:24:52 +08:00
const { error, status } = spawnSync('pnpm', args, {
stdio: 'inherit',
cwd: options.cwd,
shell: true,
env,
})
2020-05-09 22:50:47 +08:00
endGroup()
2020-05-09 21:24:52 +08:00
if (error) {
setFailed(error)
continue
}
if (status) {
setFailed(`Command ${cmdStr} (cwd: ${options.cwd}) exits with status ${status}`)
continue
}
}
}
export default runPnpmInstall