mirror of
https://github.com/actions/runner-container-hooks.git
synced 2025-12-14 00:26:44 +00:00
39 lines
1.0 KiB
TypeScript
39 lines
1.0 KiB
TypeScript
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
import { RunScriptStepArgs } from 'hooklib'
|
|
import { execPodStep } from '../k8s'
|
|
import { JOB_CONTAINER_NAME } from './constants'
|
|
|
|
export async function runScriptStep(
|
|
args: RunScriptStepArgs,
|
|
state,
|
|
responseFile
|
|
): Promise<void> {
|
|
const cb = new CommandsBuilder(
|
|
args.entryPoint,
|
|
args.entryPointArgs,
|
|
args.environmentVariables
|
|
)
|
|
await execPodStep(cb.command, state.jobPod, JOB_CONTAINER_NAME)
|
|
}
|
|
|
|
class CommandsBuilder {
|
|
constructor(
|
|
private entryPoint: string,
|
|
private entryPointArgs: string[],
|
|
private environmentVariables: { [key: string]: string }
|
|
) {}
|
|
|
|
get command(): string[] {
|
|
const envCommands: string[] = []
|
|
if (
|
|
this.environmentVariables &&
|
|
Object.entries(this.environmentVariables).length
|
|
) {
|
|
for (const [key, value] of Object.entries(this.environmentVariables)) {
|
|
envCommands.push(`${key}=${value}`)
|
|
}
|
|
}
|
|
return ['env', ...envCommands, this.entryPoint, ...this.entryPointArgs]
|
|
}
|
|
}
|