Skip to content

Commit

Permalink
Merge pull request #2356 from intuit/from-latest
Browse files Browse the repository at this point in the history
Add --from latest option to release and changelog commands
  • Loading branch information
hipstersmoothie committed Apr 26, 2023
2 parents 726ed50 + b9aa3db commit 71e8439
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
11 changes: 6 additions & 5 deletions packages/cli/src/parse-args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
},
],
},
Expand All @@ -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",
Expand Down
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
Expand Up @@ -39,6 +39,7 @@ jest.mock("@octokit/rest", () => {

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

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

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

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


test("should use --to commit target", async () => {
const auto = new Auto({ ...defaults, plugins: [] });
auto.logger = dummyLog();
Expand All @@ -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",
Expand Down
8 changes: 6 additions & 2 deletions packages/core/src/auto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.`);
Expand Down

0 comments on commit 71e8439

Please sign in to comment.