From 84d1abfe4e0c08b14e9d1e4b13fbf548323f2aa7 Mon Sep 17 00:00:00 2001 From: Alan Agius <17563226+alan-agius4@users.noreply.github.com> Date: Fri, 9 May 2025 07:17:11 +0000 Subject: [PATCH] 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. --- .../actions/renovate-config-updates.ts | 41 +++++++++++++++++++ .../actions/shared/branch-off-next-branch.ts | 11 ++++- 2 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 ng-dev/release/publish/actions/renovate-config-updates.ts diff --git a/ng-dev/release/publish/actions/renovate-config-updates.ts b/ng-dev/release/publish/actions/renovate-config-updates.ts new file mode 100644 index 000000000..9ee6e28a2 --- /dev/null +++ b/ng-dev/release/publish/actions/renovate-config-updates.ts @@ -0,0 +1,41 @@ +import {existsSync} from 'node:fs'; +import {green, Log} from '../../../utils/logging.js'; +import {join} from 'node:path'; +import {writeFile, readFile} from 'node:fs/promises'; + +/** + * Updates the `renovate.json` configuration file to include a new base branch. + * + * @param projectDir - The project directory path. + * @param newBranchName - The name of the new branch to add to the base branches list. + * @returns A promise that resolves to an string containing the path to the modified `renovate.json` file, + * or null if config updating is disabled. + */ +export async function updateRenovateConfig( + projectDir: string, + newBranchName: string, +): Promise { + const renovateConfigPath = join(projectDir, 'renovate.json'); + if (!existsSync(renovateConfigPath)) { + Log.warn(` ✘ Skipped updating Renovate config as it was not found.`); + + return null; + } + + const config = await readFile(renovateConfigPath, 'utf-8'); + const configJson = JSON.parse(config) as Record; + const baseBranches = configJson.baseBranches; + if (!Array.isArray(baseBranches) || baseBranches.length !== 2) { + Log.warn( + ` ✘ Skipped updating Renovate config: "baseBranches" must contain exactly 2 branches.`, + ); + + return null; + } + + configJson.baseBranches = ['main', newBranchName]; + await writeFile(renovateConfigPath, JSON.stringify(configJson, undefined, 2)); + Log.info(green(` ✓ Updated Renovate config.`)); + + return renovateConfigPath; +} diff --git a/ng-dev/release/publish/actions/shared/branch-off-next-branch.ts b/ng-dev/release/publish/actions/shared/branch-off-next-branch.ts index 09a4286ad..7c504da8b 100644 --- a/ng-dev/release/publish/actions/shared/branch-off-next-branch.ts +++ b/ng-dev/release/publish/actions/shared/branch-off-next-branch.ts @@ -19,6 +19,7 @@ import { import {CutNpmNextPrereleaseAction} from '../cut-npm-next-prerelease.js'; import {CutNpmNextReleaseCandidateAction} from '../cut-npm-next-release-candidate.js'; import {ActiveReleaseTrains} from '../../../versioning/active-release-trains.js'; +import {updateRenovateConfig} from '../renovate-config-updates.js'; /** * 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 // Create an individual commit for the next version bump. The changelog should go into // a separate commit that makes it clear where the changelog is cherry-picked from. - await this.createCommit(bumpCommitMessage, [ + const filesToCommit: string[] = [ workspaceRelativePackageJsonPath, ...this.getAspectLockFiles(), - ]); + ]; + const renovateConfigPath = await updateRenovateConfig(this.projectDir, nextBranch); + if (renovateConfigPath) { + filesToCommit.push(renovateConfigPath); + } + + await this.createCommit(bumpCommitMessage, filesToCommit); await this.prependReleaseNotesToChangelog(releaseNotes); const commitMessage = getReleaseNoteCherryPickCommitMessage(releaseNotes.version);