From abb72fabb168b9b7d49c8b5443551af53feb2278 Mon Sep 17 00:00:00 2001 From: Johan de Klerk <jdeklerk00@gmail.com> Date: Fri, 5 Nov 2021 15:43:31 +0200 Subject: [PATCH] Create release tag --- mage_helpers/git.go | 53 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/mage_helpers/git.go b/mage_helpers/git.go index 7a8c27d..b322307 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 +} -- GitLab