diff --git a/src/inputs/index.ts b/src/inputs/index.ts new file mode 100644 index 0000000..c66aa2d --- /dev/null +++ b/src/inputs/index.ts @@ -0,0 +1,21 @@ +import { getInput, InputOptions } from '@actions/core' + +export interface Inputs { + readonly version: string + readonly dest: string + readonly binDest: string + readonly registry: string +} + +const options: InputOptions = { + required: true, +} + +export const getInputs = (): Inputs => ({ + version: getInput('version', options), + dest: getInput('dest', options), + binDest: getInput('bin_dest', options), + registry: getInput('registry', options), +}) + +export default getInputs diff --git a/src/install/index.ts b/src/install/index.ts new file mode 100644 index 0000000..8169fb7 --- /dev/null +++ b/src/install/index.ts @@ -0,0 +1,17 @@ +import { setFailed } from '@actions/core' +import { getInputs } from '../inputs' +import runSelfInstaller from './run' + +export { runSelfInstaller } + +export async function install() { + const { error, status } = await runSelfInstaller(getInputs()) + + if (error) return setFailed(error) + + if (status) { + return setFailed(`Something does wrong, self-installer exits with code ${status}`) + } +} + +export default install diff --git a/src/install/run.ts b/src/install/run.ts new file mode 100644 index 0000000..cf17f11 --- /dev/null +++ b/src/install/run.ts @@ -0,0 +1,18 @@ +import { spawnSync } from 'child_process' +import { downloadSelfInstaller } from '../self-installer' +import { Inputs } from '../inputs' + +export async function runSelfInstaller(inputs: Inputs) { + return spawnSync('node', { + env: { + PNPM_VERSION: inputs.version, + PNPM_DEST: inputs.dest, + PNPM_BIN_DEST: inputs.binDest, + PNPM_REGISTRY: inputs.registry, + }, + input: await downloadSelfInstaller(), + stdio: 'inherit', + }) +} + +export default runSelfInstaller diff --git a/src/self-installer/download.ts b/src/self-installer/download.ts new file mode 100644 index 0000000..4dd85a4 --- /dev/null +++ b/src/self-installer/download.ts @@ -0,0 +1,4 @@ +import download from 'download' +import url from './url' +export const downloadSelfInstaller = () => download(url) +export default downloadSelfInstaller diff --git a/src/self-installer/index.ts b/src/self-installer/index.ts new file mode 100644 index 0000000..be7f00f --- /dev/null +++ b/src/self-installer/index.ts @@ -0,0 +1,2 @@ +export * from './url' +export * from './download' diff --git a/src/self-installer/url.ts b/src/self-installer/url.ts new file mode 100644 index 0000000..09d3028 --- /dev/null +++ b/src/self-installer/url.ts @@ -0,0 +1,3 @@ +export const ref = '301414cec74a2b6b63c95b42f2ad1790ccb980ed' +export const url = `https://raw.githubusercontent.com/pnpm/self-installer/${ref}/install.js` +export default url