Develop #134
18
Makefile
18
Makefile
@@ -11,7 +11,6 @@ MAKEFLAGS += --no-builtin-rules
|
|||||||
CUR_SHA=$(shell git log -n1 --pretty='%h')
|
CUR_SHA=$(shell git log -n1 --pretty='%h')
|
||||||
CUR_BRANCH=$(shell git branch --show-current)
|
CUR_BRANCH=$(shell git branch --show-current)
|
||||||
VERSION=$(shell git describe --exact-match --tags $(CUR_SHA) 2>/dev/null || echo $(CUR_BRANCH)-$(CUR_SHA))# use by golang flags
|
VERSION=$(shell git describe --exact-match --tags $(CUR_SHA) 2>/dev/null || echo $(CUR_BRANCH)-$(CUR_SHA))# use by golang flags
|
||||||
PKG_VERSION=$(VERSION)# used for package name
|
|
||||||
|
|
||||||
# Go build command and environment variables for target OS and architecture
|
# Go build command and environment variables for target OS and architecture
|
||||||
GOVERSION=1.24
|
GOVERSION=1.24
|
||||||
@@ -21,7 +20,6 @@ GOOS=linux
|
|||||||
GOARCH=amd64
|
GOARCH=amd64
|
||||||
CGO_ENABLED=0
|
CGO_ENABLED=0
|
||||||
PREFIX=~/.local
|
PREFIX=~/.local
|
||||||
BLD_CMD=go build -ldflags="-X 'katenary/generator.Version=$(VERSION)'" -o $(OUTPUT) ./cmd/katenary
|
|
||||||
|
|
||||||
# Get the container (podman is preferred, but docker is also supported)
|
# Get the container (podman is preferred, but docker is also supported)
|
||||||
# TODO: prpose nerdctl
|
# TODO: prpose nerdctl
|
||||||
@@ -38,13 +36,16 @@ PKG_OCI_OPTS:=--rm -it \
|
|||||||
|
|
||||||
# Set the version and package version, following build mode (default, release)
|
# Set the version and package version, following build mode (default, release)
|
||||||
MODE=default
|
MODE=default
|
||||||
RELEASE=""
|
|
||||||
# If release mode
|
# If release mode
|
||||||
ifeq ($(MODE),release)
|
ifeq ($(MODE),release)
|
||||||
PKG_VERSION=v$(VERSION)
|
PKG_VERSION:=$(VERSION)
|
||||||
VERSION:=release-$(VERSION)
|
VERSION:=$(VERSION)
|
||||||
|
else
|
||||||
|
PKG_VERSION=$(VERSION)# used for package name
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
BLD_CMD=go build -ldflags="-X 'katenary/generator.Version=$(VERSION)'" -o $(OUTPUT) ./cmd/katenary
|
||||||
|
|
||||||
|
|
||||||
# UPX compression
|
# UPX compression
|
||||||
UPX_OPTS =
|
UPX_OPTS =
|
||||||
@@ -67,6 +68,13 @@ SIGNER=metal3d@gmail.com
|
|||||||
# Browser command to see coverage report after tests
|
# Browser command to see coverage report after tests
|
||||||
BROWSER=$(shell command -v epiphany || echo xdg-open)
|
BROWSER=$(shell command -v epiphany || echo xdg-open)
|
||||||
|
|
||||||
|
check-version:
|
||||||
|
@echo "=> Checking version..."
|
||||||
|
@echo "Mode: $(MODE)"
|
||||||
|
@echo "Current version: $(VERSION)"
|
||||||
|
@echo "Package version: $(PKG_VERSION)"
|
||||||
|
@echo "Build command: $(BLD_CMD)"
|
||||||
|
|
||||||
all: build
|
all: build
|
||||||
|
|
||||||
help:
|
help:
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
package generator
|
package generator
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"regexp"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Version is the version of katenary. It is set at compile time.
|
// Version is the version of katenary. It is set at compile time.
|
||||||
@@ -12,13 +12,19 @@ var Version = "master" // changed at compile time
|
|||||||
// the version is set at compile time for the github release. But, it the user get
|
// the version is set at compile time for the github release. But, it the user get
|
||||||
// katneary using `go install`, the version should be different.
|
// katneary using `go install`, the version should be different.
|
||||||
func GetVersion() string {
|
func GetVersion() string {
|
||||||
if strings.HasPrefix(Version, "release-") {
|
// try to get the semantic version from the Version variable (theorically set at compile time)
|
||||||
|
reg := regexp.MustCompile(`^(.?\d+.\d+.\d+.*)|^release-.*`)
|
||||||
|
if reg.MatchString(Version) {
|
||||||
return Version
|
return Version
|
||||||
}
|
}
|
||||||
// get the version from the build info
|
|
||||||
|
// OK... let's try to get the version from the build info
|
||||||
|
// get the version from the build info (when installed with go install)
|
||||||
v, ok := debug.ReadBuildInfo()
|
v, ok := debug.ReadBuildInfo()
|
||||||
if ok {
|
if ok {
|
||||||
return v.Main.Version + "-" + v.GoVersion
|
return v.Main.Version + "-" + v.GoVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// OK... none worked, so we return the default version
|
||||||
return Version
|
return Version
|
||||||
}
|
}
|
||||||
|
@@ -8,11 +8,24 @@ import (
|
|||||||
func TestVersion(t *testing.T) {
|
func TestVersion(t *testing.T) {
|
||||||
// we build on "devel" branch
|
// we build on "devel" branch
|
||||||
v := GetVersion()
|
v := GetVersion()
|
||||||
|
// by default, the version comes from build info and it's a development version
|
||||||
if !strings.Contains(v, "(devel)") {
|
if !strings.Contains(v, "(devel)") {
|
||||||
t.Errorf("Expected version to be set, got %s", v)
|
t.Errorf("Expected version to be set, got %s", v)
|
||||||
}
|
}
|
||||||
|
|
||||||
// now, imagine we are on a release branch
|
// now, imagine we are on a release branch
|
||||||
|
Version = "1.0.0"
|
||||||
|
v = GetVersion()
|
||||||
|
if !strings.Contains(v, "1.0.0") {
|
||||||
|
t.Errorf("Expected version to be set, got %s", v)
|
||||||
|
}
|
||||||
|
// now, imagine we are on v1.0.0
|
||||||
|
Version = "v1.0.0"
|
||||||
|
v = GetVersion()
|
||||||
|
if !strings.Contains(v, "v1.0.0") {
|
||||||
|
t.Errorf("Expected version to be set, got %s", v)
|
||||||
|
}
|
||||||
|
// we can also compile a release branch
|
||||||
Version = "release-1.0.0"
|
Version = "release-1.0.0"
|
||||||
v = GetVersion()
|
v = GetVersion()
|
||||||
if !strings.Contains(v, "release-1.0.0") {
|
if !strings.Contains(v, "release-1.0.0") {
|
||||||
|
Reference in New Issue
Block a user