Skip to content

Commit

Permalink
Include commit on version and update build scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
calvn committed Jun 24, 2016
1 parent bd35e04 commit 3f9919e
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 7 deletions.
25 changes: 22 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
TEST?=$(shell go list ./... | grep -v /vendor/)

.PHONY: build test
# Get git commit information
GIT_COMMIT=$(shell git rev-parse HEAD)
GIT_DIRTY=$(shell test -n "`git status --porcelain`" && echo "+CHANGES" || true)

default: test

Expand All @@ -9,17 +11,34 @@ test: generate
@go list $(TEST) \
| grep -v "/vendor/" \
| xargs -n1 go test -v -timeout=60s $(TESTARGS)
.PHONY: test

generate:
@echo " ==> Generating..."
@find . -type f -name '.DS_Store' -delete
@go list ./... \
| grep -v "/vendor/" \
| xargs -n1 go generate $(PACKAGES)
.PHONY: generate

create_docker_image:

build: generate
@echo " ==> Building..."
@go build -ldflags "-X main.GitCommit=${GIT_COMMIT}${GIT_DIRTY}" .
.PHONY: build

build-linux: create-build-image remove-dangling build-native
.PHONY: build-linux

create-build-image:
@docker build -t cimpress/git2consul-builder $(CURDIR)/build/
.PHONY: create-build-image

remove-dangling:
@docker images --quiet --filter dangling=true | grep . | xargs docker rmi
.PHONY: remove-dangling

build:
run-build-image:
@echo " ===> Building..."
@docker run --rm --name git2consul-builder -v $(CURDIR):/app -v $(CURDIR)/build/bin:/build/bin cimpress/git2consul-builder
.PHONY: run-build-image
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ The path to the configuration file. This flag is *required*.
### `-once`
Runs git2consul once and exits. This essentially ignores webhook polling.

### `-v`
### `-version`
Displays the version of git2consul and exits. All other commands are ignored.

## Webhooks
Expand Down
3 changes: 2 additions & 1 deletion build/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ export PKG_CONFIG_PATH="/usr/lib/pkgconfig/:/usr/local/lib/pkgconfig/"
# Build git2consul
cd ${BUILDPATH}
go get -v
go build -o /build/bin/git2consul.linux.amd64 .
GOOS=linux GOARCH=amd64 go build -o /build/bin/git2consul.linux.amd64 .
# GOOS=darwin GOARCH=amd64 CGO_ENABLED=1 go build -o /build/bin/git2consul.darwin.amd64 .
2 changes: 1 addition & 1 deletion build/install-libgit2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ git clone -b ${LIBGIT2BRANCH} --depth 1 -- ${LIBGIT2REPO} ${LIBGIT2PATH}

mkdir -p ${LIBGIT2PATH}/build
cd ${LIBGIT2PATH}/build
cmake .. -DBUILD_CLAR=off
cmake -DBUILD_CLAR=OFF ..
cmake --build . --target install

# Cleanup
Expand Down
6 changes: 5 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ func main() {
}

if version {
fmt.Println(Version)
fmt.Println("git2consul:")
fmt.Printf(" %-9s%s\n", "Version:", Version)
if GitCommit != "" {
fmt.Printf(" %-9s%s\n", "Build:", GitCommit)
}
return
}

Expand Down
5 changes: 5 additions & 0 deletions version.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
package main

// The git commit that will be used to describe the version
var (
GitCommit string
)

// Version of the program
const Version = "0.0.1"

0 comments on commit 3f9919e

Please sign in to comment.