forked from angular/dev-infra
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: introduce script for updating all generated files
Introduces a script for automatically updating all generated files in the dev-infra repository. This script can be wired up in a Github action Slash command, or when Renovate updates dependencies.
- Loading branch information
1 parent
e3148f6
commit ea8ceb0
Showing
2 changed files
with
38 additions
and
1 deletion.
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,36 @@ | ||
/** | ||
* Script that finds all `generated_file_test` targets and runs their `.update` targets. | ||
* This is useful if a dependency that is bundled into all checked-in bundles has been | ||
* updated. All of the checked-in bundles would need to be updated and it's cumbersome | ||
* to manually run all of these targets. | ||
*/ | ||
|
||
import {join} from 'path'; | ||
import {spawnSync, SpawnSyncOptionsWithStringEncoding} from 'child_process'; | ||
|
||
const projectDir = join(__dirname, '../'); | ||
const bazelPath = process.env.BAZEL ?? join(projectDir, 'node_modules/.bin/bazel'); | ||
const spawnOptions: SpawnSyncOptionsWithStringEncoding = { | ||
encoding: 'utf8', | ||
cwd: projectDir, | ||
shell: true, | ||
}; | ||
|
||
const queryProcess = spawnSync( | ||
bazelPath, | ||
['query', `"kind(nodejs_binary, //...) intersect attr(name, '.update$', //...)"`], | ||
spawnOptions, | ||
); | ||
|
||
if (queryProcess.status !== 0) { | ||
throw Error(`Unexpected error: ${queryProcess.error ?? queryProcess.stderr}`); | ||
} | ||
|
||
const updateTargets = queryProcess.stdout.trim().split(/\r?\n/); | ||
|
||
for (const targetName of updateTargets) { | ||
const proc = spawnSync(bazelPath, ['run', targetName], {...spawnOptions, stdio: 'inherit'}); | ||
if (proc.status !== 0) { | ||
throw Error(`Unexpected error while updating: ${targetName}.`); | ||
} | ||
} |