Skip to content

Commit

Permalink
fix: clean up tags if release fails
Browse files Browse the repository at this point in the history
  • Loading branch information
justinawrey committed Oct 10, 2022
1 parent 891d8c1 commit 58c7ca8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
8 changes: 8 additions & 0 deletions git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ export default {
return bash(`git push origin ${tag}`);
},

deleteLocalTag(tag: string): Promise<string> {
return bash(`git tag -d ${tag}`);
},

deleteRemoteTag(tag: string): Promise<string> {
return bash(`git push --delete origin ${tag}`);
},

async repoInfo(): Promise<{ repo: string; owner: string }> {
const { project: repo, owner } = parseRepo(
await bash("git remote get-url origin"),
Expand Down
13 changes: 12 additions & 1 deletion shipit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,17 @@ console.log("New remote tag created:", `${nextVer}\n`);

// Create Github release.
logHeader("Creating new Github release...");
const url = await github.release(nextVer, { major, minor, patch, docs });

let url: string;
try {
url = await github.release(nextVer, { major, minor, patch, docs });
} catch (error) {
// Something went wrong, so delete the local and remote tag and bail.
console.error(error);
await git.deleteLocalTag(nextVer);
await git.deleteRemoteTag(nextVer);
Deno.exit(0);
}

console.log("Successfully created new Github release! 🎉");
console.log("View it here:", url);

0 comments on commit 58c7ca8

Please sign in to comment.