|
17 | 17 | // If the script exits with non-zero code, it's considered as a failure |
18 | 18 | // and the output will be discarded. |
19 | 19 |
|
20 | | -(async () => { |
21 | | - const execa = require('execa'); |
| 20 | +(() => { |
| 21 | + const cp = require('child_process'); |
22 | 22 | const os = require('os'); |
23 | 23 |
|
24 | | - async function runCmd(cmd, args) { |
| 24 | + function runCmd(cmd, args) { |
25 | 25 | try { |
26 | | - return await execa(cmd, args); |
| 26 | + const spawnResult = cp.spawnSync(cmd, args); |
| 27 | + const exitCode = spawnResult.status !== null ? spawnResult.status : 1; |
| 28 | + const stdoutStr = spawnResult.stdout.toString(); |
| 29 | + const stdout = stdoutStr ? stdoutStr.trim() : null; |
| 30 | + |
| 31 | + return { |
| 32 | + exitCode, |
| 33 | + stdout, |
| 34 | + }; |
27 | 35 | } catch (e) { |
28 | 36 | return { exitCode: 1 }; |
29 | 37 | } |
30 | 38 | } |
31 | 39 |
|
32 | 40 | // Git repo |
33 | 41 | const kbnGitOriginName = process.env.KBN_GIT_ORIGIN_NAME || 'origin'; |
34 | | - const repoUrlCmdResult = await runCmd('git', [ |
35 | | - 'config', |
36 | | - '--get', |
37 | | - `remote.${kbnGitOriginName}.url`, |
38 | | - ]); |
| 42 | + const repoUrlCmdResult = runCmd('git', ['config', '--get', `remote.${kbnGitOriginName}.url`]); |
39 | 43 | if (repoUrlCmdResult.exitCode === 0) { |
40 | 44 | // Only output REPO_URL when found it |
41 | 45 | console.log(`REPO_URL ${repoUrlCmdResult.stdout}`); |
42 | 46 | } |
43 | 47 |
|
44 | 48 | // Commit SHA |
45 | | - const commitSHACmdResult = await runCmd('git', ['rev-parse', 'HEAD']); |
| 49 | + const commitSHACmdResult = runCmd('git', ['rev-parse', 'HEAD']); |
46 | 50 | if (commitSHACmdResult.exitCode === 0) { |
47 | 51 | console.log(`COMMIT_SHA ${commitSHACmdResult.stdout}`); |
48 | 52 |
|
49 | 53 | // Branch |
50 | | - const gitBranchCmdResult = await runCmd('git', ['rev-parse', '--abbrev-ref', 'HEAD']); |
| 54 | + const gitBranchCmdResult = runCmd('git', ['rev-parse', '--abbrev-ref', 'HEAD']); |
51 | 55 | if (gitBranchCmdResult.exitCode === 0) { |
52 | 56 | console.log(`GIT_BRANCH ${gitBranchCmdResult.stdout}`); |
53 | 57 | } |
54 | 58 |
|
55 | 59 | // Tree status |
56 | | - const treeStatusCmdResult = await runCmd('git', ['diff-index', '--quiet', 'HEAD', '--']); |
| 60 | + const treeStatusCmdResult = runCmd('git', ['diff-index', '--quiet', 'HEAD', '--']); |
57 | 61 | const treeStatusVarStr = 'GIT_TREE_STATUS'; |
58 | 62 | if (treeStatusCmdResult.exitCode === 0) { |
59 | 63 | console.log(`${treeStatusVarStr} Clean`); |
|
64 | 68 |
|
65 | 69 | // Host |
66 | 70 | if (process.env.CI) { |
67 | | - const hostCmdResult = await runCmd('hostname'); |
| 71 | + const hostCmdResult = runCmd('hostname'); |
68 | 72 | const hostStr = hostCmdResult.stdout.split('-').slice(0, -1).join('-'); |
69 | 73 | const coresStr = os.cpus().filter((cpu, index) => { |
70 | 74 | return !cpu.model.includes('Intel') || index % 2 === 1; |
|
0 commit comments