From 697ce202347a0df53653c9f0ec4b076c3bba8858 Mon Sep 17 00:00:00 2001 From: Blallo Date: Wed, 29 Apr 2020 10:12:03 +0200 Subject: [PATCH] Add makefile and version automation --- .gitignore | 1 + Makefile | 34 ++++++++++++++++++++++++++++++++++ main.go | 9 +++++++-- 3 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 .gitignore create mode 100644 Makefile diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..354da5c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/output/* diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..bdf4e0d --- /dev/null +++ b/Makefile @@ -0,0 +1,34 @@ +VERS_MAJOR := 0 +VERS_MINOR := 2 +VERSION := $(VERS_MAJOR).$(VERS_MINOR) +NEW_MINOR := $$(( $(VERS_MINOR) + 1 )) +NEW_MAJOR := $$(( $(VERS_MAJOR) + 1 )) + +output: + +output/sendmail: output + go build -o output/sendmail -ldflags "-X main.version=$(VERSION)" ./... + +build: output/sendmail + +bumpvers-minor: + sed -i"" "s/VERS_MINOR := $(VERS_MINOR)/VERS_MINOR := $(NEW_MINOR)/" Makefile + git add Makefile + git commit -m "Bump version $(VERSION) -> $(VERS_MAJOR).$(NEW_MINOR)" + git tag $(VERS_MAJOR).$(NEW_MINOR) + +bumpvers-major: + sed -i"" "s/VERS_MAJOR := $(VERS_MAJOR)/VERS_MAJOR := $$(( $(VERS_MAJOR) + 1 ))/" Makefile + git add Makefile + git commit -m "Bump version $(VERSION) -> $(NEW_MAJOR).$(VERS_MINOR)" + git tag $(NEW_MAJOR).$(VERS_MINOR) + +release-min: + make bumpvers-minor + make build + +release-maj: + make bumpvers-major + make build + +PHONY: bumpvers-minor bumpvers-major release-min release-maj diff --git a/main.go b/main.go index bc81e70..b38a52b 100644 --- a/main.go +++ b/main.go @@ -8,7 +8,8 @@ import ( "strings" ) -var version = "0.1" +var noVersion = "dev" +var version string func readFromConsole() string { var text, line string @@ -90,7 +91,11 @@ func main() { LogInit(dbg) if versionFlag { - Info.F("Version: %s", version) + showVersion := noVersion + if version != "" { + showVersion = version + } + Info.F("Version: %s", showVersion) os.Exit(0) }