|
| 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 | + |
0 commit comments