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

Add --from latest option to release and changelog commands #2356

Merged
merged 2 commits into from
Apr 26, 2023
Merged
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
11 changes: 6 additions & 5 deletions packages/cli/src/parse-args.ts
Original file line number Diff line number Diff line change
@@ -236,7 +236,7 @@ const useVersion: AutoOption = {
group: "main",
description:
"Version number to publish as. Defaults to reading from the package definition for the platform.",
}
};

interface AutoCommand extends Command {
/** Options for the command */
@@ -455,7 +455,7 @@ export const commands: AutoCommand[] = [
type: String,
group: "main",
description:
"Tag to start changelog generation on. Defaults to latest tag.",
"Tag to start changelog generation on. Defaults to latest tag or if a prerelease the latest tag in the branch. Provide latest to override.",
},
{
name: "to",
@@ -498,7 +498,7 @@ export const commands: AutoCommand[] = [
type: String,
group: "main",
description:
"Git revision (tag, commit sha, ...) to start release notes from. Defaults to latest tag.",
"Tag to start changelog generation on. Defaults to latest tag or if a prerelease the latest tag in the branch. Provide latest to override.",
},
{
name: "to",
@@ -518,7 +518,8 @@ export const commands: AutoCommand[] = [
},
{
desc: "Create a GitHub release using provided commit range and version",
example: "{green $} auto release --from v0.20.1 --to HEAD --use-version v0.21.0",
example:
"{green $} auto release --from v0.20.1 --to HEAD --use-version v0.21.0",
},
],
},
@@ -538,7 +539,7 @@ export const commands: AutoCommand[] = [
...latestCommandArgs,
{
...useVersion,
description: `${useVersion.description} Currently only supported for the **npm plugin**.`
description: `${useVersion.description} Currently only supported for the **npm plugin**.`,
},
{
name: "only-graduate-with-release-label",
1 change: 1 addition & 0 deletions packages/core/src/__tests__/auto-make-changelog.test.ts
Original file line number Diff line number Diff line change
@@ -39,6 +39,7 @@ jest.mock("@octokit/rest", () => {

repos = {
get: jest.fn().mockReturnValue(Promise.resolve({})),
getLatestRelease: jest.fn().mockReturnValue({ data: { tag_name: "" } }),
};

hook = {
4 changes: 2 additions & 2 deletions packages/core/src/__tests__/auto.test.ts
Original file line number Diff line number Diff line change
@@ -54,6 +54,7 @@ jest.mock("@octokit/rest", () => {

repos = {
get: jest.fn().mockReturnValue({}),
getLatestRelease: jest.fn().mockReturnValue({ data: { tag_name: "" } }),
};

hook = {
@@ -976,7 +977,6 @@ describe("Auto", () => {
);
});


test("should use --to commit target", async () => {
const auto = new Auto({ ...defaults, plugins: [] });
auto.logger = dummyLog();
@@ -995,7 +995,7 @@ describe("Auto", () => {
auto.hooks.afterRelease.tap("test", afterRelease);
jest.spyOn(auto.release!, "getCommits").mockImplementation();

await auto.runRelease({ to: 'abc'});
await auto.runRelease({ to: "abc" });

expect(auto.git!.publish).toHaveBeenCalledWith(
"releaseNotes",
8 changes: 6 additions & 2 deletions packages/core/src/auto.ts
Original file line number Diff line number Diff line change
@@ -1913,7 +1913,9 @@ export default class Auto {
);
}

const lastRelease = from || (await this.git.getLatestRelease());
const latestRelease = await this.git.getLatestRelease();
const lastRelease =
(from === "latest" && latestRelease) || from || latestRelease;
const bump = await this.release.getSemverBump(lastRelease, to);
const releaseNotes = await this.release.generateReleaseNotes(
lastRelease,
@@ -1995,11 +1997,13 @@ export default class Auto {
return process.exit(1);
}

const latestRelease = await this.git.getLatestRelease();
const isPrerelease = prerelease || this.inPrereleaseBranch();
let lastRelease =
(from === "latest" && latestRelease) ||
from ||
(isPrerelease && (await this.git.getPreviousTagInBranch())) ||
(await this.git.getLatestRelease());
latestRelease;

// Find base commit or latest release to generate the changelog to HEAD (new tag)
this.logger.veryVerbose.info(`Using ${lastRelease} as previous release.`);