Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion ng-dev/release/publish/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ ts_project(
"//ng-dev:node_modules/semver",
"//ng-dev:node_modules/typed-graphqlify",
"//ng-dev/commit-message",
"//ng-dev/pr/common/labels",
"//ng-dev/pr/merge",
"//ng-dev/release/build",
"//ng-dev/release/config",
Expand Down
15 changes: 0 additions & 15 deletions ng-dev/release/publish/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ import {promptToInitiatePullRequestMerge} from './prompt-merge.js';
import {Prompt} from '../../utils/prompt.js';
import {PnpmVersioning} from './pnpm-versioning.js';
import {Commit} from '../../utils/git/octokit-types.js';
import {updateRenovateConfigTargetLabels} from './actions/renovate-config-updates.js';
import {targetLabels} from '../../pr/common/labels/target.js';

/** Interface describing a Github repository. */
export interface GithubRepo {
Expand Down Expand Up @@ -567,19 +565,6 @@ export abstract class ReleaseAction {

const filesToCommit: string[] = [workspaceRelativeChangelogPath];

if (version.patch === 0 && version.prerelease.length === 0) {
// Switch the renovate labels for `target: rc` to `target: patch`
const renovateConfigPath = await updateRenovateConfigTargetLabels(
this.projectDir,
targetLabels['TARGET_RC'].name,
targetLabels['TARGET_PATCH'].name,
);

if (renovateConfigPath) {
filesToCommit.push(renovateConfigPath);
}
}

await this.createCommit(commitMessage, filesToCommit);
Log.info(green(` ✓ Created changelog cherry-pick commit for: "${version}".`));

Expand Down
85 changes: 0 additions & 85 deletions ng-dev/release/publish/actions/renovate-config-updates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {existsSync} from 'node:fs';
import {green, Log} from '../../../utils/logging.js';
import {join} from 'node:path';
import {writeFile, readFile} from 'node:fs/promises';
import {targetLabels} from '../../../pr/common/labels/target.js';

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

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

updateRenovateTargetLabel(
configJson,
targetLabels['TARGET_PATCH'].name,
targetLabels['TARGET_RC'].name,
);
await writeFile(renovateConfigPath, JSON.stringify(configJson, undefined, 2));

Log.info(green(` ✓ Updated Renovate config.`));
return renovateConfigPath;
}

/**
* Updates a specific target label in the `renovate.json` configuration file.
* This function specifically targets and replaces one label with another within the `packageRules`.
*
* @param projectDir - The path to the project directory.
* @param fromLabel - The label name to be replaced.
* @param toLabel - The new label name to replace `fromLabel` with.
* @returns A promise that resolves to the path of the modified `renovate.json` file if updated,
* or `null` if the file was not found or the `baseBranchPatterns` array has an unexpected format.
*/
export async function updateRenovateConfigTargetLabels(
projectDir: string,
fromLabel: string,
toLabel: string,
): Promise<string | null> {
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<string, unknown>;

// Check baseBranchPatterns just in case, though this function's primary focus is labels
const baseBranchPatterns = configJson['baseBranchPatterns'];
if (!Array.isArray(baseBranchPatterns) || baseBranchPatterns.length !== 2) {
Log.warn(
` ✘ Skipped updating Renovate config: "baseBranchPatterns" must contain exactly 2 branches.`,
);

return null;
}

if (updateRenovateTargetLabel(configJson, fromLabel, toLabel)) {
await writeFile(renovateConfigPath, JSON.stringify(configJson, undefined, 2));
Log.info(green(` ✓ Updated target label in Renovate config.`));

return renovateConfigPath;
} else {
Log.info(green(` ✓ No changes to target labels in Renovate config.`));
return null;
}
}

/**
* Updates a specific target label within the `packageRules` of a Renovate configuration.
*
* @param configJson - The parsed JSON object of the Renovate configuration.
* @param fromLabel - The label name to be replaced.
* @param toLabel - The new label name to replace `fromLabel` with.
* @returns `true` is the label has been updated, otherwise `false`.
*/
function updateRenovateTargetLabel(
configJson: Record<string, unknown>,
fromLabel: string,
toLabel: string,
): boolean {
if (!Array.isArray(configJson['packageRules'])) {
return false;
}

let updated = false;
for (const rule of configJson['packageRules']) {
if (!Array.isArray(rule.addLabels)) {
continue;
}

const idx = (rule.addLabels as string[]).findIndex((x) => x === fromLabel);
if (idx >= 0) {
rule.addLabels[idx] = toLabel;
updated = true;
}
}

return updated;
}
81 changes: 0 additions & 81 deletions ng-dev/release/publish/test/common.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -582,87 +582,6 @@ describe('common release action logic', () => {
}),
);
});

