Skip to content

Commit

Permalink
fix(ng-dev): configure next as major action never selectable
Browse files Browse the repository at this point in the history
It looks like we never wired up this action properly. We should
enable it so that the caretaker can use it, instead of manually
having to do it.
  • Loading branch information
devversion committed Dec 22, 2022
1 parent 4058cc6 commit c37e8ac
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 38 deletions.
16 changes: 11 additions & 5 deletions ng-dev/release/publish/actions/configure-next-as-major.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import {workspaceRelativePackageJsonPath} from '../../../utils/constants.js';
import {ActiveReleaseTrains} from '../../versioning/active-release-trains.js';
import {ReleaseAction} from '../actions.js';
import {getCommitMessageForNextBranchMajorSwitch} from '../commit-message.js';
import {isFirstNextPrerelease} from '../../versioning/prerelease-version.js';
import {isVersionPublishedToNpm} from '../../versioning/npm-registry.js';
import {ReleaseConfig} from '../../config/index.js';

/**
* Release action that configures the active next release-train to be for a major
Expand Down Expand Up @@ -49,10 +52,13 @@ export class ConfigureNextAsMajorAction extends ReleaseAction {
await this.promptAndWaitForPullRequestMerged(pullRequest);
}

static override async isActive(active: ActiveReleaseTrains) {
// The `next` branch can always be switched to a major version, unless it already
// is targeting a new major. A major can contain minor changes, so we can always
// change the target from a minor to a major.
return !active.next.isMajor;
static override async isActive(active: ActiveReleaseTrains, config: ReleaseConfig) {
// The `next` branch can be switched to a major version, unless it already
// is targeting a new major, or if pre-releases have already started.
return (
!active.next.isMajor &&
isFirstNextPrerelease(active.next.version) &&
!(await isVersionPublishedToNpm(active.next.version, config))
);
}
}
3 changes: 2 additions & 1 deletion ng-dev/release/publish/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import {ReleaseActionConstructor} from '../actions.js';

import {ConfigureNextAsMajorAction} from './configure-next-as-major.js';
import {CutLongTermSupportPatchAction} from './cut-lts-patch.js';
import {CutNewPatchAction} from './cut-new-patch.js';
import {CutNpmNextPrereleaseAction} from './cut-npm-next-prerelease.js';
Expand All @@ -34,6 +34,7 @@ export const actions: ReleaseActionConstructor[] = [
CutNpmNextPrereleaseAction,
MoveNextIntoFeatureFreezeAction,
MoveNextIntoReleaseCandidateAction,
ConfigureNextAsMajorAction,
PrepareExceptionalMinorAction,
CutLongTermSupportPatchAction,
];
4 changes: 4 additions & 0 deletions ng-dev/release/publish/test/common.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ describe('common release action logic', () => {
`Cut a first release-candidate for the "10.1.x" branch (v10.1.0-rc.0).`,
`Cut a new patch release for the "10.0.x" branch (v10.0.2).`,
`Cut a new pre-release for the "10.1.x" branch (v10.1.0-next.4).`,
`Configure the "master" branch to be released as major (v11.0.0-next.0).`,
`Cut a new release for an active LTS branch (0 active).`,
]);
});
Expand Down Expand Up @@ -102,6 +103,7 @@ describe('common release action logic', () => {
'Cut a stable release for the "15.0.x" branch — published as `@next` (v15.0.0).',
'Cut a new patch release for the "14.3.x" branch (v14.3.2).',
`Cut a new pre-release for the "15.0.x" branch (v15.0.0-rc.2).`,
`Configure the "main" branch to be released as major (v16.0.0-next.0).`,
`Prepare an exceptional minor based on the existing "14.3.x" branch (14.4.x).`,
`Cut a new release for an active LTS branch (0 active).`,
]);
Expand Down Expand Up @@ -134,6 +136,7 @@ describe('common release action logic', () => {
`Exceptional Minor: Cut a new pre-release for the "14.4.x" branch (v14.4.0-next.0).`,
'Cut a new patch release for the "14.3.x" branch (v14.3.2).',
`Cut a new pre-release for the "15.0.x" branch (v15.0.0-rc.2).`,
`Configure the "main" branch to be released as major (v16.0.0-next.0).`,
`Cut a new release for an active LTS branch (0 active).`,
]);
});
Expand Down Expand Up @@ -165,6 +168,7 @@ describe('common release action logic', () => {
`Cut a stable release for the "14.4.x" branch — published as \`@latest\` (v14.4.0).`,
'Cut a new patch release for the "14.3.x" branch (v14.3.2).',
`Cut a new pre-release for the "15.0.x" branch (v15.0.0-rc.2).`,
`Configure the "main" branch to be released as major (v16.0.0-next.0).`,
`Cut a new release for an active LTS branch (0 active).`,
]);
});
Expand Down
91 changes: 59 additions & 32 deletions ng-dev/release/publish/test/configure-next-as-major.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,43 +13,70 @@ import {ConfigureNextAsMajorAction} from '../actions/configure-next-as-major.js'
import {parse, setupReleaseActionForTesting} from './test-utils/test-utils.js';

describe('configure next as major action', () => {
it('should be active if the next branch is for a minor', async () => {
expect(
await ConfigureNextAsMajorAction.isActive(
new ActiveReleaseTrains({
exceptionalMinor: null,
releaseCandidate: null,
next: new ReleaseTrain('master', parse('10.1.0-next.3')),
latest: new ReleaseTrain('10.0.x', parse('10.0.3')),
}),
),
).toBe(true);
it('should be active if the next branch is for a minor where the pre-release is unpublished', async () => {
const action = setupReleaseActionForTesting(
ConfigureNextAsMajorAction,
new ActiveReleaseTrains({
exceptionalMinor: null,
releaseCandidate: null,
next: new ReleaseTrain('master', parse('10.1.0-next.0')),
latest: new ReleaseTrain('10.0.x', parse('10.0.3')),
}),
{isNextPublishedToNpm: false},
);

expect(await ConfigureNextAsMajorAction.isActive(action.active, action.releaseConfig)).toBe(
true,
);
});

it('should be active regardless of a feature-freeze/release-candidate train', async () => {
expect(
await ConfigureNextAsMajorAction.isActive(
new ActiveReleaseTrains({
exceptionalMinor: null,
releaseCandidate: new ReleaseTrain('10.1.x', parse('10.1.0-rc.1')),
next: new ReleaseTrain('master', parse('10.2.0-next.3')),
latest: new ReleaseTrain('10.0.x', parse('10.0.3')),
}),
),
).toBe(true);
const action = setupReleaseActionForTesting(
ConfigureNextAsMajorAction,
new ActiveReleaseTrains({
exceptionalMinor: null,
releaseCandidate: new ReleaseTrain('10.1.x', parse('10.1.0-rc.1')),
next: new ReleaseTrain('master', parse('10.2.0-next.0')),
latest: new ReleaseTrain('10.0.x', parse('10.0.3')),
}),
{isNextPublishedToNpm: false},
);

expect(await ConfigureNextAsMajorAction.isActive(action.active, action.releaseConfig)).toBe(
true,
);
});

it('should be not active if the next branch is for a minor but already pre-releases are published', async () => {
const action = setupReleaseActionForTesting(
ConfigureNextAsMajorAction,
new ActiveReleaseTrains({
exceptionalMinor: null,
releaseCandidate: null,
next: new ReleaseTrain('master', parse('10.1.0-next.3')),
latest: new ReleaseTrain('10.0.x', parse('10.0.3')),
}),
);

expect(await ConfigureNextAsMajorAction.isActive(action.active, action.releaseConfig)).toBe(
false,
);
});

it('should not be active if the next branch is for a major', async () => {
expect(
await ConfigureNextAsMajorAction.isActive(
new ActiveReleaseTrains({
exceptionalMinor: null,
releaseCandidate: null,
next: new ReleaseTrain('master', parse('11.0.0-next.0')),
latest: new ReleaseTrain('10.0.x', parse('10.0.3')),
}),
),
).toBe(false);
it('should not be active if the next branch is already set to major', async () => {
const action = setupReleaseActionForTesting(
ConfigureNextAsMajorAction,
new ActiveReleaseTrains({
exceptionalMinor: null,
releaseCandidate: null,
next: new ReleaseTrain('master', parse('11.0.0-next.0')),
latest: new ReleaseTrain('10.0.x', parse('10.0.3')),
}),
);

expect(await ConfigureNextAsMajorAction.isActive(action.active, action.releaseConfig)).toBe(
false,
);
});

it('should compute proper version and create staging pull request', async () => {
Expand Down

0 comments on commit c37e8ac

Please sign in to comment.