angular/aio/tools/transforms/angular-base-package/services/bazelStampedProperties.js
Derek Cormier 8c9f067125 build(bazel): prevent remote cache misses on dgeni build (#48585)
Using 'always' as the stamp attribute caused stable-status.txt
to always be included as an input, which has different values on
different ci executors causing a cache miss.

We run the regular aio build without stamping on ci so only include
status files when stamping is explicitly enabled.

PR Close #48585
2022-12-24 11:25:40 +00:00

28 lines
No EOL
784 B
JavaScript

'use strict';
const fs = require('fs');
/**
* Provide stamped Bazel variables from the workspace status command.
*
* (see https://bazel.build/docs/user-manual#workspace-status)
*
* @returns a map of key-value pairs
*/
module.exports = function bazelStampedProperties() {
if (!process.env.BAZEL_VERSION_FILE) {
// Bazel stamping not enabled with --stamp
return {};
}
const volatileStatus = fs.readFileSync(process.env.BAZEL_VERSION_FILE, 'utf8');
const properties = {};
for (const match of `\n${volatileStatus}`.matchAll(/^([^\s]+)\s+(.*)/gm)) {
// Lines which go unmatched define an index value of `0` and should be skipped.
if (match.index === 0) {
continue;
}
properties[match[1]] = match[2];
}
return properties;
};