Skip to content

Commit

Permalink
adds version via ldflags to circleci build
Browse files Browse the repository at this point in the history
  • Loading branch information
makii42 committed Nov 17, 2017
1 parent ce21f1b commit b17d5ea
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
6 changes: 5 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ jobs:
- run: go test -v $(go list ./...)
- run: go build .
- run: ./golcov --help
- run: gox -output="dist/{{.Dir}}_{{.OS}}_{{.Arch}}" --osarch="linux/386 linux/amd64 linux/arm darwin/386 darwin/amd64 windows/386 windows/adm64"
- run: |
gox \
-output="dist/{{.Dir}}_{{.OS}}_{{.Arch}}" \
-osarch="linux/386 linux/amd64 linux/arm darwin/386 darwin/amd64 windows/386 windows/adm64" \
-ldflags="-X main.version=$CIRCLE_TAG -X main.revision=$CIRCLE_SHA1"
- run: cd dist && sha256sum golcov* | tee sha256sums.txt
- persist_to_workspace:
root: ./dist
Expand Down
12 changes: 12 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"log"
"os"

Expand All @@ -17,6 +18,7 @@ func main() {
Usage: "Runs go test with default coverage options for each package and writes it to standard out",
Commands: []cli.Command{
testCmd,
versionCmd,
},
Before: setup,
Action: testAction,
Expand All @@ -33,6 +35,8 @@ func main() {
var (
osa osadapter.OS
goBinary string
version string = "dev"
revision string = "dev"
)

var testCmd = cli.Command{
Expand Down Expand Up @@ -74,3 +78,11 @@ func createTests(pkgs ...string) (tests []test.Test) {
}
return
}

var versionCmd = cli.Command{
Name: "version",
Usage: "displays the version",
Action: func(c *cli.Context) {
fmt.Printf("%s version: %s (%s)\n", c.App.Name, version, revision)
},
}

0 comments on commit b17d5ea

Please sign in to comment.