Skip to content

Commit

Permalink
feat(ng-dev): remove prerelease changelog entries when cutting a stab…
Browse files Browse the repository at this point in the history
…le release (#260)

When cutting a stable release, the changelog entries for the prerelease entries are removed as stable release
note entries contain the entirety from the previous stable release and the newly created stable release.

PR Close #260
  • Loading branch information
josephperrott committed Oct 13, 2021
1 parent 387b9d2 commit 8cec60f
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 2 deletions.
7 changes: 6 additions & 1 deletion ng-dev/release/notes/release-notes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,14 @@ export class ReleaseNotes {

/**
* Prepend generated release note to the CHANGELOG.md file in the base directory of the repository
* provided by the GitClient.
* provided by the GitClient. Removes entries for related prerelease entries as appropriate.
*/
async prependEntryToChangelogFile() {
// When the version for the entry is a non-prelease (i.e. 1.0.0 rather than 1.0.0-next.1), the
// pre-release entries for the version should be removed from the changelog.
if (semver.prerelease(this.version) === null) {
Changelog.removePrereleaseEntriesForVersion(this.git, this.version);
}
Changelog.prependEntryToChangelogFile(this.git, await this.getChangelogEntry());

// TODO(josephperrott): Remove file formatting calls.
Expand Down
73 changes: 73 additions & 0 deletions ng-dev/release/publish/test/cut-stable.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
import {testTmpDir} from '../../../utils/testing';
import {SandboxGitRepo} from '../../../utils/testing';
import {ActiveReleaseTrains} from '../../versioning';
import {ReleaseNotes} from '../../notes/release-notes';

describe('cut stable action', () => {
it('should not activate if a feature-freeze release-train is active', async () => {
Expand Down Expand Up @@ -181,4 +182,76 @@ describe('cut stable action', () => {
`);
},
);

it(
'removes prerelease changelog entries for the new stable release when creating the stable ' +
'release changelog entry',
async () => {
const action = setupReleaseActionForTesting(
CutStableAction,
new ActiveReleaseTrains({
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.3')),
}),
true,
{useSandboxGitClient: true},
);

SandboxGitRepo.withInitialCommit(action.githubConfig)
.commit('fix(pkg1): landed in all release trains *1')
.branchOff('10.0.x')
.commit('fix(pkg1): released in patch, cherry-picked *1', 1)
.commit('fix(pkg1): released in patch, cherry-picked *2', 2)
.createTagForHead('10.0.3')
.commit('fix(pkg1): landed in patch, not released but cherry-picked *1', 3)
.switchToBranch('master')
.cherryPick(1)
.cherryPick(2)
.cherryPick(3)
.commit('fix(pkg1): released first next pre-release *1')
.commit('fix(pkg1): released first next pre-release *2')
.createTagForHead('10.1.0-next.0')
.commit('fix(pkg1): released feature-freeze pre-release *1')
.commit('fix(pkg1): released feature-freeze pre-release *2')
.branchOff('10.1.x')
.createTagForHead('10.1.0-next.1')
.commit('fix(pkg1): released release-candidate *1')
.commit('fix(pkg1): released release-candidate *2')
.createTagForHead('10.1.0-rc.0')
.commit('fix(pkg1): not yet released *1')
.commit('fix(pkg1): not yet released *2');

const entriesBeforeStableReleaseAction: [startingRef: string, endingRef: string][] = [
['10.0.3~2', '10.0.3'],
['10.0.3', '10.1.0-next.0'],
['10.1.0-next.0', '10.1.0-next.1'],
['10.1.0-next.1', '10.1.0-rc.0'],
];
for (const [start, end] of entriesBeforeStableReleaseAction) {
const releaseNotes = await ReleaseNotes.forRange(action.gitClient, parse(end), start, end);
await releaseNotes.prependEntryToChangelogFile();
}

// Assert the existence of the expected versions in the changelog.
const changelogBeforeAction = readFileSync(`${testTmpDir}/CHANGELOG.md`, 'utf8');
expect(changelogBeforeAction).toContain('<a name="10.0.3"></a>');
expect(changelogBeforeAction).toContain('<a name="10.1.0-next.0"></a>');
expect(changelogBeforeAction).toContain('<a name="10.1.0-next.1"></a>');
expect(changelogBeforeAction).toContain('<a name="10.1.0-rc.0"></a>');
expect(changelogBeforeAction).not.toContain('<a name="10.1.0"></a>');

await expectGithubApiRequestsForStaging(action, '10.1.x', '10.1.0', true);
await action.instance.perform();

// Assert the removal of changelog entries for the prerelease versions expected to be removed
// and now has the new stable entry.
const changelogAfterAction = readFileSync(`${testTmpDir}/CHANGELOG.md`, 'utf8');
expect(changelogAfterAction).not.toContain('<a name="10.0.3"></a>');
expect(changelogAfterAction).not.toContain('<a name="10.1.0-next.0"></a>');
expect(changelogAfterAction).not.toContain('<a name="10.1.0-next.1"></a>');
expect(changelogAfterAction).not.toContain('<a name="10.1.0-rc.0"></a>');
expect(changelogAfterAction).toContain('<a name="10.1.0"></a>');
},
);
});
16 changes: 15 additions & 1 deletion tools/local-actions/changelog/main.js

Large diffs are not rendered by default.

0 comments on commit 8cec60f

Please sign in to comment.