diff --git a/src/model/docker.ts b/src/model/docker.ts index b9be14aa..41ac8758 100644 --- a/src/model/docker.ts +++ b/src/model/docker.ts @@ -52,7 +52,8 @@ class Docker { const { workspace, actionFolder, unitySerial, gitPrivateToken, cliStoragePath } = parameters; // Todo - get this to work on a non-github runner local machine - // return String.dedent`run ${image} powershell c:/steps/entrypoint.ps1`; + // Note: difference between `docker run` and `run` + return String.dedent`run ${image} powershell c:/steps/entrypoint.ps1`; return String.dedent` docker run \ --workdir /github/workspace \ diff --git a/src/model/system.ts b/src/model/system.ts index 409f8ecb..73f0de89 100644 --- a/src/model/system.ts +++ b/src/model/system.ts @@ -8,8 +8,12 @@ class System { * Make sure it's Windows/MacOS/Ubuntu compatible or has alternative commands. * * Intended to always be silent and capture the output. + * + * @returns {string} output of the command on success or failure + * + * @throws {Error} if anything was output to stderr. */ - static async run(rawCommand: string, options: RunOptions = {}) { + static async run(rawCommand: string, options: RunOptions = {}): Promise { const { pwd } = options; let command = rawCommand; @@ -23,11 +27,11 @@ class System { return shellMethod(command, options); } - static async shellRun(command: string, options: RunOptions = {}) { + static async shellRun(command: string, options: RunOptions = {}): Promise { return System.newRun('sh', ['-c', command]); } - static async powershellRun(command: string, options: RunOptions = {}) { + static async powershellRun(command: string, options: RunOptions = {}): Promise { return System.newRun('powershell', [command]); } @@ -45,9 +49,9 @@ class System { * System.newRun(sh, ['-c', 'echo something']) * System.newRun(powershell, ['echo something']) * - * @deprecated use System.run instead, this method will be private + * @deprecated not really deprecated, but please use System.run instead because this method will be made private. */ - public static async newRun(command, args: string | string[] = []) { + public static async newRun(command, args: string | string[] = []): Promise { if (!Array.isArray(args)) args = [args]; const argsString = args.join(' '); @@ -78,7 +82,13 @@ class System { }); } - if (error) throw new Error(error); + if (error) { + // Make sure we don't swallow any output + const errorMessage = output ? `${error}\n\n---\n\nOutput before the error:\n${output}` : error; + + // Throw instead or returning when any output was written to stdout + throw new Error(errorMessage); + } return result; }