8000 feat(ng-dev): update `renovate.json` baseBranches when creating a new… · angular/dev-infra@d344104 · GitHub
[go: up one dir, main page]

Skip to content

Commit d344104

Browse files
alan-agius4devversion
authored andcommitted
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 359e881 commit d344104

File tree

2 files changed

+50
-2
lines changed

2 files changed

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

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)
0