mirror of
https://git.mirrors.martin98.com/https://github.com/actions/toolkit
synced 2026-04-06 01:03:16 +08:00
toolrunner should which tool before invoking (#220)
This commit is contained in:
@@ -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:')
|
||||
|
||||
Reference in New Issue
Block a user