Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update: Major version changelogs include all prereleases #37

Merged
merged 2 commits into from
May 8, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
33 changes: 30 additions & 3 deletions lib/release-ops.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,33 @@ function calculateReleaseFromGitLogs(currentVersion, logs, prereleaseId) {
return releaseInfo;
}

/**
* Gets the range of commits to include in a changelog.
* If this will be the first stable release following a prerelease sequence,
* all commits going back to the previous stable release are included.
* @param {string[]} tags All prior version tags.
* @param {string} [prereleaseId] The prerelease identifier if this is a prerelease.
* @returns {string} The commit range to include in the changelog.
* @private
*/
function getChangelogCommitRange(tags, prereleaseId) {
let lastTag = null;

// If this will be a stable release after a prerelease...
if (!prereleaseId && semver.prerelease(tags[tags.length - 1])) {
let i = 2;

do {
lastTag = tags[tags.length - i];
i++;
} while (semver.prerelease(lastTag));
} else {
lastTag = tags[tags.length - 1];
}

return lastTag ? `${lastTag}..HEAD` : "";
}

/**
* Gets all changes since the last tag that represents a version.
* @param {string} [prereleaseId] The prerelease identifier if this is a prerelease.
Expand All @@ -257,11 +284,10 @@ function calculateReleaseFromGitLogs(currentVersion, logs, prereleaseId) {
*/
function calculateReleaseInfo(prereleaseId) {

// get most recent tag
// get last version tag
const pkg = getPackageInfo(),
tags = getVersionTags(),
lastTag = tags[tags.length - 1],
commitRange = lastTag ? `${lastTag}..HEAD` : "";
commitRange = getChangelogCommitRange(tags, prereleaseId);

// get log statements
const logs = ShellOps.execSilent(`git log --no-merges --pretty=format:"* %H %s (%an)%n%b" ${commitRange}`).split(/\n/g);
Expand Down Expand Up @@ -427,6 +453,7 @@ module.exports = {
generateRelease,
publishRelease,
calculateReleaseInfo,
getChangelogCommitRange,
calculateReleaseFromGitLogs,
writeChangelog
};
62 changes: 62 additions & 0 deletions tests/lib/release-ops.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,38 @@ describe("ReleaseOps", () => {

});

describe("getChangelogCommitRange", () => {

it("returns an empty string when there are no prior releases", () => {
const tags = [];
const range = ReleaseOps.getChangelogCommitRange(tags);

assert.strictEqual(range, "");
});

it("finds the most recent tag for normal releases", () => {
const tags = ["1.0.0", "1.0.1"];
const range = ReleaseOps.getChangelogCommitRange(tags);

assert.strictEqual(range, "1.0.1..HEAD");
});

it("finds the most recent tag for prereleases", () => {
const tags = ["1.0.0", "1.0.1", "2.0.0-alpha.0", "2.0.0-alpha.1"];
const range = ReleaseOps.getChangelogCommitRange(tags, "beta");

assert.strictEqual(range, "2.0.0-alpha.1..HEAD");
});

it("finds the last stable tag for a new stable following prereleases", () => {
const tags = ["1.0.0", "1.0.1", "2.0.0-alpha.0", "2.0.0-rc.0"];
const range = ReleaseOps.getChangelogCommitRange(tags);

assert.strictEqual(range, "1.0.1..HEAD");
});

});

describe("calculateReleaseFromGitLogs()", () => {

it("should create a patch release when only bug fixes are present", () => {
Expand Down Expand Up @@ -252,6 +284,36 @@ describe("ReleaseOps", () => {
});
});

it("should create the next stable release following a prerelease", () => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, assuming our last prerelease before a stable major release was a release candidate, the stable release's changelog would've only included changes since the release candidate. At that phase of the release, breaking changes are discouraged. Now that we're including breaking changes in the stable release's changelog, I added this test to verify that the version bump won't mistakenly go from 7.0.0-rc.0 to 8.0.0 when it sees a Breaking: commit in the changelog for a release following a release candidate.

const logs = [
"* 7e8a43b2b6350e13a61858f33b4099c964cdd758 Breaking: Remove API (githubhandle)",
"* 0c07d6ac037076557e34d569cd0290e529b3318a Docs: Something else (Committer Name)",
"* 196d32dbfb7cb37b886e7c4ba0adff499c6b26ac Fix: Something else (Abc D. Efg)"
],
releaseInfo = ReleaseOps.calculateReleaseFromGitLogs("2.0.0-rc.0", logs);

assert.deepStrictEqual(releaseInfo, {
version: "2.0.0",
type: "major",
changelog: {
fix: [
"* [`196d32d`](https://github.com/eslint/eslint-release/commit/196d32dbfb7cb37b886e7c4ba0adff499c6b26ac) Fix: Something else (Abc D. Efg)"
],
docs: [
"* [`0c07d6a`](https://github.com/eslint/eslint-release/commit/0c07d6ac037076557e34d569cd0290e529b3318a) Docs: Something else (Committer Name)"
],
breaking: [
"* [`7e8a43b`](https://github.com/eslint/eslint-release/commit/7e8a43b2b6350e13a61858f33b4099c964cdd758) Breaking: Remove API (githubhandle)"
]
},
rawChangelog: [
"* [`7e8a43b`](https://github.com/eslint/eslint-release/commit/7e8a43b2b6350e13a61858f33b4099c964cdd758) Breaking: Remove API (githubhandle)",
"* [`0c07d6a`](https://github.com/eslint/eslint-release/commit/0c07d6ac037076557e34d569cd0290e529b3318a) Docs: Something else (Committer Name)",
"* [`196d32d`](https://github.com/eslint/eslint-release/commit/196d32dbfb7cb37b886e7c4ba0adff499c6b26ac) Fix: Something else (Abc D. Efg)"
].join("\n")
});
});

it("should gracefully handle unformatted commit messages", () => {
const logs = [
"* 70222e95932d3a391ac5717252e13b478d686ba9 0.4.0-alpha.4 (Nicholas C. Zakas)",
Expand Down