diff --git a/dist/index.js b/dist/index.js index 83e7641..e3600f0 100644 Binary files a/dist/index.js and b/dist/index.js differ diff --git a/src/index.ts b/src/index.ts index 8add39b..4273417 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,12 +2,14 @@ import { setFailed } from '@actions/core' import getInputs from './inputs' import setOutputs from './outputs' import installPnpm from './install-pnpm' +import pnpmInstall from './pnpm-install' async function main() { const inputs = getInputs() await installPnpm(inputs) console.log('Installation Completed!') setOutputs(inputs) + pnpmInstall(inputs) } main().catch(error => { diff --git a/src/pnpm-install/index.ts b/src/pnpm-install/index.ts new file mode 100644 index 0000000..5a09a0d --- /dev/null +++ b/src/pnpm-install/index.ts @@ -0,0 +1,40 @@ +import process from 'process' +import path from 'path' +import { spawnSync } from 'child_process' +import { setFailed } from '@actions/core' +import { Inputs } from '../inputs' + +export function runPnpmInstall(inputs: Inputs) { + const env = { + ...process.env, + PATH: inputs.binDest + path.delimiter + process.env.PATH + } + + 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(' ') + console.log('Running', cmdStr) + + const { error, status } = spawnSync('pnpm', args, { + stdio: 'inherit', + cwd: options.cwd, + shell: true, + env, + }) + + if (error) { + setFailed(error) + continue + } + + if (status) { + setFailed(`Command ${cmdStr} (cwd: ${options.cwd}) exits with status ${status}`) + continue + } + } +} + +export default runPnpmInstall