Skip to content
This repository was archived by the owner on Nov 22, 2024. It is now read-only.

Commit 47de598

Browse files
committed
build: fix populating version placeholder in release builds
1 parent 69149de commit 47de598

File tree

3 files changed

+42
-41
lines changed

3 files changed

+42
-41
lines changed

.bazelrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ test
4040

4141
# Configures script to do version stamping.
4242
# See https://docs.bazel.build/versions/master/user-manual.html#flag--workspace_status_command
43-
build:release --workspace_status_command=./tools/bazel-stamp-vars.sh
43+
build:release --workspace_status_command="node ./tools/bazel-stamp-vars.js"
4444

4545
###############################
4646
# Typescript / Angular / Sass #
@@ -66,4 +66,4 @@ build --define=compile=legacy
6666

6767
# Turn on managed directories feature in Bazel
6868
# This allows us to avoid installing a second copy of node_modules
69-
common --experimental_allow_incremental_repository_updates
69+
common --experimental_allow_incremental_repository_updates

tools/bazel-stamp-vars.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* Bazel workspace status script that is responsible for creating Bazel stamping variables.
5+
* The stamping variables will be used by the NodeJS Bazel rules to provide proper version
6+
* placeholder replacements. Read more about variable stamping within Bazel:
7+
* https://docs.bazel.build/versions/master/user-manual.html#flag--workspace_status_command
8+
*/
9+
10+
const spawnSync = require('child_process').spawnSync;
11+
const packageJson = require('../package');
12+
13+
const currentCommitSha = getCurrentCommitSha();
14+
15+
// The "BUILD_SCM_VERSION" will be picked up by the "npm_package" and "ng_package"
16+
// rule in order to populate the "0.0.0-PLACEHOLDER". Note that the SHA will be only
17+
// appended for snapshots builds from within the "publish-build-artifacts.sh" script.
18+
console.log(`BUILD_SCM_VERSION ${packageJson.version}`);
19+
console.log(`BUILD_SCM_COMMIT_SHA ${currentCommitSha}`);
20+
console.log(`BUILD_SCM_BRANCH ${getCurrentBranchName()}`);
21+
console.log(`BUILD_SCM_USER ${getCurrentGitUser()}`);
22+
23+
/** Returns the commit SHA for the current git HEAD of the project. */
24+
function getCurrentCommitSha() {
25+
return spawnSync('git', ['rev-parse', 'HEAD']).stdout.toString().trim();
26+
}
27+
28+
/** Returns the name of the currently checked out branch of the project. */
29+
function getCurrentBranchName() {
30+
return spawnSync('git', ['symbolic-ref', '--short', 'HEAD']).stdout.toString().trim();
31+
}
32+
33+
/** Returns the name and email of the Git user that creates this release build. */
34+
function getCurrentGitUser() {
35+
const userName = spawnSync('git', ['config', 'user.name']).stdout.toString().trim();
36+
const userEmail = spawnSync('git', ['config', 'user.email']).stdout.toString().trim();
37+
38+
return `${userName} <${userEmail}>`;
39+
}
40+

tools/bazel-stamp-vars.sh

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)