Skip to content

Commit 76e78bb

Browse files
committed
fix(ng-dev): fix prerelease check in cherryPickChangelogIntoNextBranch
Prerelease is not a boolean but rather an array.
1 parent d861dc9 commit 76e78bb

File tree

2 files changed

+87
-4
lines changed

2 files changed

+87
-4
lines changed

ng-dev/release/publish/actions.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -575,15 +575,17 @@ export abstract class ReleaseAction {
575575
stagingBranch: string,
576576
): Promise<boolean> {
577577
const nextBranch = this.active.next.branchName;
578-
const commitMessage = getReleaseNoteCherryPickCommitMessage(releaseNotes.version);
578+
const {version} = releaseNotes;
579+
const commitMessage = getReleaseNoteCherryPickCommitMessage(version);
579580

580581
// Checkout the next branch.
581582
await this.checkoutUpstreamBranch(nextBranch);
582583

583584
await this.prependReleaseNotesToChangelog(releaseNotes);
584585

585586
const filesToCommit: string[] = [workspaceRelativeChangelogPath];
586-
if (releaseNotes.version.patch === 0 && !releaseNotes.version.prerelease) {
587+
588+
if (version.patch === 0 && version.prerelease.length === 0) {
587589
// Switch the renovate labels for `target: rc` to `target: patch`
588590
const renovateConfigPath = await updateRenovateConfigTargetLabels(
589591
this.projectDir,
@@ -597,12 +599,12 @@ export abstract class ReleaseAction {
597599
}
598600

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

602604
// Create a cherry-pick pull request that should be merged by the caretaker.
603605
const pullRequest = await this.pushChangesToForkAndCreatePullRequest(
604606
nextBranch,
605-
`changelog-cherry-pick-${releaseNotes.version}`,
607+
`changelog-cherry-pick-${version}`,
606608
commitMessage,
607609
`Cherry-picks the changelog from the "${stagingBranch}" branch to the next ` +
608610
`branch (${nextBranch}).`,

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

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,87 @@ 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+
'baseBranches': ['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+
});
585666
});
586667
});
587668

0 commit comments

Comments
 (0)