-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(NA): move bazel workspace status from bash script into nodejs e…
…xecutable (#90560) * chore(NA): move bazel workspace status into nodejs executable * chore(NA): removed unused console.log on error * chore(NA): ability to setup different name for origin remote on workspace status command * chore(NA): do not fail if cant collect repo url Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
- Loading branch information
1 parent
b39ad86
commit 15a4c28
Showing
3 changed files
with
81 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
// Inspired on https://github.com/buildbuddy-io/buildbuddy/blob/master/workspace_status.sh | ||
// This script will be run bazel when building process starts to | ||
// generate key-value information that represents the status of the | ||
// workspace. The output should be like | ||
// | ||
// KEY1 VALUE1 | ||
// KEY2 VALUE2 | ||
// | ||
// 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 os = require('os'); | ||
|
||
async function runCmd(cmd, args) { | ||
try { | ||
return await execa(cmd, args); | ||
} catch (e) { | ||
return { exitCode: 1 }; | ||
} | ||
} | ||
|
||
// Git repo | ||
const kbnGitOriginName = process.env.KBN_GIT_ORIGIN_NAME || 'origin'; | ||
const repoUrlCmdResult = await 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']); | ||
if (commitSHACmdResult.exitCode !== 0) { | ||
process.exit(1); | ||
} | ||
console.log(`COMMIT_SHA ${commitSHACmdResult.stdout}`); | ||
|
||
// Git branch | ||
const gitBranchCmdResult = await runCmd('git', ['rev-parse', '--abbrev-ref', 'HEAD']); | ||
if (gitBranchCmdResult.exitCode !== 0) { | ||
process.exit(1); | ||
} | ||
console.log(`GIT_BRANCH ${gitBranchCmdResult.stdout}`); | ||
|
||
// Tree status | ||
const treeStatusCmdResult = await runCmd('git', ['diff-index', '--quiet', 'HEAD', '--']); | ||
const treeStatusVarStr = 'GIT_TREE_STATUS'; | ||
if (treeStatusCmdResult.exitCode === 0) { | ||
console.log(`${treeStatusVarStr} Clean`); | ||
} else { | ||
console.log(`${treeStatusVarStr} Modified`); | ||
} | ||
|
||
// Host | ||
if (process.env.CI) { | ||
const hostCmdResult = await 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; | ||
}).length; | ||
|
||
if (hostCmdResult.exitCode !== 0) { | ||
process.exit(1); | ||
} | ||
console.log(`HOST ${hostStr}-${coresStr}`); | ||
} | ||
})(); |
This file was deleted.
Oops, something went wrong.