Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the rollback mechanism for tags during a release #392

Merged
merged 2 commits into from Dec 14, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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