Skip to content

Commit e54eaa7

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 e54eaa7

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

ng-dev/release/publish/actions.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
getListCommitsInBranchUrl,
2020
getRepositoryGitUrl,
2121
} from '../../utils/git/github-urls.js';
22-
import {green, Log} from '../../utils/logging.js';
22+
import {green, Log, yellow} from '../../utils/logging.js';
2323
import {Spinner} from '../../utils/spinner.js';
2424
import {BuiltPackage, BuiltPackageWithInfo, ReleaseConfig} from '../config/index.js';
2525
import {ReleaseNotes, workspaceRelativeChangelogPath} from '../notes/release-notes.js';
@@ -140,6 +140,37 @@ 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+
const spinner = new Spinner('Updating Renovate config');
155+
const renovateConfigPath = path.join(this.projectDir, 'renovate.json');
156+
const config = await fs.readFile(renovateConfigPath, 'utf-8');
157+
const configJson = JSON.parse(config) as Record<string, unknown>;
158+
const baseBranches = configJson.baseBranches;
159+
if (!Array.isArray(baseBranches) || baseBranches.length !== 2) {
160+
spinner.success(
161+
yellow('Skipped updating Renovate config: "baseBranches" must contain exactly 2 branches.'),
162+
);
163+
164+
return null;
165+
}
166+
167+
configJson.baseBranches = ['main', newBranchName];
168+
await fs.writeFile(renovateConfigPath, JSON.stringify(configJson, undefined, 2));
169+
spinner.success(green(' Updated Renovate config'));
170+
171+
return renovateConfigPath;
172+
}
173+
143174
/*
144175
* Get the modified Aspect lock files if `rulesJsInteropMode` is enabled.
145176
*/

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)