Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions src/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import os from 'os'
import fs from 'fs'
import path from 'path'
import util from 'util'
import {getExecOutput, ExecOptions} from '@actions/exec'
import * as toolCache from '@actions/tool-cache'
Expand Down Expand Up @@ -39,15 +40,39 @@
args: string[],
options: ExecOptions = {} as ExecOptions
): Promise<ExecResult> {
const result = await getExecOutput(toolPath, args, options)
const allowedToolNames = new Set(['helm', 'kubectl', 'kompose'])
const resolvedToolPath = fs.realpathSync(toolPath)

Check failure on line 44 in src/utilities.ts

View workflow job for this annotation

GitHub Actions / build

src/utilities.test.ts > Test all functions in utilities file > execCommand() - return ExecOptions type object with stdout if exit code is 0

Error: ENOENT: no such file or directory, lstat '/home/runner/work/k8s-bake/k8s-bake/ls' ❯ Module.execCommand src/utilities.ts:44:32 ❯ src/utilities.test.ts:68:22 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { errno: -2, code: 'ENOENT', syscall: 'lstat', path: '/home/runner/work/k8s-bake/k8s-bake/ls' }
const executableName = path.basename(
resolvedToolPath,
getExecutableExtension()
)

if (!path.isAbsolute(resolvedToolPath)) {
throw Error(util.format('Executable path must be absolute: %s', toolPath))
}

if (!allowedToolNames.has(executableName)) {
throw Error(
util.format('Unexpected executable selected: %s', resolvedToolPath)
)
}

const executableStat = fs.statSync(resolvedToolPath)
if (!executableStat.isFile()) {
throw Error(
util.format('Executable path is not a file: %s', resolvedToolPath)
)
}

const result = await getExecOutput(resolvedToolPath, args, options)
if (result.exitCode != 0) {
if (!!result.stderr) {
throw Error(result.stderr)
} else {
throw Error(
util.format(
'%s exited with result code %s',
toolPath,
resolvedToolPath,
result.exitCode
)
)
Expand Down
Loading