Skip to content

Commit

Permalink
Fix the rollback mechanism for tags during a release (#392)
Browse files Browse the repository at this point in the history
* this fixes the rollback mechanism for tags during a release
* check for goreleaser before we do anything else
  • Loading branch information
natefinch committed Dec 14, 2021
1 parent 404c119 commit fd5011e
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions magefile.go
@@ -1,4 +1,5 @@
//+build mage
//go:build mage
// +build mage

// This is the build script for Mage. The install target is all you really need.
// The release target is for generating official releases and is really only
Expand All @@ -9,6 +10,7 @@ import (
"errors"
"fmt"
"os"
"os/exec"
"path/filepath"
"regexp"
"runtime"
Expand Down Expand Up @@ -69,6 +71,9 @@ var releaseTag = regexp.MustCompile(`^v1\.[0-9]+\.[0-9]+$`)

// Generates a new release. Expects a version tag in v1.x.x format.
func Release(tag string) (err error) {
if _, err := exec.LookPath("goreleaser"); err != nil {
return fmt.Errorf("can't find goreleaser: %w", err)
}
if !releaseTag.MatchString(tag) {
return errors.New("TAG environment variable must be in semver v1.x.x format, but was " + tag)
}
Expand All @@ -81,8 +86,8 @@ func Release(tag string) (err error) {
}
defer func() {
if err != nil {
sh.RunV("git", "tag", "--delete", "$TAG")
sh.RunV("git", "push", "--delete", "origin", "$TAG")
sh.RunV("git", "tag", "--delete", tag)
sh.RunV("git", "push", "--delete", "origin", tag)
}
}()
return sh.RunV("goreleaser")
Expand Down

0 comments on commit fd5011e

Please sign in to comment.