Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

Commit

Permalink
Adds goreleaser
Browse files Browse the repository at this point in the history
  • Loading branch information
simonswine committed Jul 10, 2017
1 parent ead9123 commit 7ef286c
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,10 @@ builds:
- darwin
goarch:
- amd64
flags: -tags netgo
archive:
format: binary
release:
github:
owner: jetstack-experimental
name: vault-unsealer
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ BUILD_IMAGE_NAME := golang:1.8

GOPATH ?= /tmp/go

CI_COMMIT_TAG ?= unknown
CI_COMMIT_SHA ?= unknown

help:
# all - runs verify, build and docker_build targets
# test - runs go_test target
Expand Down Expand Up @@ -56,7 +59,7 @@ docker_push: docker_build
go_verify: go_fmt go_vet go_test

go_build:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -tags netgo -ldflags '-w' -o vault-unsealer_linux_amd64
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -tags netgo -ldflags '-w -X main.version=$(CI_COMMIT_TAG) -X main.commit=$(CI_COMMIT_SHA) -X main.date=$(shell date -u +%Y-%m-%d_%H:%M:%S)' -o vault-unsealer_linux_amd64

go_test:
go test $$(go list ./... | grep -v '/vendor/')
Expand Down
41 changes: 41 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package cmd

import (
"fmt"
"reflect"
"strings"

"github.com/spf13/cobra"
)

var Version struct {
Version string
BuildDate string
Commit string
}

var AppName string = "vault-unsealer"

func init() {
RootCmd.AddCommand(versionCmd)
}

var versionCmd = &cobra.Command{
Use: "version",
Short: fmt.Sprint("Print the version number of ", AppName),
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("%s", AppName)

v := reflect.ValueOf(Version)

for i := 0; i < v.NumField(); i++ {
fmt.Printf(
" %s: %s",
strings.ToLower(v.Type().Field(i).Name),
v.Field(i).Interface(),
)
}

fmt.Println("")
},
}
9 changes: 9 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@ import (
"github.com/jetstack-experimental/vault-unsealer/cmd"
)

var (
version string = "dev"
commit string = "unknown"
date string = "unknown"
)

func main() {
flag.Parse()
cmd.Version.Version = version
cmd.Version.Commit = commit
cmd.Version.BuildDate = date
cmd.Execute()
}

0 comments on commit 7ef286c

Please sign in to comment.