Skip to content

Commit f78ddc9

Browse files
committed
feat(ng-dev): update renovate.json baseBranches when creating a new branch
Adds support for automatically modifying `renovate.json` to include newly created branches in the `baseBranches` array, when `updateRenovateConfig` is enabled.
1 parent 030487a commit f78ddc9

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

ng-dev/release/config/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,17 @@ export interface ReleaseConfig {
6868
*/
6969
// TODO(devversion): Remove after completing `rules_js` migration.
7070
rulesJsInteropMode?: boolean;
71+
72+
/**
73+
* Indicates whether the `renovate.json` configuration file should be updated
74+
* when a new branch is created (e.g., for feature freeze).
75+
*
76+
* If enabled (`true`), the new branch name will be added to the `baseBranches` field
77+
* in `renovate.json` to ensure Renovate monitors it.
78+
*
79+
* Defaults to `false` if not specified.
80+
*/
81+
updateRenovateConfig?: boolean;
7182
}
7283

7384
/**

ng-dev/release/publish/actions.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,33 @@ export abstract class ReleaseAction {
140140
}
141141
}
142142

143+
/**
144+
* Updates the `renovate.json` configuration file to include a new base branch.
145+
*
146+
* This is used when `rulesJsInteropMode` is enabled to ensure the Renovate
147+
* tool considers both the main branch and a new feature or update branch.
148+
*
149+
* @param newBranchName - The name of the new branch to add to the base branches list.
150+
* @returns A promise that resolves to an string containing the path to the modified `renovate.json` file,
151+
* or null if config updating is disabled.
152+
*/
153+
protected async updateRenovateConfig(newBranchName: string): Promise<string | null> {
154+
if (!this.config.updateRenovateConfig) {
155+
return null;
156+
}
157+
158+
const spinner = new Spinner('Updating Renovate config');
159+
const renovateConfigPath = path.join(this.projectDir, 'renovate.json');
160+
const config = await fs.readFile(renovateConfigPath, 'utf-8');
161+
const configJson = JSON.parse(config);
162+
configJson.baseBranches = ['main', newBranchName];
163+
164+
await fs.writeFile(renovateConfigPath, JSON.stringify(configJson, undefined, 2));
165+
spinner.success(green(' Updated Renovate config.'));
166+
167+
return renovateConfigPath;
168+
}
169+
143170
/*
144171
* Get the modified Aspect lock files if `rulesJsInteropMode` is enabled.
145172
*/

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,17 @@ export abstract class BranchOffNextBranchBaseAction extends CutNpmNextPrerelease
139139

140140
// Create an individual commit for the next version bump. The changelog should go into
141141
// a separate commit that makes it clear where the changelog is cherry-picked from.
142-
await this.createCommit(bumpCommitMessage, [
142+
const filesToCommit: string[] = [
143143
workspaceRelativePackageJsonPath,
144144
...this.getAspectLockFiles(),
145-
]);
145+
];
146146

147+
const renovateConfigPath = await this.updateRenovateConfig(nextBranch);
148+
if (renovateConfigPath) {
149+
filesToCommit.push(renovateConfigPath);
150+
}
151+
152+
await this.createCommit(bumpCommitMessage, filesToCommit);
147153
await this.prependReleaseNotesToChangelog(releaseNotes);
148154

149155
const commitMessage = getReleaseNoteCherryPickCommitMessage(releaseNotes.version);

0 commit comments

Comments
 (0)