Skip to content

Commit 7fb8527

Browse files
devversionzarend
authored andcommitted
refactor(dev-infra): remove invoke bazel clean command from release tool (#42101)
Currently the ng-dev release tool always run `bazel clean` before calling the configured build release function. The clean is necessary to ensure the release output is actually built; and not restored from previous builds which could have different bazel workspace status variables (which provide the NPM package version). Instead of doing this as part of the release tool, the actual script running to build the release output should run the `bazel clean`. The release tool does not intend to know about details on how the release output is built. This is necessary because the build setup could vary between version branches (especially for older ones; such as LTS version branches). PR Close #42101
1 parent 3aec55b commit 7fb8527

File tree

5 files changed

+11
-40
lines changed

5 files changed

+11
-40
lines changed

dev-infra/ng-dev.js

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5623,25 +5623,6 @@ function invokeYarnInstallCommand(projectDir) {
56235623
}
56245624
});
56255625
}
5626-
/**
5627-
* Invokes the `yarn bazel clean` command in order to clean the output tree and ensure new artifacts
5628-
* are created for builds.
5629-
*/
5630-
function invokeBazelCleanCommand(projectDir) {
5631-
return tslib.__awaiter(this, void 0, void 0, function* () {
5632-
try {
5633-
// Note: No progress indicator needed as that is the responsibility of the command.
5634-
// TODO: Consider using an Ora spinner instead to ensure minimal console output.
5635-
yield spawnWithDebugOutput('yarn', ['bazel', 'clean'], { cwd: projectDir });
5636-
info(green(' ✓ Cleaned bazel output tree.'));
5637-
}
5638-
catch (e) {
5639-
error(e);
5640-
error(red(' ✘ An error occurred while cleaning the bazel output tree.'));
5641-
throw new FatalReleaseActionError();
5642-
}
5643-
});
5644-
}
56455626

56465627
/**
56475628
* @license
@@ -6297,7 +6278,6 @@ class ReleaseAction {
62976278
// created in the `next` branch. The new package would not be part of the patch branch,
62986279
// so we cannot build and publish it.
62996280
yield invokeYarnInstallCommand(this.projectDir);
6300-
yield invokeBazelCleanCommand(this.projectDir);
63016281
const builtPackages = yield invokeReleaseBuildCommand();
63026282
// Verify the packages built are the correct version.
63036283
yield this._verifyPackageVersions(releaseNotes.version, builtPackages);

dev-infra/release/publish/actions.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {runNpmPublish} from '../versioning/npm-publish';
2121
import {FatalReleaseActionError, UserAbortedReleaseActionError} from './actions-error';
2222
import {getCommitMessageForRelease, getReleaseNoteCherryPickCommitMessage} from './commit-message';
2323
import {changelogPath, packageJsonPath, waitForPullRequestInterval} from './constants';
24-
import {invokeBazelCleanCommand, invokeReleaseBuildCommand, invokeYarnInstallCommand} from './external-commands';
24+
import {invokeReleaseBuildCommand, invokeYarnInstallCommand} from './external-commands';
2525
import {findOwnedForksOfRepoQuery} from './graphql-queries';
2626
import {getPullRequestState} from './pull-request-state';
2727
import {getLocalChangelogFilePath, ReleaseNotes} from './release-notes/release-notes';
@@ -463,7 +463,6 @@ export abstract class ReleaseAction {
463463
// created in the `next` branch. The new package would not be part of the patch branch,
464464
// so we cannot build and publish it.
465465
await invokeYarnInstallCommand(this.projectDir);
466-
await invokeBazelCleanCommand(this.projectDir);
467466
const builtPackages = await invokeReleaseBuildCommand();
468467

469468
// Verify the packages built are the correct version.

dev-infra/release/publish/external-commands.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -90,20 +90,3 @@ export async function invokeYarnInstallCommand(projectDir: string): Promise<void
9090
throw new FatalReleaseActionError();
9191
}
9292
}
93-
94-
/**
95-
* Invokes the `yarn bazel clean` command in order to clean the output tree and ensure new artifacts
96-
* are created for builds.
97-
*/
98-
export async function invokeBazelCleanCommand(projectDir: string): Promise<void> {
99-
try {
100-
// Note: No progress indicator needed as that is the responsibility of the command.
101-
// TODO: Consider using an Ora spinner instead to ensure minimal console output.
102-
await spawnWithDebugOutput('yarn', ['bazel', 'clean'], {cwd: projectDir});
103-
info(green(' ✓ Cleaned bazel output tree.'));
104-
} catch (e) {
105-
error(e);
106-
error(red(' ✘ An error occurred while cleaning the bazel output tree.'));
107-
throw new FatalReleaseActionError();
108-
}
109-
}

dev-infra/release/publish/test/test-utils.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ export function setupReleaseActionForTesting<T extends ReleaseAction>(
9797
spyOn(npm, 'runNpmPublish').and.resolveTo();
9898
spyOn(externalCommands, 'invokeSetNpmDistCommand').and.resolveTo();
9999
spyOn(externalCommands, 'invokeYarnInstallCommand').and.resolveTo();
100-
spyOn(externalCommands, 'invokeBazelCleanCommand').and.resolveTo();
101100
spyOn(externalCommands, 'invokeReleaseBuildCommand').and.resolveTo([
102101
{name: '@angular/pkg1', outputPath: `${testTmpDir}/dist/pkg1`},
103102
{name: '@angular/pkg2', outputPath: `${testTmpDir}/dist/pkg2`}

scripts/build/package-builder.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@ function buildTargetPackages(destDir, enableIvy, description, isRelease = false)
8181
bazelCmd} query --output=label "attr('tags', '\\[.*release-with-framework.*\\]', //packages/...) intersect kind('ng_package|pkg_npm', //packages/...)"`;
8282
const targets = exec(getTargetsCmd, true).split(/\r?\n/);
8383

84+
// If we are in release mode, run `bazel clean` to ensure the execroot and action cache
85+
// are not populated. This is necessary because targets using `npm_package` rely on
86+
// workspace status variables for the package version. Such NPM package targets are not
87+
// rebuilt if only the workspace status variables change. This could result in accidental
88+
// re-use of previously built package output with a different `version` in the `package.json`.
89+
if (isRelease) {
90+
console.info('Building in release mode. Resetting the Bazel execroot and action cache..');
91+
exec(`${bazelCmd} clean`);
92+
}
93+
8494
// Use either `--config=snapshot` or `--config=release` so that builds are created with the
8595
// correct embedded version info.
8696
exec(`${bazelCmd} build --config=${isRelease ? 'release' : 'snapshot'} --config=${

0 commit comments

Comments
 (0)