Files
runner-container-hooks/packages/docker/src/index.ts
T

50 lines
1.2 KiB
TypeScript
Raw Normal View History

2022-06-02 15:53:11 -04:00
import * as core from '@actions/core'
import {
Command,
getInputFromStdin,
PrepareJobArgs,
RunContainerStepArgs,
RunScriptStepArgs
} from 'hooklib/lib'
import { exit } from 'process'
import {
cleanupJob,
prepareJob,
runContainerStep,
runScriptStep
} from './hooks'
import { checkEnvironment } from './utils'
2022-06-02 15:53:11 -04:00
async function run(): Promise<void> {
try {
checkEnvironment()
const input = await getInputFromStdin()
const args = input['args']
const command = input['command']
const responseFile = input['responseFile']
const state = input['state']
2022-06-02 15:53:11 -04:00
switch (command) {
case Command.PrepareJob:
await prepareJob(args as PrepareJobArgs, responseFile)
return exit(0)
case Command.CleanupJob:
2022-06-03 15:15:19 +02:00
await cleanupJob()
2022-06-02 15:53:11 -04:00
return exit(0)
case Command.RunScriptStep:
await runScriptStep(args as RunScriptStepArgs, state)
return exit(0)
case Command.RunContainerStep:
await runContainerStep(args as RunContainerStepArgs, state)
return exit(0)
default:
throw new Error(`Command not recognized: ${command}`)
}
} catch (error) {
core.error(`${error}`)
exit(1)
}
}
void run()