Skip to content

Commit 915b105

Browse files
Merge pull request #1929 from intuit/release-flag
Release Command: Tag creation fallback.
2 parents 6505c79 + cca314f commit 915b105

File tree

4 files changed

+64
-10
lines changed

4 files changed

+64
-10
lines changed

packages/cli/src/parse-args.ts

+12-3
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,11 @@ export const commands: AutoCommand[] = [
467467
{
468468
name: "release",
469469
group: "Release Commands",
470-
description: "Auto-generate a github release",
470+
description: endent`
471+
Create a GitHub release for a tag. Defaults to last tag in branch.
472+
473+
> NOTE: The tag must already be pushed to GitHub. If it isn't GitHub will create a tag pointing to the "to" option value.
474+
`,
471475
options: [
472476
dryRun,
473477
noVersionPrefix,
@@ -485,7 +489,7 @@ export const commands: AutoCommand[] = [
485489
type: String,
486490
group: "main",
487491
description:
488-
"Git revision (tag, commit sha, ...) to end release notes at. Defaults to HEAD",
492+
"Git revision (tag, commit sha, ...) to end release notes at. Defaults to HEAD.",
489493
},
490494
{
491495
name: "use-version",
@@ -499,7 +503,12 @@ export const commands: AutoCommand[] = [
499503
],
500504
examples: [
501505
"{green $} auto release",
502-
"{green $} auto release --from v0.20.1 --use-version v0.21.0",
506+
{
507+
desc:
508+
"This command can be used in isolation easily. This example will: tag the release version at 'to' and create a GitHub release changelog over the commits range",
509+
example:
510+
"{green $} auto release --from v0.20.1 --to HEAD --use-version v0.21.0",
511+
},
503512
],
504513
},
505514
{

packages/core/src/__tests__/auto.test.ts

+39-5
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,8 @@ describe("Auto", () => {
948948
expect(auto.git!.publish).toHaveBeenCalledWith(
949949
"releaseNotes",
950950
"v1.2.4",
951-
false
951+
false,
952+
""
952953
);
953954
expect(afterRelease).toHaveBeenCalledWith(
954955
expect.objectContaining({
@@ -958,6 +959,35 @@ describe("Auto", () => {
958959
);
959960
});
960961

962+
963+
test("should use --to commit target", async () => {
964+
const auto = new Auto({ ...defaults, plugins: [] });
965+
auto.logger = dummyLog();
966+
await auto.loadConfig();
967+
auto.git!.getLatestRelease = () => Promise.resolve("1.2.3");
968+
969+
jest.spyOn(auto.git!, "publish").mockReturnValueOnce({ data: {} } as any);
970+
jest
971+
.spyOn(auto.release!, "generateReleaseNotes")
972+
.mockImplementation(() => Promise.resolve("releaseNotes"));
973+
auto.release!.getCommitsInRelease = () =>
974+
Promise.resolve([makeCommitFromMsg("Test Commit")]);
975+
976+
auto.hooks.getPreviousVersion.tap("test", () => "1.2.4");
977+
const afterRelease = jest.fn();
978+
auto.hooks.afterRelease.tap("test", afterRelease);
979+
jest.spyOn(auto.release!, "getCommits").mockImplementation();
980+
981+
await auto.runRelease({ to: 'abc'});
982+
983+
expect(auto.git!.publish).toHaveBeenCalledWith(
984+
"releaseNotes",
985+
"v1.2.4",
986+
false,
987+
"abc"
988+
);
989+
});
990+
961991
test("should publish to a tag", async () => {
962992
const auto = new Auto({ ...defaults, plugins: [] });
963993
auto.logger = dummyLog();
@@ -1013,7 +1043,8 @@ describe("Auto", () => {
10131043
expect(auto.git!.publish).toHaveBeenCalledWith(
10141044
"releaseNotes",
10151045
"v1.2.4",
1016-
true
1046+
true,
1047+
""
10171048
);
10181049
expect(afterRelease).toHaveBeenCalledWith(
10191050
expect.objectContaining({
@@ -1052,7 +1083,8 @@ describe("Auto", () => {
10521083
expect(auto.git!.publish).toHaveBeenCalledWith(
10531084
"releaseNotes",
10541085
"v1.2.4",
1055-
false
1086+
false,
1087+
""
10561088
);
10571089
expect(afterRelease).toHaveBeenCalledWith(
10581090
expect.objectContaining({
@@ -1091,7 +1123,8 @@ describe("Auto", () => {
10911123
expect(auto.git!.publish).toHaveBeenCalledWith(
10921124
"releaseNotes",
10931125
"v1.3.0",
1094-
false
1126+
false,
1127+
""
10951128
);
10961129
expect(afterRelease).toHaveBeenCalledWith(
10971130
expect.objectContaining({
@@ -1130,7 +1163,8 @@ describe("Auto", () => {
11301163
expect(auto.git!.publish).toHaveBeenCalledWith(
11311164
"releaseNotes",
11321165
"v1.2.3+1",
1133-
false
1166+
false,
1167+
""
11341168
);
11351169
expect(afterRelease).toHaveBeenCalledWith(
11361170
expect.objectContaining({

packages/core/src/auto.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ export interface IAutoHooks {
193193
DryRunOption & {
194194
/** Commit to start calculating the version from */
195195
from: string;
196+
/** Commit to end calculating the version from */
197+
to: string;
196198
/** The version being released */
197199
newVersion: string;
198200
/** Whether the release being made is a prerelease */
@@ -551,7 +553,8 @@ export default class Auto {
551553
const release = await this.git!.publish(
552554
options.fullReleaseNotes,
553555
options.newVersion,
554-
options.isPrerelease
556+
options.isPrerelease,
557+
options.to
555558
);
556559

557560
this.logger.log.info(release.data.html_url);
@@ -1472,6 +1475,7 @@ export default class Auto {
14721475
const release = await this.hooks.makeRelease.promise({
14731476
commits,
14741477
from: lastTag,
1478+
to: await this.git.getSha(),
14751479
isPrerelease: true,
14761480
newVersion,
14771481
fullReleaseNotes: releaseNotes,
@@ -1983,6 +1987,7 @@ export default class Auto {
19831987
const release = await this.hooks.makeRelease.promise({
19841988
dryRun,
19851989
from: lastRelease,
1990+
to: to || (await this.git.getSha()),
19861991
isPrerelease,
19871992
newVersion,
19881993
fullReleaseNotes: releaseNotes,

packages/core/src/git.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -845,13 +845,19 @@ export default class Git {
845845
}
846846

847847
/** Create a release for the GitHub project */
848-
async publish(releaseNotes: string, tag: string, prerelease = false) {
848+
async publish(
849+
releaseNotes: string,
850+
tag: string,
851+
prerelease = false,
852+
fallbackCommit?: string,
853+
) {
849854
this.logger.verbose.info("Creating release on GitHub for tag:", tag);
850855

851856
const result = await this.github.repos.createRelease({
852857
owner: this.options.owner,
853858
repo: this.options.repo,
854859
tag_name: tag,
860+
target_commitish: fallbackCommit,
855861
name: tag,
856862
body: releaseNotes,
857863
prerelease,

0 commit comments

Comments
 (0)