Skip to content

Commit

Permalink
Migrate to use govvv for builds
Browse files Browse the repository at this point in the history
  • Loading branch information
stack72 committed Apr 23, 2018
1 parent ea6255e commit 6345f09
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# Folders
_obj
_test
dist/

# Architecture specific extensions/prefixes
*.[568vq]
Expand Down
2 changes: 1 addition & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ builds:
# - Version (Tag with the `v` prefix stripped)
# The default is `-s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}}`
# Date format is `2006-01-02_15:04:05`
ldflags: -s -w -X main.Name={{ .ProjectName }} -X main.Version={{.Version}} -X main.GitCommit={{.Commit}}"
ldflags: -s -w -X main.Name={{ .ProjectName }} -X main.Version={{.Version}} -X main.GitCommit={{.Commit}} -X main.BuildDate={{.Date}} -X main.GitBranch={{.Tag}} -X main.GitState={{.Tag}} -X main.GitSummary={{.Commit}}"

archive:
# You can change the name of the archive.
Expand Down
6 changes: 3 additions & 3 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ default: check test build

tools: ## Install the tools used to test and build
@echo "==> Installing build tools"
go get github.com/mitchellh/gox
go get github.com/ahmetb/govvv
go get github.com/alecthomas/gometalinter
go get github.com/goreleaser/goreleaser
gometalinter --install

build: ## Build Levant for development purposes
@echo "==> Running $@..."
@go build -tags "$(BUILDTAGS) cgo" -o levant-local .
govvv build -o levant-local . -version local

test: ## Run the Levant test suite with coverage
@echo "==> Running $@..."
Expand All @@ -18,7 +18,7 @@ test: ## Run the Levant test suite with coverage

release: ## Trigger the release build script
@echo "==> Running $@..."
./scripts/build.sh
@goreleaser --rm-dist

.PHONY: check
check: ## Run the gometalinter suite
Expand Down
15 changes: 15 additions & 0 deletions buildtime/consts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package buildtime

var (
Version string
BuildDate string
GitCommit string
GitBranch string
GitState string
GitSummary string
)

const (
PROGNAME = "Levant"
)

6 changes: 6 additions & 0 deletions command/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"

"github.com/mitchellh/cli"
"github.com/jrasell/levant/buildtime"
)

// VersionCommand is a Command implementation that prints the version.
Expand Down Expand Up @@ -39,5 +40,10 @@ func (c *VersionCommand) Run(_ []string) int {
}

c.UI.Output(versionString.String())
c.UI.Output(fmt.Sprintf("Date: %s", buildtime.BuildDate))
c.UI.Output(fmt.Sprintf("Commit: %s", buildtime.GitCommit))
c.UI.Output(fmt.Sprintf("Branch: %s", buildtime.GitBranch))
c.UI.Output(fmt.Sprintf("State: %s", buildtime.GitState))
c.UI.Output(fmt.Sprintf("Summary: %s", buildtime.GitSummary))
return 0
}
21 changes: 21 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,21 @@ import (
"os"

"github.com/mitchellh/cli"
"github.com/jrasell/levant/buildtime"
)

var (
// variables populated by govvv(1)
Version = "dev"
BuildDate string
GitCommit string
GitBranch string
GitState string
GitSummary string
)

func main() {
exportBuildtimeConsts()
os.Exit(Run(os.Args[1:]))
}

Expand Down Expand Up @@ -54,3 +66,12 @@ func RunCustom(args []string, commands map[string]cli.CommandFactory) int {

return exitCode
}

func exportBuildtimeConsts() {
buildtime.GitCommit = GitCommit
buildtime.GitBranch = GitBranch
buildtime.GitState = GitState
buildtime.GitSummary = GitSummary
buildtime.BuildDate = BuildDate
buildtime.Version = Version
}

0 comments on commit 6345f09

Please sign in to comment.