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 committed Feb 21, 2019
1 parent ee7cc1e commit a131f82
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
29 changes: 19 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
#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
DEP=dep
.PHONY : all install test

all : def
DEP=dep

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 *
rm -rf *
3 changes: 2 additions & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"fmt"
"github.com/spf13/cobra"
G "github.com/leopardslab/Dunner/pkg/global"
)

func init() {
Expand All @@ -14,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("v0.1")
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 a131f82

Please sign in to comment.