Skip to content

fix(ng-dev): ensure update-generate-files completes on error #2810

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 16, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 39 additions & 34 deletions ng-dev/misc/generated-files/update-generated-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,45 +14,50 @@ import {green, Log} from '../../utils/logging.js';
export async function updateGeneratedFileTargets(): Promise<void> {
const spinner = new Spinner('Querying for all generated file targets');

// Query for all of the generated file targets
const result = await ChildProcess.spawn(
getBazelBin(),
[
'query',
`"kind(nodejs_binary, //...) intersect attr(name, '.update$', //...)"`,
'--output',
'label',
],
{mode: 'silent'},
);

if (result.status !== 0) {
spinner.complete();
throw Error(`Unexpected error: ${result.stderr}`);
}
try {
// Query for all of the generated file targets
const result = await ChildProcess.spawn(
getBazelBin(),
[
'query',
`"kind(nodejs_binary, //...) intersect attr(name, '.update$', //...)"`,
'--output',
'label',
],
{mode: 'silent'},
);

if (result.status !== 0) {
throw new Error(`Unexpected error: ${result.stderr}`);
}

const targets = result.stdout.trim().split(/\r?\n/);
const targets = result.stdout.trim().split(/\r?\n/);

Log.debug.group('Discovered Targets');
targets.forEach((target) => Log.debug(target));
Log.debug.groupEnd();
Log.debug.group('Discovered Targets');
targets.forEach((target) => Log.debug(target));
Log.debug.groupEnd();

spinner.update(`Found ${targets.length} generated file targets to update`);
spinner.update(`Found ${targets.length} generated file targets to update`);

// Build all of the generated file targets in parallel.
await ChildProcess.spawn(getBazelBin(), ['build', targets.join(' ')], {mode: 'silent'});
// Build all of the generated file targets in parallel.
await ChildProcess.spawn(getBazelBin(), ['build', targets.join(' ')], {mode: 'silent'});

// Individually run the generated file update targets.
for (let idx = 0; idx < targets.length; idx++) {
const target = targets[idx];
spinner.update(`${idx + 1} of ${targets.length} updates completed`);
const updateResult = await ChildProcess.spawn(getBazelBin(), ['run', target], {mode: 'silent'});
if (updateResult.status !== 0) {
spinner.complete();
throw Error(`Unexpected error while updating: ${target}.`);
// Individually run the generated file update targets.
for (let idx = 0; idx < targets.length; idx++) {
const target = targets[idx];
spinner.update(`${idx + 1} of ${targets.length} updates completed`);
const updateResult = await ChildProcess.spawn(getBazelBin(), ['run', target], {
mode: 'silent',
});
if (updateResult.status !== 0) {
throw new Error(`Unexpected error while updating: ${target}.`);
}
}
}

spinner.complete();
Log.info(` ${green('✔')} Updated all generated files (${targets.length} targets)`);
spinner.complete();
Log.info(` ${green('✔')} Updated all generated files (${targets.length} targets)`);
} catch (e) {
spinner.failure('An error has occurred.');
throw e;
}
}