diff --git a/mage_helpers/git.go b/mage_helpers/git.go index 7a8c27d5e922db10c6c5de7a80835c5a8fb752d9..b32230733393e23c72a06ab9ac1c8beedfd3dfd7 100644 --- a/mage_helpers/git.go +++ b/mage_helpers/git.go @@ -4,6 +4,7 @@ import ( "fmt" "os/exec" "strings" + "github.com/Masterminds/semver" ) func HasChanges(previousCommit string, folder string) bool { @@ -43,3 +44,55 @@ func CurrentCommit() string { } return string(output) } + +func CreateReleaseTag() { + + // Get version and increase version number + previousVersion, err := semver.NewVersion(GetLatestGitTag()) + if err != nil { + fmt.Println(err) + } + + newVersion := previousVersion.IncMinor() + + // Create git tag + newTagName := newVersion.Original() + commandArgs := []string{ + `tag`, + newTagName, + } + cmd := exec.Command("git", commandArgs...) + _, err = cmd.CombinedOutput() + if err != nil { + fmt.Println(err) + } + + // Push new tag + commandArgs = []string{ + `push`, + `origin`, + newTagName, + } + cmd = exec.Command("git", commandArgs...) + _, err = cmd.CombinedOutput() + if err != nil { + fmt.Println(err) + } + return +} + +func GetLatestGitTag() string { + commandArgs := []string{ + `describe`, + `--tags`, + } + cmd := exec.Command("git", commandArgs...) + output, err := cmd.CombinedOutput() + if err != nil { + fmt.Println(err) + } + tag := string(output) + tag = strings.TrimSuffix(tag, "\n") + + return tag +}