This commit is contained in:
khai96_ 2020-05-08 14:12:16 +07:00
parent 905bfaca2c
commit cf0395bd79
3 changed files with 25 additions and 9 deletions

BIN
dist/index.js vendored

Binary file not shown.

View File

@ -3,12 +3,15 @@ import getInputs from './inputs'
import setOutputs from './outputs'
import install from './install'
const inputs = getInputs()
async function main() {
const inputs = await getInputs()
await install(inputs).then(() => {
console.log('Installation Completed!')
setOutputs(inputs)
})
}
install(inputs).then(() => {
console.log('Installation Completed!')
setOutputs(inputs)
}).catch(error => {
main().catch(error => {
console.error(error)
setFailed(error)
})

View File

@ -1,4 +1,6 @@
import { getInput, InputOptions } from '@actions/core'
import { inspect } from 'util'
import { getInput, error, InputOptions } from '@actions/core'
import * as glob from '@actions/glob'
export interface Inputs {
readonly version: string
@ -11,10 +13,21 @@ const options: InputOptions = {
required: true,
}
export const getInputs = (): Inputs => ({
async function parsePath(pattern: string, inputName: string) {
const builder = await glob.create(pattern)
const paths = await builder.glob()
if (paths.length !== 1) {
error(`Input ${inputName} is expected to match 1 path, but it matches ${paths.length}: ${inspect(paths)}`)
}
return paths[0]
}
const parseInputPath = (name: string) => parsePath(getInput(name, options), name)
export const getInputs = async (): Promise<Inputs> => ({
version: getInput('version', options),
dest: getInput('dest', options),
binDest: getInput('bin_dest', options),
dest: await parseInputPath('dest'),
binDest: await parseInputPath('bin_dest'),
registry: getInput('registry', options),
})