Skip to content

Commit dc41771

Browse files
committed
feat(ng-dev): handle updating the MODULE.bazel.lock file during a release
This lock has contains hashes of the package.json file. Thus it needs to be updated once the version is updating during the release.
1 parent fada401 commit dc41771

File tree

6 files changed

+71
-6
lines changed

6 files changed

+71
-6
lines changed

ng-dev/release/publish/actions.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ import {promises as fs, existsSync} from 'fs';
1010
import path, {join} from 'path';
1111
import semver from 'semver';
1212

13-
import {workspaceRelativePackageJsonPath} from '../../utils/constants.js';
13+
import {
14+
workspaceRelativeBazelModuleLock,
15+
workspaceRelativePackageJsonPath,
16+
} from '../../utils/constants.js';
1417
import {AuthenticatedGitClient} from '../../utils/git/authenticated-git-client.js';
1518
import {isGithubApiError} from '../../utils/git/github.js';
1619
import githubMacros from '../../utils/git/github-macros.js';
@@ -140,6 +143,10 @@ export abstract class ReleaseAction {
140143
if (this.config.rulesJsInteropMode && existsSync(path.join(this.projectDir, '.aspect'))) {
141144
await ExternalCommands.invokeBazelUpdateAspectLockFiles(this.projectDir);
142145
}
146+
147+
if (existsSync(join(this.projectDir, workspaceRelativeBazelModuleLock))) {
148+
await ExternalCommands.invokeBazelModDepsUpdate(this.projectDir);
149+
}
143150
}
144151

145152
/*
@@ -152,6 +159,15 @@ export abstract class ReleaseAction {
152159
: [];
153160
}
154161

162+
/*
163+
* Get the modified "MODULE.bazel.lock" if bazel modules are enabled.
164+
*/
165+
protected getModuleBazelLockFile(): string | undefined {
166+
return existsSync(join(this.projectDir, workspaceRelativeBazelModuleLock))
167+
? workspaceRelativeBazelModuleLock
168+
: undefined;
169+
}
170+
155171
/** Gets the most recent commit of a specified branch. */
156172
protected async getLatestCommitOfBranch(branchName: string): Promise<Commit> {
157173
const {
@@ -225,6 +241,11 @@ export abstract class ReleaseAction {
225241
...this.getAspectLockFiles(),
226242
];
227243

244+
const bazelModuleLockFile = this.getModuleBazelLockFile();
245+
if (bazelModuleLockFile) {
246+
filesToCommit.push(bazelModuleLockFile);
247+
}
248+
228249
const commitMessage = getCommitMessageForRelease(newVersion);
229250

230251
// Create a release staging commit including changelog and version bump.

ng-dev/release/publish/actions/configure-next-as-major.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,18 @@ export class ConfigureNextAsMajorAction extends ReleaseAction {
3939
await this.checkoutUpstreamBranch(branchName);
4040
await this.updateProjectVersion(newVersion);
4141

42-
await this.createCommit(getCommitMessageForNextBranchMajorSwitch(newVersion), [
42+
const filesToCommit: string[] = [
4343
workspaceRelativePackageJsonPath,
4444
...this.getAspectLockFiles(),
45-
]);
45+
];
46+
47+
const bazelModuleLockFile = this.getModuleBazelLockFile();
48+
if (bazelModuleLockFile) {
49+
filesToCommit.push(bazelModuleLockFile);
50+
}
51+
52+
await this.createCommit(getCommitMessageForNextBranchMajorSwitch(newVersion), filesToCommit);
53+
4654
const pullRequest = await this.pushChangesToForkAndCreatePullRequest(
4755
branchName,
4856
`switch-next-to-major-${newVersion}`,

ng-dev/release/publish/actions/exceptional-minor/prepare-exceptional-minor.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,20 @@ export class PrepareExceptionalMinorAction extends ReleaseAction {
4949
pkgJson[exceptionalMinorPackageIndicator] = true;
5050
});
5151

52-
await this.createCommit(`build: prepare exceptional minor branch: ${this._newBranch}`, [
52+
const filesToCommit: string[] = [
5353
workspaceRelativePackageJsonPath,
5454
...this.getAspectLockFiles(),
55-
]);
55+
];
56+
57+
const bazelModuleLockFile = this.getModuleBazelLockFile();
58+
if (bazelModuleLockFile) {
59+
filesToCommit.push(bazelModuleLockFile);
60+
}
61+
62+
await this.createCommit(
63+
`build: prepare exceptional minor branch: ${this._newBranch}`,
64+
filesToCommit,
65+
);
5666

5767
await this.pushHeadToRemoteBranch(this._newBranch);
5868

ng-dev/release/publish/actions/shared/branch-off-next-branch.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@ export abstract class BranchOffNextBranchBaseAction extends CutNpmNextPrerelease
145145
...this.getAspectLockFiles(),
146146
];
147147

148+
const bazelModuleLockFile = this.getModuleBazelLockFile();
149+
if (bazelModuleLockFile) {
150+
filesToCommit.push(bazelModuleLockFile);
151+
}
152+
148153
const renovateConfigPath = await updateRenovateConfig(
149154
this.projectDir,
150155
`${version.major}.${version.minor}.x`,

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
*/
88

99
import semver from 'semver';
10-
1110
import {ChildProcess, SpawnResult, SpawnOptions} from '../../utils/child-process.js';
1211
import {Spinner} from '../../utils/spinner.js';
1312
import {NpmDistTag} from '../versioning/index.js';
@@ -263,6 +262,25 @@ export abstract class ExternalCommands {
263262
}
264263
}
265264

265+
/**
266+
* Invokes the `bazel mod deps --lockfile_mode=update` command in order
267+
* to refresh `MODULE.bazel.lock` file.
268+
*/
269+
static async invokeBazelModDepsUpdate(projectDir: string): Promise<void> {
270+
const spinner = new Spinner('Updating "MODULE.bazel.lock"');
271+
try {
272+
await ChildProcess.spawn(getBazelBin(), ['mod', 'deps', '--lockfile_mode=update'], {
273+
cwd: projectDir,
274+
mode: 'silent',
275+
});
276+
} catch (e) {
277+
Log.error(e);
278+
Log.error(' ✘ An error occurred while updating "MODULE.bazel.lock".');
279+
throw new FatalReleaseActionError();
280+
}
281+
spinner.success(green(' Updated "MODULE.bazel.lock" file.'));
282+
}
283+
266284
/**
267285
* Invokes the `yarn bazel sync --only=repo` command in order
268286
* to refresh Aspect lock files.

ng-dev/utils/constants.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@ export const ngDevNpmPackageName = '@angular/ng-dev';
1111

1212
/** Workspace-relative path for the "package.json" file. */
1313
export const workspaceRelativePackageJsonPath = 'package.json';
14+
15+
/** Workspace-relative path for the "MODULE.bazel.lock" file. */
16+
export const workspaceRelativeBazelModuleLock = 'MODULE.bazel.lock';

0 commit comments

Comments
 (0)