Skip to content

Commit 825f198

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 825f198

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import {existsSync} from 'node:fs';
2+
import {green, Log} from '../../../utils/logging.js';
3+
import {join} from 'node:path';
4+
import {writeFile, readFile} from 'node:fs/promises';
5+
6+
/**
7+
* Updates the `renovate.json` configuration file to include a new base branch.
8+
*
9+
* This is used when `rulesJsInteropMode` is enabled to ensure the Renovate
10+
* tool considers both the main branch and a new feature or update branch.
11+
*
12+
* @param projectDir - The project directory path.
13+
* @param newBranchName - The name of the new branch to add to the base branches list.
14+
* @returns A promise that resolves to an string containing the path to the modified `renovate.json` file,
15+
* or null if config updating is disabled.
16+
*/
17+
export async function updateRenovateConfig(
18+
projectDir: string,
19+
newBranchName: string,
20+
): Promise<string | null> {
21+
const renovateConfigPath = join(projectDir, 'renovate.json');
22+
if (!existsSync(renovateConfigPath)) {
23+
Log.warn(` ✘ Skipped updating Renovate config as it was not found.`);
24+
25+
return null;
26+
}
27+
28+
const config = await readFile(renovateConfigPath, 'utf-8');
29+
const configJson = JSON.parse(config) as Record<string, unknown>;
30+
const baseBranches = configJson.baseBranches;
31+
if (!Array.isArray(baseBranches) || baseBranches.length !== 2) {
32+
Log.warn(
33+
` ✘ Skipped updating Renovate config: "baseBranches" must contain exactly 2 branches.`,
34+
);
35+
36+
return null;
37+
}
38+
39+
configJson.baseBranches = ['main', newBranchName];
40+
await writeFile(renovateConfigPath, JSON.stringify(configJson, undefined, 2));
41+
Log.info(green(` ✓ Updated Renovate config.`));
42+
43+
return renovateConfigPath;
44+
}

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
import {CutNpmNextPrereleaseAction} from '../cut-npm-next-prerelease.js';
2020
import {CutNpmNextReleaseCandidateAction} from '../cut-npm-next-release-candidate.js';
2121
import {ActiveReleaseTrains} from '../../../versioning/active-release-trains.js';
22+
import {updateRenovateConfig} from '../renovate-config-updates.js';
2223

2324
/**
2425
* Base action that can be used to move the next release-train into the dedicated FF/RC
@@ -139,11 +140,17 @@ export abstract class BranchOffNextBranchBaseAction extends CutNpmNextPrerelease
139140

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

148+
const renovateConfigPath = await updateRenovateConfig(this.projectDir, nextBranch);
149+
if (renovateConfigPath) {
150+
filesToCommit.push(renovateConfigPath);
151+
}
152+
153+
await this.createCommit(bumpCommitMessage, filesToCommit);
147154
await this.prependReleaseNotesToChangelog(releaseNotes);
148155

149156
const commitMessage = getReleaseNoteCherryPickCommitMessage(releaseNotes.version);

0 commit comments

Comments
 (0)