Skip to content

Commit

Permalink
enhance: setting version information (#240)
Browse files Browse the repository at this point in the history
* enhance(version): add fallback for empty tag

* enhance(version): use go version from runtime library

* chore: clean go code
  • Loading branch information
jbrockopp committed Nov 17, 2021
1 parent 0c2684d commit cd07f79
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
8 changes: 1 addition & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,8 @@ ifndef GITHUB_TAG
GITHUB_TAG = $(shell git describe --tag --abbrev=0)
endif

# check if a go version is already set
ifndef GOLANG_VERSION
# capture the current go version we build the application from
GOLANG_VERSION = $(shell go version | awk '{ print $$3 }')
endif

# create a list of linker flags for building the golang application
LD_FLAGS = -X github.com/go-vela/worker/version.Commit=${GITHUB_SHA} -X github.com/go-vela/worker/version.Date=${BUILD_DATE} -X github.com/go-vela/worker/version.Go=${GOLANG_VERSION} -X github.com/go-vela/worker/version.Tag=${GITHUB_TAG}
LD_FLAGS = -X github.com/go-vela/worker/version.Commit=${GITHUB_SHA} -X github.com/go-vela/worker/version.Date=${BUILD_DATE} -X github.com/go-vela/worker/version.Tag=${GITHUB_TAG}

# The `clean` target is intended to clean the workspace
# and prepare the local changes for submission.
Expand Down
12 changes: 10 additions & 2 deletions version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"runtime"

"github.com/Masterminds/semver/v3"

"github.com/go-vela/types/version"
"github.com/sirupsen/logrus"
)

var (
Expand All @@ -23,7 +23,7 @@ var (
// Date represents the build date information for the package.
Date string
// Go represents the golang version information for the package.
Go string
Go = runtime.Version()
// OS represents the operating system information for the package.
OS = runtime.GOOS
// Tag represents the git tag information for the package.
Expand All @@ -32,6 +32,14 @@ var (

// New creates a new version object for Vela that is used throughout the application.
func New() *version.Version {
// check if a semantic tag was provided
if len(Tag) == 0 {
logrus.Warningf("no semantic tag provided - defaulting to v0.0.0")

// set a fallback default for the tag
Tag = "v0.0.0"
}

v, err := semver.NewVersion(Tag)
if err != nil {
fmt.Println(fmt.Errorf("unable to parse semantic version for %s: %v", Tag, err))
Expand Down

0 comments on commit cd07f79

Please sign in to comment.