diff --git a/Makefile b/Makefile index 65630f1..8804dcb 100644 --- a/Makefile +++ b/Makefile @@ -20,10 +20,15 @@ test: tidy fmt vet go test ./... -coverprofile=coverage.out go tool cover -func=coverage.out -release: - @version=$$(go run version/semver/main.go); \ +release: semver + @version=$$(semver); \ git tag -s $$version -m"Release $$version" goreleaser --rm-dist test-release: - goreleaser --skip-publish --snapshot --rm-dist \ No newline at end of file + goreleaser --skip-publish --snapshot --rm-dist + +semver: +ifeq (, $(shell which semver)) + $(shell go get -u github.com/bakito/semver) +endif \ No newline at end of file diff --git a/version/semver/main.go b/version/semver/main.go deleted file mode 100644 index ad45c5c..0000000 --- a/version/semver/main.go +++ /dev/null @@ -1,49 +0,0 @@ -package main - -import ( - "bufio" - "fmt" - "os" - "os/exec" - "strings" - - "github.com/coreos/go-semver/semver" -) - -func main() { - out, err := exec.Command("git", "branch", "--show-current").Output() - if err != nil { - panic(err) - } - branch := strings.TrimSpace(string(out)) - if branch != "main" { - panic(fmt.Errorf(`error: must be in "master" branch, current branch: %q`, branch)) - } - - out, err = exec.Command("git", "describe").Output() - if err != nil { - panic(err) - } - - version := strings.TrimPrefix(strings.TrimSpace(string(out)), "v") - v := semver.New(version) - v.BumpPatch() - reader := bufio.NewReader(os.Stdin) - if _, err = fmt.Fprintf(os.Stderr, "Enter Release Version: [v%v] ", v); err != nil { - panic(err) - } - - text, err := reader.ReadString('\n') - if err != nil { - panic(err) - } - if strings.HasPrefix(text, "v") { - text = text[1:] - v = semver.New(strings.TrimSpace(text)) - } - - if _, err = fmt.Fprintf(os.Stderr, "Using Version: v%v\n", v); err != nil { - panic(err) - } - fmt.Printf("v%v", v) -}