Skip to content

Commit

Permalink
Release Command: When creating a release for a tag that isn't on remo…
Browse files Browse the repository at this point in the history
…te, fallback to creating a tag pointing at the --to option
  • Loading branch information
hipstersmoothie committed Mar 29, 2021
1 parent 11778dd commit d052139
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
4 changes: 2 additions & 2 deletions packages/cli/src/parse-args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ export const commands: AutoCommand[] = [
description: endent`
Create a GitHub release for a tag. Defaults to last tag in branch.
> NOTE: The tag must already be pushed to GitHub. If it isn't GitHub will create a tag pointing to the HEAD of you default branch.
> NOTE: The tag must already be pushed to GitHub. If it isn't GitHub will create a tag pointing to the "to" option value.
`,
options: [
dryRun,
Expand All @@ -489,7 +489,7 @@ export const commands: AutoCommand[] = [
type: String,
group: "main",
description:
"Git revision (tag, commit sha, ...) to end release notes at. Defaults to HEAD",
"Git revision (tag, commit sha, ...) to end release notes at. Defaults to HEAD.",
},
{
name: "use-version",
Expand Down
15 changes: 10 additions & 5 deletions packages/core/src/__tests__/auto.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,8 @@ describe("Auto", () => {
expect(auto.git!.publish).toHaveBeenCalledWith(
"releaseNotes",
"v1.2.4",
false
false,
""
);
expect(afterRelease).toHaveBeenCalledWith(
expect.objectContaining({
Expand Down Expand Up @@ -1013,7 +1014,8 @@ describe("Auto", () => {
expect(auto.git!.publish).toHaveBeenCalledWith(
"releaseNotes",
"v1.2.4",
true
true,
""
);
expect(afterRelease).toHaveBeenCalledWith(
expect.objectContaining({
Expand Down Expand Up @@ -1052,7 +1054,8 @@ describe("Auto", () => {
expect(auto.git!.publish).toHaveBeenCalledWith(
"releaseNotes",
"v1.2.4",
false
false,
""
);
expect(afterRelease).toHaveBeenCalledWith(
expect.objectContaining({
Expand Down Expand Up @@ -1091,7 +1094,8 @@ describe("Auto", () => {
expect(auto.git!.publish).toHaveBeenCalledWith(
"releaseNotes",
"v1.3.0",
false
false,
""
);
expect(afterRelease).toHaveBeenCalledWith(
expect.objectContaining({
Expand Down Expand Up @@ -1130,7 +1134,8 @@ describe("Auto", () => {
expect(auto.git!.publish).toHaveBeenCalledWith(
"releaseNotes",
"v1.2.3+1",
false
false,
""
);
expect(afterRelease).toHaveBeenCalledWith(
expect.objectContaining({
Expand Down
7 changes: 6 additions & 1 deletion packages/core/src/auto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ export interface IAutoHooks {
DryRunOption & {
/** Commit to start calculating the version from */
from: string;
/** Commit to end calculating the version from */
to: string;
/** The version being released */
newVersion: string;
/** Whether the release being made is a prerelease */
Expand Down Expand Up @@ -551,7 +553,8 @@ export default class Auto {
const release = await this.git!.publish(
options.fullReleaseNotes,
options.newVersion,
options.isPrerelease
options.isPrerelease,
options.to
);

this.logger.log.info(release.data.html_url);
Expand Down Expand Up @@ -1472,6 +1475,7 @@ export default class Auto {
const release = await this.hooks.makeRelease.promise({
commits,
from: lastTag,
to: await this.git.getSha(),
isPrerelease: true,
newVersion,
fullReleaseNotes: releaseNotes,
Expand Down Expand Up @@ -1983,6 +1987,7 @@ export default class Auto {
const release = await this.hooks.makeRelease.promise({
dryRun,
from: lastRelease,
to: to || (await this.git.getSha()),
isPrerelease,
newVersion,
fullReleaseNotes: releaseNotes,
Expand Down
8 changes: 7 additions & 1 deletion packages/core/src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -845,13 +845,19 @@ export default class Git {
}

/** Create a release for the GitHub project */
async publish(releaseNotes: string, tag: string, prerelease = false) {
async publish(
releaseNotes: string,
tag: string,
prerelease = false,
fallbackCommit?: string,
) {
this.logger.verbose.info("Creating release on GitHub for tag:", tag);

const result = await this.github.repos.createRelease({
owner: this.options.owner,
repo: this.options.repo,
tag_name: tag,
target_commitish: fallbackCommit,
name: tag,
body: releaseNotes,
prerelease,
Expand Down

0 comments on commit d052139

Please sign in to comment.