Skip to content

Commit

Permalink
Build: Use current tag name as version in linker
Browse files Browse the repository at this point in the history
  • Loading branch information
qraimbault committed Aug 1, 2020
1 parent 3f46d54 commit e971753
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 12 deletions.
7 changes: 2 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
buildcerberus:
GO111MODULE=on go build -ldflags="-s -w -X github.com/forsam-education/cerberus/utils.VersionHash=`git rev-parse HEAD` -X github.com/forsam-education/cerberus/utils.BuildTime=`date +%Y-%m-%dT%T%z`" -o bin/cerberus

install: buildcerberus
sudo cp bin/cerberus /usr/local/bin
build: main.go
GO111MODULE=on go build -ldflags="-s -w -X github.com/forsam-education/cerberus/utils.VersionHash=`git rev-parse HEAD` -X github.com/forsam-education/cerberus/utils.BuildTime=`date +%Y-%m-%dT%T%z` -X github.com/forsam-education/cerberus/utils.VersionIdentifier=`git describe --tags`" -o bin/cerberus .
2 changes: 1 addition & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var versionCmd = &cobra.Command{
Shows the version for Cerberus.`, utils.ASCIILogo),
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("Cerberus version %d.%d.%d - %s (Build time: %s)\n", utils.MajorVersion, utils.MinorVersion, utils.PatchVersion, utils.VersionHash, utils.BuildTime)
fmt.Printf("Cerberus version %s - %s (Build time: %s)\n", utils.VersionIdentifier, utils.VersionHash, utils.BuildTime)
},
}

Expand Down
8 changes: 2 additions & 6 deletions utils/version.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
package utils

var (
// MajorVersion is the hardcoded major version of Cerberus.
MajorVersion = 0
// MinorVersion is the hardcoded minor version of Cerberus.
MinorVersion = 12
// PatchVersion is the hardcoded patch version of Cerberus.
PatchVersion = 1
// VersionIdentifier is the hardcoded version identifier of Cerberus.
VersionIdentifier = ""
// VersionHash is the commit hash for the built version injected by the linker.
VersionHash = ""
// BuildTime is the build time in RFC3309 format injected by the linker.
Expand Down

0 comments on commit e971753

Please sign in to comment.