toolrunner should which tool before invoking (#220)

This commit is contained in:
eric sciple
2019-11-18 16:20:01 -05:00
committed by GitHub
parent 9a3c005162
commit 5c894298f2
10 changed files with 261 additions and 65 deletions

View File

@@ -1,8 +1,11 @@
import * as os from 'os'
import * as events from 'events'
import * as child from 'child_process'
import * as path from 'path'
import * as stream from 'stream'
import * as im from './interfaces'
import * as io from '@actions/io'
import * as ioUtil from '@actions/io/lib/io-util'
/* eslint-disable @typescript-eslint/unbound-method */
@@ -392,6 +395,24 @@ export class ToolRunner extends events.EventEmitter {
* @returns number
*/
async exec(): Promise<number> {
// root the tool path if it is unrooted and contains relative pathing
if (
!ioUtil.isRooted(this.toolPath) &&
(this.toolPath.includes('/') ||
(IS_WINDOWS && this.toolPath.includes('\\')))
) {
// prefer options.cwd if it is specified, however options.cwd may also need to be rooted
this.toolPath = path.resolve(
process.cwd(),
this.options.cwd || process.cwd(),
this.toolPath
)
}
// if the tool is only a file name, then resolve it from the PATH
// otherwise verify it exists (add extension on Windows if necessary)
this.toolPath = await io.which(this.toolPath, true)
return new Promise<number>((resolve, reject) => {
this._debug(`exec tool: ${this.toolPath}`)
this._debug('arguments:')