it('should update the renovate config labels in the cherry-pick commit', async () => {
const baseReleaseTrains = new ActiveReleaseTrains({
exceptionalMinor: null,
releaseCandidate: new ReleaseTrain('10.1.x', parse('10.1.0-rc.0')),
next: new ReleaseTrain('master', parse('10.2.0-next.0')),
latest: new ReleaseTrain('10.0.x', parse('10.0.0')),
});
const {version, branchName} = baseReleaseTrains.latest;
const forkBranchName = `changelog-cherry-pick-${version}`;

const {repo, fork, instance, gitClient, projectDir} = setupReleaseActionForTesting(
DelegateTestAction,
baseReleaseTrains,
);

// Expect the changelog to be fetched and return a fake changelog to test that
// it is properly appended. Also expect a pull request to be created in the fork.
repo
.expectFindForkRequest(fork)
.expectPullRequestToBeCreated('master', fork, forkBranchName, 200)
.expectPullRequestMergeCheck(200, false)
.expectPullRequestMerge(200);

// Simulate that the fork branch name is available.
fork.expectBranchRequest(forkBranchName);

const renovateConfigPath = join(projectDir, 'renovate.json');
writeFileSync(
renovateConfigPath,
JSON.stringify({
'baseBranchPatterns': ['main', '20.1.x'],
'packageRules': [
{
'matchBaseBranches': ['main'],
'addLabels': ['target: minor'],
},
{
'matchBaseBranches': ['!main'],
'addLabels': ['target: rc'],
},
],
}),
'utf8',
);

await instance.testCherryPickWithPullRequest(version, branchName);

expect(gitClient.pushed.length).toBe(1);
expect(gitClient.pushed[0]).toEqual(
getBranchPushMatcher({
targetBranch: forkBranchName,
targetRepo: fork,
baseBranch: 'master',
baseRepo: repo,
expectedCommits: [
{
message: `docs: release notes for the v${version} release`,
files: ['CHANGELOG.md', renovateConfigPath],
},
],
}),
);

// Verify renovate config contents
const {packageRules} = JSON.parse(readFileSync(renovateConfigPath, 'utf-8')) as Record<
string,
unknown
>;

expect(packageRules).toEqual([
{
'matchBaseBranches': ['main'],
'addLabels': ['target: minor'],
},
{
'matchBaseBranches': ['!main'],
'addLabels': ['target: patch'],
},
]);
});
});
});

Expand Down
3 changes: 1 addition & 2 deletions renovate-presets/default.json5
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
semanticCommits: 'enabled',
semanticCommitScope: '',
semanticCommitType: 'build',
labels: ['area: build & ci', 'action: merge'],
labels: ['area: build & ci', 'action: merge', 'target: automation'],

lockFileMaintenance: {
enabled: true,
Expand Down Expand Up @@ -44,7 +44,6 @@
{
postUpgradeTasks: {
commands: [
'var',
'git restore .npmrc || true', // In case `.npmrc` avoid a hard error.
'pnpm install --frozen-lockfile',
'pnpm bazel mod deps --lockfile_mode=update',
Expand Down
Loading