Skip to content

Commit c30a786

Browse files
committed
build: add build step to the public API extractor script
This commit adds a step where we build all found targets in parallel, which speeds up the process of completing public API extractor test/update.
1 parent 6d3849f commit c30a786

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

goldens/public-api/manage.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,38 @@ const {Parser: parser} = require('yargs/helpers');
55
const argv = parser(process.argv.slice(2));
66
// The command the user would like to run, either 'accept' or 'test'
77
const USER_COMMAND = argv._[0];
8+
9+
// Location of all packages that we'd need to process.
10+
const API_TARGETS_LOCATION = 'packages/...';
11+
812
// The shell command to query for all Public API guard tests.
9-
const BAZEL_PUBLIC_API_TARGET_QUERY_CMD = `yarn -s bazel query --output label 'kind(nodejs_test, ...) intersect attr("tags", "api_guard", ...)'`;
13+
const BAZEL_PUBLIC_API_TARGET_QUERY_CMD =
14+
`yarn -s bazel query --output label 'kind(nodejs_test, ${API_TARGETS_LOCATION}) ` +
15+
`intersect attr("tags", "api_guard", ${API_TARGETS_LOCATION})'`;
1016
// Bazel targets for testing Public API goldens
11-
process.stdout.write('Gathering all Public API targets');
17+
process.stdout.write('Gathering all Public API targets...');
1218
const ALL_PUBLIC_API_TESTS = exec(BAZEL_PUBLIC_API_TARGET_QUERY_CMD, {silent: true})
1319
.trim()
1420
.split('\n')
1521
.map((test) => test.trim());
1622
process.stdout.clearLine();
1723
process.stdout.cursorTo(0);
24+
1825
// Bazel targets for generating Public API goldens
1926
const ALL_PUBLIC_API_ACCEPTS = ALL_PUBLIC_API_TESTS.map((test) => `${test}.accept`);
2027

28+
/** Builds all targets in parallel. */
29+
function buildTargets(targets) {
30+
process.stdout.write('Building all public API targets...');
31+
const commandResult = exec(`yarn -s bazel build ${targets.join(' ')}`, {silent: true});
32+
if (commandResult.code) {
33+
console.error(commandResult.stdout || commandResult.stderr);
34+
} else {
35+
process.stdout.clearLine();
36+
process.stdout.cursorTo(0);
37+
}
38+
}
39+
2140
/**
2241
* Run the provided bazel commands on each provided target individually.
2342
*/
@@ -40,9 +59,11 @@ function runBazelCommandOnTargets(command, targets, present) {
4059

4160
switch (USER_COMMAND) {
4261
case 'accept':
62+
buildTargets(ALL_PUBLIC_API_ACCEPTS);
4363
runBazelCommandOnTargets('run', ALL_PUBLIC_API_ACCEPTS, 'Running');
4464
break;
4565
case 'test':
66+
buildTargets(ALL_PUBLIC_API_TESTS);
4667
runBazelCommandOnTargets('test', ALL_PUBLIC_API_TESTS, 'Testing');
4768
break;
4869
default:

0 commit comments

Comments
 (0)