19 Commits

Author SHA1 Message Date
271a9df5fb Try different ways 2020-05-09 20:57:00 +07:00
3b5e8836ec Update dist/index.js 2020-05-09 20:52:54 +07:00
0fa2b7d3a5 Use console.log 2020-05-09 20:52:27 +07:00
c3e0d9f20f Update dist/index.js 2020-05-09 20:50:21 +07:00
d2316507fd Inspect isPost 2020-05-09 20:47:42 +07:00
1790ca7f76 Add pnpm install 2020-05-09 20:24:52 +07:00
9a1617cf46 Rename install to install-pnpm 2020-05-09 20:03:45 +07:00
6fe65dc1af Move run-install to its own module 2020-05-09 20:01:25 +07:00
91d3d73121 Correct validation error message 2020-05-09 19:52:48 +07:00
7a5d08caa7 Update run.sh 2020-05-09 19:46:36 +07:00
e373fffa0a Use ajv to validate schema 2020-05-09 19:45:31 +07:00
bb24f595c2 Add schema generator 2020-05-09 19:24:07 +07:00
d44b8c5e53 Add run_install input 2020-05-09 19:13:46 +07:00
4b13327683 Re-add dist/index.js 2020-05-09 18:27:15 +07:00
49ba4cbc60 Delete dist/index.js 2020-05-09 18:26:16 +07:00
9649109f2e Fix .gitattributes 2020-05-09 08:13:09 +07:00
087311f996 refactor: Remove then 2020-05-08 21:55:03 +07:00
9979c3d928 Use node-fetch 2020-05-08 21:34:25 +07:00
738fb9213f Fix README.md 2020-05-08 21:23:23 +07:00
16 changed files with 796 additions and 656 deletions

2
.gitattributes vendored
View File

@ -1,2 +1,2 @@
* text=auto
dist/index.js -text
/dist/index.js binary

View File

@ -20,6 +20,10 @@ Install PNPM package manager.
**Optional** Registry to download PNPM from.
### `run_install`
**Optional** If specified, run `pnpm install`.
## Outputs
### `dest`
@ -28,7 +32,7 @@ Expanded path of inputs#dest.
### `bin_dest`
Expanded path of inputs@bin_dest.
Expanded path of inputs#bin_dest.
## Usage example

View File

@ -19,6 +19,11 @@ inputs:
description: Registry to download PNPM from
required: false
default: https://registry.npmjs.com
run_install:
description: If specified, run `pnpm install`
required: false
default: 'null'
runs:
using: node12
main: dist/index.js
post: dist/index.js

2
dist/index.js vendored

File diff suppressed because one or more lines are too long

View File

@ -1,20 +1,25 @@
{
"private": true,
"scripts": {
"build:schemas": "ts-schema-autogen generate",
"build:ncc": "ncc build --minify --no-source-map-register --no-cache dist/tsc/index.js --out dist/",
"build": "tsc && pnpm run build:ncc",
"build": "pnpm run build:schemas && tsc && pnpm run build:ncc",
"start": "pnpm run build && sh ./run.sh"
},
"dependencies": {
"download": "^8.0.0",
"node-fetch": "^2.6.0",
"expand-tilde": "^2.0.2",
"js-yaml": "^3.13.1",
"ajv": "^6.12.0",
"@actions/core": "^1.2.4",
"@types/download": "^6.2.4",
"@types/expand-tilde": "^2.0.0",
"@types/node-fetch": "^2.5.7",
"@types/js-yaml": "^3.12.3",
"@types/node": "^13.13.5"
},
"devDependencies": {
"typescript": "^3.8.3",
"@ts-schema-autogen/cli": "^0.1.2",
"@zeit/ncc": "^0.22.1"
}
}

1251
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

1
run.sh
View File

@ -5,4 +5,5 @@ export INPUT_VERSION=4.11.1
export INPUT_DEST='~/pnpm.temp'
export INPUT_BIN_DEST='~/pnpm.temp/.bin'
export INPUT_REGISTRY=https://registry.npmjs.com
export INPUT_RUN_INSTALL=null
exec node dist/index.js

View File

