From d2ce32dcebf94b75d0693d241f7aa202ebef7ed0 Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Wed, 3 Mar 2021 22:29:24 -0500 Subject: [PATCH] chore(NA): do not use execa on bazel workspace status update script (#93532) (#93547) Co-authored-by: Tiago Costa --- src/dev/bazel_workspace_status.js | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/dev/bazel_workspace_status.js b/src/dev/bazel_workspace_status.js index 3c3ef1574cd8e..c7ae05ce48744 100644 --- a/src/dev/bazel_workspace_status.js +++ b/src/dev/bazel_workspace_status.js @@ -17,13 +17,21 @@ // If the script exits with non-zero code, it's considered as a failure // and the output will be discarded. -(async () => { - const execa = require('execa'); +(() => { + const cp = require('child_process'); const os = require('os'); - async function runCmd(cmd, args) { + function runCmd(cmd, args) { try { - return await execa(cmd, args); + const spawnResult = cp.spawnSync(cmd, args); + const exitCode = spawnResult.status !== null ? spawnResult.status : 1; + const stdoutStr = spawnResult.stdout.toString(); + const stdout = stdoutStr ? stdoutStr.trim() : null; + + return { + exitCode, + stdout, + }; } catch (e) { return { exitCode: 1 }; } @@ -31,29 +39,25 @@ // Git repo const kbnGitOriginName = process.env.KBN_GIT_ORIGIN_NAME || 'origin'; - const repoUrlCmdResult = await runCmd('git', [ - 'config', - '--get', - `remote.${kbnGitOriginName}.url`, - ]); + const repoUrlCmdResult = runCmd('git', ['config', '--get', `remote.${kbnGitOriginName}.url`]); if (repoUrlCmdResult.exitCode === 0) { // Only output REPO_URL when found it console.log(`REPO_URL ${repoUrlCmdResult.stdout}`); } // Commit SHA - const commitSHACmdResult = await runCmd('git', ['rev-parse', 'HEAD']); + const commitSHACmdResult = runCmd('git', ['rev-parse', 'HEAD']); if (commitSHACmdResult.exitCode === 0) { console.log(`COMMIT_SHA ${commitSHACmdResult.stdout}`); // Branch - const gitBranchCmdResult = await runCmd('git', ['rev-parse', '--abbrev-ref', 'HEAD']); + const gitBranchCmdResult = runCmd('git', ['rev-parse', '--abbrev-ref', 'HEAD']); if (gitBranchCmdResult.exitCode === 0) { console.log(`GIT_BRANCH ${gitBranchCmdResult.stdout}`); } // Tree status - const treeStatusCmdResult = await runCmd('git', ['diff-index', '--quiet', 'HEAD', '--']); + const treeStatusCmdResult = runCmd('git', ['diff-index', '--quiet', 'HEAD', '--']); const treeStatusVarStr = 'GIT_TREE_STATUS'; if (treeStatusCmdResult.exitCode === 0) { console.log(`${treeStatusVarStr} Clean`); @@ -64,7 +68,7 @@ // Host if (process.env.CI) { - const hostCmdResult = await runCmd('hostname'); + const hostCmdResult = runCmd('hostname'); const hostStr = hostCmdResult.stdout.split('-').slice(0, -1).join('-'); const coresStr = os.cpus().filter((cpu, index) => { return !cpu.model.includes('Intel') || index % 2 === 1;