mirror of
https://github.com/Borales/actions-yarn.git
synced 2026-06-25 18:09:27 +08:00
Initial migration on TS
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
import {debug, getInput, setOutput, setFailed} from '@actions/core'
|
||||
import {ensureYarnIsInstalled} from './yarn'
|
||||
import {run} from './run'
|
||||
|
||||
const main = async () => {
|
||||
await ensureYarnIsInstalled()
|
||||
|
||||
const cmd: string = getInput('cmd', {required: true})
|
||||
|
||||
try {
|
||||
debug(`Running "${cmd}" command`)
|
||||
|
||||
await run(cmd)
|
||||
setOutput(cmd, 'Done')
|
||||
} catch (error) {
|
||||
if (error instanceof Error) setFailed(error.message)
|
||||
}
|
||||
}
|
||||
|
||||
main()
|
||||
@@ -0,0 +1,5 @@
|
||||
import {exec} from '@actions/exec'
|
||||
|
||||
export const run = async (cmd: string) => {
|
||||
await exec('yarn', [cmd])
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
import {debug} from '@actions/core'
|
||||
import {exec, getExecOutput} from '@actions/exec'
|
||||
import {which} from '@actions/io'
|
||||
|
||||
export const ensureYarnIsInstalled = async () => {
|
||||
try {
|
||||
await which('yarn', true)
|
||||
} catch (e) {
|
||||
await exec('npm install --global yarn')
|
||||
}
|
||||
|
||||
const [{stdout: yarnVersion}, {stdout: nodeVersion}] = await Promise.all([
|
||||
getExecOutput('yarn', ['--version'], {silent: true}),
|
||||
getExecOutput('node', ['--version'], {silent: true})
|
||||
])
|
||||
debug(`Node ${nodeVersion.trim()} detected`)
|
||||
debug(`Yarn v${yarnVersion.trim()} detected`)
|
||||
}
|
||||
Reference in New Issue
Block a user