2020-03-05 21:19:45 +08:00
|
|
|
import {exec} from '@actions/exec'
|
2021-04-21 23:03:15 +08:00
|
|
|
import buffer from 'buffer'
|
2020-01-12 09:26:08 +08:00
|
|
|
|
2021-04-21 23:03:15 +08:00
|
|
|
let output = ''
|
2020-01-20 04:33:14 +08:00
|
|
|
|
2020-01-12 09:26:08 +08:00
|
|
|
/** Wrapper around the GitHub toolkit exec command which returns the output.
|
|
|
|
* Also allows you to easily toggle the current working directory.
|
2020-03-09 21:19:16 +08:00
|
|
|
*
|
|
|
|
* @param {string} cmd - The command to execute.
|
|
|
|
* @param {string} cwd - The current working directory.
|
2020-06-26 20:18:23 +08:00
|
|
|
* @param {boolean} silent - Determines if the in/out should be silenced or not.
|
2020-01-12 09:26:08 +08:00
|
|
|
*/
|
2020-06-26 20:18:23 +08:00
|
|
|
export async function execute(
|
|
|
|
cmd: string,
|
|
|
|
cwd: string,
|
2020-06-27 02:10:06 +08:00
|
|
|
silent: boolean
|
2020-06-26 20:18:23 +08:00
|
|
|
): Promise<any> {
|
2020-03-05 21:19:45 +08:00
|
|
|
output = ''
|
2020-01-12 09:26:08 +08:00
|
|
|
|
|
|
|
await exec(cmd, [], {
|
2020-03-02 20:52:38 +08:00
|
|
|
// Silences the input unless the INPUT_DEBUG flag is set.
|
2020-06-26 20:18:23 +08:00
|
|
|
silent,
|
2020-01-12 09:26:08 +08:00
|
|
|
cwd,
|
|
|
|
listeners: {
|
2020-01-20 04:33:14 +08:00
|
|
|
stdout
|
2020-01-12 09:26:08 +08:00
|
|
|
}
|
2020-03-05 21:19:45 +08:00
|
|
|
})
|
2020-01-12 09:26:08 +08:00
|
|
|
|
2020-03-31 08:44:09 +08:00
|
|
|
return Promise.resolve(output)
|
2020-01-12 09:26:08 +08:00
|
|
|
}
|
2020-01-20 04:33:14 +08:00
|
|
|
|
2020-03-07 11:36:56 +08:00
|
|
|
export function stdout(data: any): string | void {
|
2021-04-21 23:03:15 +08:00
|
|
|
if (output.length < buffer.constants.MAX_STRING_LENGTH) {
|
|
|
|
output += data.toString().trim()
|
|
|
|
}
|
2020-01-20 04:33:14 +08:00
|
|
|
}
|