Skip to content

Commit

Permalink
Adjust build scripts to make --version vars compatible with goreleaser
Browse files Browse the repository at this point in the history
  • Loading branch information
kmoppel committed Jan 16, 2020
1 parent 5cc9e2f commit 6bcb765
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions pgwatch2/build_gatherer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ echo "running 'go build pgwatch2.go prom.go patroni.go logparse.go' ..."

if [ -n "$GIT_TIME" -a -n "$GIT_HASH" ] ; then

go build -ldflags "-X 'main.GitVersionHash=$GIT_HASH ($GIT_TIME)'" pgwatch2.go prom.go patroni.go logparse.go
go build -ldflags "-X main.commit=$GIT_HASH -X main.date='$GIT_TIME'" pgwatch2.go prom.go patroni.go logparse.go

elif [ -f build_git_version.txt ] ; then
# Dockerfile build fills the file with HEAD hash
go build -ldflags "-X 'main.GitVersionHash=`cat build_git_version.txt`'" pgwatch2.go prom.go patroni.go logparse.go
go build -ldflags "-X 'main.commit=`cat build_git_version.txt`'" pgwatch2.go prom.go patroni.go logparse.go
else

git_on_path=$(which git)
# assuming located in pgwatch2 Git repo ...
if [ -n "$git_on_path" -a -f pgwatch2.go ] ; then
go build -ldflags "-X 'main.GitVersionHash=`git show -s --format=\"%H (%ci)\" HEAD`'" pgwatch2.go prom.go patroni.go logparse.go
go build -ldflags "-X 'main.commit=`git show -s --format=\"%H\" HEAD`' -X 'main.date=`git show -s --format=\"%ci\" HEAD`'" pgwatch2.go prom.go patroni.go logparse.go
else
go build pgwatch2.go prom.go patroni.go logparse.go
fi
Expand Down
10 changes: 5 additions & 5 deletions pgwatch2/pgwatch2.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ import (
"gopkg.in/yaml.v2"
)

var GitVersionHash = "" // Will be set by "go build"!
var commit = "" // Git hash. Will be set on build time by build_gatherer.sh / goreleaser
var date = "" // Will be set on build time by build_gatherer.sh / goreleaser

type MonitoredDatabase struct {
DBUniqueName string `yaml:"unique_name"`
Expand All @@ -65,7 +66,6 @@ type MonitoredDatabase struct {
IsEnabled bool `yaml:"is_enabled"`
CustomTags map[string]string `yaml:"custom_tags"` // ignored on graphite
HostConfig HostConfigAttrs `yaml:"host_config"`
//JdbcConnStr string `yaml: "jdbc_conn_str"`
OnlyIfMaster bool `yaml:"only_if_master"`
}

Expand Down Expand Up @@ -3292,11 +3292,11 @@ func main() {
}

if opts.Version {
if GitVersionHash == "" {
fmt.Println("Git version not set! Use the 'build_gatherer.sh' script to build the binary or use 'go build -ldflags \"-X 'main.GitVersionHash=`git show -s --format=\"%H (%ci)\" HEAD`\"' ...")
if commit == "" {
fmt.Println("Git version not set! Use the 'build_gatherer.sh' script to build the binary or specify 'commit' and 'date' via -ldflags...")
os.Exit(1)
}
fmt.Println(GitVersionHash)
fmt.Println(fmt.Sprintf("%s (%s)", commit, date))
os.Exit(0)
}

Expand Down

0 comments on commit 6bcb765

Please sign in to comment.