Skip to content

Commit b888786

Browse files
committed
fix(ng-dev): remove renovate target label update during release
The logic to update the renovate config during the release to switch the target labels from `target: rc` to `target: patch` has been removed. Instead, a static `target: automation` label is added to the default renovate preset. This simplifies the release process by removing the need to update the renovate config during the release.
1 parent 0f0f951 commit b888786

File tree

5 files changed

+1
-184
lines changed

5 files changed

+1
-184
lines changed

ng-dev/release/publish/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ ts_project(
1818
"//ng-dev:node_modules/semver",
1919
"//ng-dev:node_modules/typed-graphqlify",
2020
"//ng-dev/commit-message",
21-
"//ng-dev/pr/common/labels",
2221
"//ng-dev/pr/merge",
2322
"//ng-dev/release/build",
2423
"//ng-dev/release/config",

ng-dev/release/publish/actions.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ import {promptToInitiatePullRequestMerge} from './prompt-merge.js';
4343
import {Prompt} from '../../utils/prompt.js';
4444
import {PnpmVersioning} from './pnpm-versioning.js';
4545
import {Commit} from '../../utils/git/octokit-types.js';
46-
import {updateRenovateConfigTargetLabels} from './actions/renovate-config-updates.js';
47-
import {targetLabels} from '../../pr/common/labels/target.js';
4846

4947
/** Interface describing a Github repository. */
5048
export interface GithubRepo {
@@ -567,19 +565,6 @@ export abstract class ReleaseAction {
567565

568566
const filesToCommit: string[] = [workspaceRelativeChangelogPath];
569567

570-
if (version.patch === 0 && version.prerelease.length === 0) {
571-
// Switch the renovate labels for `target: rc` to `target: patch`
572-
const renovateConfigPath = await updateRenovateConfigTargetLabels(
573-
this.projectDir,
574-
targetLabels['TARGET_RC'].name,
575-
targetLabels['TARGET_PATCH'].name,
576-
);
577-
578-
if (renovateConfigPath) {
579-
filesToCommit.push(renovateConfigPath);
580-
}
581-
}
582-
583568
await this.createCommit(commitMessage, filesToCommit);
584569
Log.info(green(` ✓ Created changelog cherry-pick commit for: "${version}".`));
585570

ng-dev/release/publish/actions/renovate-config-updates.ts

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import {existsSync} from 'node:fs';
22
import {green, Log} from '../../../utils/logging.js';
33
import {join} from 'node:path';
44
import {writeFile, readFile} from 'node:fs/promises';
5-
import {targetLabels} from '../../../pr/common/labels/target.js';
65

76
/**
87
* Updates the `renovate.json` configuration file to include a new base branch.
@@ -37,92 +36,8 @@ export async function updateRenovateConfig(
3736

3837
configJson['baseBranchPatterns'] = ['main', newBranchName];
3938

40-
updateRenovateTargetLabel(
41-
configJson,
42-
targetLabels['TARGET_PATCH'].name,
43-
targetLabels['TARGET_RC'].name,
44-
);
4539
await writeFile(renovateConfigPath, JSON.stringify(configJson, undefined, 2));
4640

4741
Log.info(green(` ✓ Updated Renovate config.`));
4842
return renovateConfigPath;
4943
}
50-
51-
/**
52-
* Updates a specific target label in the `renovate.json` configuration file.
53-
* This function specifically targets and replaces one label with another within the `packageRules`.
54-
*
55-
* @param projectDir - The path to the project directory.
56-
* @param fromLabel - The label name to be replaced.
57-
* @param toLabel - The new label name to replace `fromLabel` with.
58-
* @returns A promise that resolves to the path of the modified `renovate.json` file if updated,
59-
* or `null` if the file was not found or the `baseBranchPatterns` array has an unexpected format.
60-
*/
61-
export async function updateRenovateConfigTargetLabels(
62-
projectDir: string,
63-
fromLabel: string,
64-
toLabel: string,
65-
): Promise<string | null> {
66-
const renovateConfigPath = join(projectDir, 'renovate.json');
67-
if (!existsSync(renovateConfigPath)) {
68-
Log.warn(` ✘ Skipped updating Renovate config as it was not found.`);
69-
70-
return null;
71-
}
72-
73-
const config = await readFile(renovateConfigPath, 'utf-8');
74-
const configJson = JSON.parse(config) as Record<string, unknown>;
75-
76-
// Check baseBranchPatterns just in case, though this function's primary focus is labels
77-
const baseBranchPatterns = configJson['baseBranchPatterns'];
78-
if (!Array.isArray(baseBranchPatterns) || baseBranchPatterns.length !== 2) {
79-
Log.warn(
80-
` ✘ Skipped updating Renovate config: "baseBranchPatterns" must contain exactly 2 branches.`,
81-
);
82-
83-
return null;
84-
}
85-
86-
if (updateRenovateTargetLabel(configJson, fromLabel, toLabel)) {
87-
await writeFile(renovateConfigPath, JSON.stringify(configJson, undefined, 2));
88-
Log.info(green(` ✓ Updated target label in Renovate config.`));
89-
90-
return renovateConfigPath;
91-
} else {
92-
Log.info(green(` ✓ No changes to target labels in Renovate config.`));
93-
return null;
94-
}
95-
}
96-
97-
/**
98-
* Updates a specific target label within the `packageRules` of a Renovate configuration.
99-
*
100-
* @param configJson - The parsed JSON object of the Renovate configuration.
101-
* @param fromLabel - The label name to be replaced.
102-
* @param toLabel - The new label name to replace `fromLabel` with.
103-
* @returns `true` is the label has been updated, otherwise `false`.
104-
*/
105-
function updateRenovateTargetLabel(
106-
configJson: Record<string, unknown>,
107-
fromLabel: string,
108-
toLabel: string,
109-
): boolean {
110-
if (!Array.isArray(configJson['packageRules'])) {
111-
return false;
112-
}
113-
114-
let updated = false;
115-
for (const rule of configJson['packageRules']) {
116-
if (!Array.isArray(rule.addLabels)) {
117-
continue;
118-
}
119-
120-
const idx = (rule.addLabels as string[]).findIndex((x) => x === fromLabel);
121-
if (idx >= 0) {
122-
rule.addLabels[idx] = toLabel;
123-
updated = true;
124-
}
125-
}
126-
127-
return updated;
128-
}

ng-dev/release/publish/test/common.spec.ts

Lines changed: 0 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -582,87 +582,6 @@ describe('common release action logic', () => {
582582
}),
583583
);
584584
});
585-
586-
it('should update the renovate config labels in the cherry-pick commit', async () => {
587-
const baseReleaseTrains = new ActiveReleaseTrains({
588-
exceptionalMinor: null,
589-
releaseCandidate: new ReleaseTrain('10.1.x', parse('10.1.0-rc.0')),
590-
next: new ReleaseTrain('master', parse('10.2.0-next.0')),
591-
latest: new ReleaseTrain('10.0.x', parse('10.0.0')),
592-
});
593-
const {version, branchName} = baseReleaseTrains.latest;
594-
const forkBranchName = `changelog-cherry-pick-${version}`;
595-
596-
const {repo, fork, instance, gitClient, projectDir} = setupReleaseActionForTesting(
597-
DelegateTestAction,
598-
baseReleaseTrains,
599-
);
600-
601-
// Expect the changelog to be fetched and return a fake changelog to test that
602-
// it is properly appended. Also expect a pull request to be created in the fork.
603-
repo
604-
.expectFindForkRequest(fork)
605-
.expectPullRequestToBeCreated('master', fork, forkBranchName, 200)
606-
.expectPullRequestMergeCheck(200, false)
607-
.expectPullRequestMerge(200);
608-
609-
// Simulate that the fork branch name is available.
610-
fork.expectBranchRequest(forkBranchName);
611-
612-
const renovateConfigPath = join(projectDir, 'renovate.json');
613-
writeFileSync(
614-
renovateConfigPath,
615-
JSON.stringify({
616-
'baseBranchPatterns': ['main', '20.1.x'],
617-
'packageRules': [
618-
{
619-
'matchBaseBranches': ['main'],
620-
'addLabels': ['target: minor'],
621-
},
622-
{
623-
'matchBaseBranches': ['!main'],
624-
'addLabels': ['target: rc'],
625-
},
626-
],
627-
}),
628-
'utf8',
629-
);
630-
631-
await instance.testCherryPickWithPullRequest(version, branchName);
632-
633-
expect(gitClient.pushed.length).toBe(1);
634-
expect(gitClient.pushed[0]).toEqual(
635-
getBranchPushMatcher({
636-
targetBranch: forkBranchName,
637-
targetRepo: fork,
638-
baseBranch: 'master',
639-
baseRepo: repo,
640-
expectedCommits: [
641-
{
642-
message: `docs: release notes for the v${version} release`,
643-
files: ['CHANGELOG.md', renovateConfigPath],
644-
},
645-
],
646-
}),
647-
);
648-
649-
// Verify renovate config contents
650-
const {packageRules} = JSON.parse(readFileSync(renovateConfigPath, 'utf-8')) as Record<
651-
string,
652-
unknown
653-
>;
654-
655-
expect(packageRules).toEqual([
656-
{
657-
'matchBaseBranches': ['main'],
658-
'addLabels': ['target: minor'],
659-
},
660-
{
661-
'matchBaseBranches': ['!main'],
662-
'addLabels': ['target: patch'],
663-
},
664-
]);
665-
});
666585
});
667586
});
668587

renovate-presets/default.json5

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
semanticCommits: 'enabled',
1717
semanticCommitScope: '',
1818
semanticCommitType: 'build',
19-
labels: ['area: build & ci', 'action: merge'],
19+
labels: ['area: build & ci', 'action: merge', 'target: automation'],
2020

2121
lockFileMaintenance: {
2222
enabled: true,
@@ -44,7 +44,6 @@
4444
{
4545
postUpgradeTasks: {
4646
commands: [
47-
'var',
4847
'git restore .npmrc || true', // In case `.npmrc` avoid a hard error.
4948
'pnpm install --frozen-lockfile',
5049
'pnpm bazel mod deps --lockfile_mode=update',

0 commit comments

Comments
 (0)