@ -1,14 +1,24 @@
import { setFailed } from '@actions/core'
import { setFailed, getState } from '@actions/core'
import getInputs from './inputs'
import setOutputs from './outputs'
import install from './install'
import installPnpm from './install-pnpm'
import pnpmInstall from './pnpm-install'
async function main() {
const inputs = getInputs()
await install(inputs).then(() => {
console.log('Installation Completed!')
setOutputs(inputs)
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()
await installPnpm(inputs)
console.log('Installation Completed!')
setOutputs(inputs)
pnpmInstall(inputs)
}
main().catch(error => {

View File

@ -1,11 +1,13 @@
import { getInput, InputOptions } from '@actions/core'
import expandTilde from 'expand-tilde'
import { RunInstall, parseRunInstall } from './run-install'
export interface Inputs {
readonly version: string
readonly dest: string
readonly binDest: string
readonly registry: string
readonly runInstall: RunInstall[]
}
const options: InputOptions = {
@ -19,6 +21,7 @@ export const getInputs = (): Inputs => ({
dest: parseInputPath('dest'),
binDest: parseInputPath('bin_dest'),
registry: getInput('registry', options),
runInstall: parseRunInstall('run_install'),
})
export default getInputs

View File

@ -0,0 +1,21 @@
{
"$schema": "https://raw.githubusercontent.com/ksxnodeapps/ts-schema-autogen/master/packages/schemas/config.schema.json",
"instruction": {
"compilerOptions": {
"strict": true,
"target": "ES2018",
"lib": [
"ES2018",
"ES2019",
"ES2020",
"ESNext"
],
"moduleResolution": "Node",
"esModuleInterop": true,
"resolveJsonModule": true
},
"input": "run-install.ts",
"symbol": "RunInstallInput",
"output": "run-install-input.schema.json"
}
}

View File

@ -0,0 +1,39 @@
{
"anyOf": [
{
"$ref": "#/definitions/RunInstall"
},
{
"type": "array",
"items": {
"$ref": "#/definitions/RunInstall"
}
},
{
"type": [
"null",
"boolean"
]
}
],
"definitions": {
"RunInstall": {
"type": "object",
"properties": {
"recursive": {
"type": "boolean"
},
"cwd": {
"type": "string"
},
"args": {
"type": "array",
"items": {
"type": "string"
}
}
}
}
},
"$schema": "http://json-schema.org/draft-07/schema#"
}

40
src/inputs/run-install.ts Normal file
View File

@ -0,0 +1,40 @@
import process from 'process'
import { safeLoad } from 'js-yaml'
import Ajv from 'ajv'
import { getInput, error, InputOptions } from '@actions/core'
import runInstallSchema from './run-install-input.schema.json'
export interface RunInstall {
readonly recursive?: boolean
readonly cwd?: string
readonly args?: readonly string[]
}
export type RunInstallInput =
| null
| boolean
| RunInstall
| RunInstall[]
const options: InputOptions = {
required: true,
}
export function parseRunInstall(name: string): RunInstall[] {
const result: RunInstallInput = safeLoad(getInput(name, options))
const ajv = new Ajv({
allErrors: true,
async: false,
})
const validate = ajv.compile(runInstallSchema)
if (!validate(result)) {
for (const errorItem of validate.errors!) {
error(`with.run_install${errorItem.dataPath}: ${errorItem.message}`)
}
return process.exit(1)
}
if (!result) return []
if (result === true) return [{ recursive: true }]
if (Array.isArray(result)) return result
return [result]
}

View File

@ -3,7 +3,7 @@ import { execPath } from 'process'
import { downloadSelfInstaller } from '../self-installer'
import { Inputs } from '../inputs'
export function runSelfInstaller(inputs: Inputs): Promise<number> {
export async function runSelfInstaller(inputs: Inputs): Promise<number> {
const cp = spawn(execPath, {
env: {
PNPM_VERSION: inputs.version,
@ -14,7 +14,8 @@ export function runSelfInstaller(inputs: Inputs): Promise<number> {
stdio: ['pipe', 'inherit', 'inherit'],
})
downloadSelfInstaller().pipe(cp.stdin)
const response = await downloadSelfInstaller()
response.body.pipe(cp.stdin)
return new Promise((resolve, reject) => {
cp.on('error', reject)

40
src/pnpm-install/index.ts Normal file
View File

@ -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

View File

@ -1,4 +1,4 @@
import download from 'download'
import fetch from 'node-fetch'
import url from './url'
export const downloadSelfInstaller = () => download(url)
export const downloadSelfInstaller = () => fetch(url)
export default downloadSelfInstaller