Skip to content

Commit f273a8a

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 f273a8a

File tree

6 files changed

+79
-6
lines changed

6 files changed

+79
-6
lines changed

ng-dev/release/publish/actions.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ 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+
workspaceRelativeBazelWorkspace,
16+
workspaceRelativePackageJsonPath,
17+
} from '../../utils/constants.js';
1418
import {AuthenticatedGitClient} from '../../utils/git/authenticated-git-client.js';
1519
import {isGithubApiError} from '../../utils/git/github.js';
1620
import githubMacros from '../../utils/git/github-macros.js';
@@ -140,6 +144,14 @@ export abstract class ReleaseAction {
140144
if (this.config.rulesJsInteropMode && existsSync(path.join(this.projectDir, '.aspect'))) {
141145
await ExternalCommands.invokeBazelUpdateAspectLockFiles(this.projectDir);
142146
}
147+
148+
if (
149+
existsSync(join(this.projectDir, workspaceRelativeBazelModuleLock)) &&
150+
!existsSync(join(this.projectDir, workspaceRelativeBazelWorkspace))
151+
) {
152+
// Updating the lock file is only needed when not using WORKSPACES.
153+
await ExternalCommands.invokeBazelModDepsUpdate(this.projectDir);
154+
}
143155
}
144156

145157
/*
@@ -152,6 +164,15 @@ export abstract class ReleaseAction {
152164
: [];
153165
}
154166

167+
/*
168+
* Get the modified "MODULE.bazel.lock" if bazel modules are enabled.
169+
*/
170+
protected getModuleBazelLockFile(): string | undefined {
171+
return existsSync(join(this.projectDir, workspaceRelativeBazelModuleLock))
172+
? workspaceRelativeBazelModuleLock
173+
: undefined;
174+
}
175+
155176
/** Gets the most recent commit of a specified branch. */
156177
protected async getLatestCommitOfBranch(branchName: string): Promise<Commit> {
157178
const {
@@ -225,6 +246,11 @@ export abstract class ReleaseAction {
225246
...this.getAspectLockFiles(),
226247
];
227248

249+
const bazelModuleLockFile = this.getModuleBazelLockFile();
250+
if (bazelModuleLockFile) {
251+
filesToCommit.push(bazelModuleLockFile);
252+
}
253+
228254
const commitMessage = getCommitMessageForRelease(newVersion);
229255

230256
// 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', 'dep', '--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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,9 @@ 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';
17+
18+
/** Workspace-relative path for the "WORKSPACE" file. */
19+
export const workspaceRelativeBazelWorkspace = 'WORKSPACE';

0 commit comments

Comments
 (0)