Skip to content

Commit

Permalink
[#22] Improve Makefile, Add better versions cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
agentmilindu authored and apoorvam committed May 15, 2019
1 parent be0fa74 commit c9a8727
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
22 changes: 17 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
#Go parameters
.PHONY: all install test build clean

SHA=$(shell git rev-list HEAD --max-count=1 --abbrev-commit)
TAG?=$(shell git tag -l --contains HEAD)
VERSION=$(TAG)

ifeq ($(VERSION),)
VERSION := latest
endif


#Go parameters
GOCMD=go
GOINSTALL=$(GOCMD) install
GOTEST=$(GOCMD) test
Expand All @@ -8,15 +18,17 @@ DEP=dep

all : def

def :
@$(GOINSTALL) -ldflags '-s'
all: build

install:
install:
@$(DEP) ensure

test:
test: install
@$(GOTEST) -v ./...

build: install
@$(GOINSTALL) -ldflags "-X main.version=$(VERSION)-$(SHA) -s"

clean:
rm -rf *

Expand Down
4 changes: 2 additions & 2 deletions cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package cmd

import (
"fmt"

"github.com/spf13/cobra"
G "github.com/leopardslab/Dunner/pkg/global"
)

func init() {
Expand All @@ -15,6 +15,6 @@ var versionCmd = &cobra.Command{
Short: "Print the version number of Dunner",
Long: `All software has versions. This is Dunners's`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("v1.0.0")
fmt.Println(G.VERSION)
},
}
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ package main

import (
"github.com/leopardslab/Dunner/cmd"
G "github.com/leopardslab/Dunner/pkg/global"
)

var version string = ""

func main() {
G.VERSION = version
cmd.Execute()
}
5 changes: 5 additions & 0 deletions pkg/global/global.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package global

var (
VERSION string
)

0 comments on commit c9a8727

Please sign in to comment.