This repository has been archived by the owner on Apr 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathMakefile
50 lines (39 loc) · 1.96 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
DOCKER ?= docker
CROSSBUILD_OS = linux windows darwin
CROSSBUILD_ARCH = 386 amd64
VERSION := $(shell git describe --tags --dirty=-dirty)
REVISION := $(shell git describe --abbrev=0 --always --match=always-commit-hash --dirty=-dirty)
BRANCH := $(or $(shell git symbolic-ref --short HEAD 2>/dev/null), "from-release-tag")
BUILDDATE := $(shell date --iso-8601=seconds)
BUILDUSER ?= $(USER)
BUILDHOST ?= $(HOSTNAME)
LDFLAGS = -X github.com/carlpett/stream_exporter/vendor/github.com/prometheus/common/version.Version=$(VERSION) \
-X github.com/carlpett/stream_exporter/vendor/github.com/prometheus/common/version.Revision=$(REVISION) \
-X github.com/carlpett/stream_exporter/vendor/github.com/prometheus/common/version.Branch=$(BRANCH) \
-X github.com/carlpett/stream_exporter/vendor/github.com/prometheus/common/version.BuildUser=$(BUILDUSER)@$(BUILDHOST) \
-X github.com/carlpett/stream_exporter/vendor/github.com/prometheus/common/version.BuildDate=$(BUILDDATE)
all: build test
test:
@echo ">> testing code"
@go test -v -cover ./...
build:
@echo ">> building binaries"
@go build -ldflags="$(LDFLAGS)"
crossbuild: $(GOPATH)/bin/gox
@echo ">> cross-building"
@gox -arch="$(CROSSBUILD_ARCH)" -os="$(CROSSBUILD_OS)" -ldflags="$(LDFLAGS)" -output="binaries/stream_exporter_{{.OS}}_{{.Arch}}"
release: bin/github-release
@echo ">> uploading release ${VERSION}"
@for bin in binaries/*; do \
./bin/github-release upload -t ${VERSION} -n $$(basename $${bin}) -f $${bin}; \
done
docker:
@echo ">> building docker image"
@$(DOCKER) build -t carlpett/stream_exporter .
$(GOPATH)/bin/gox:
# Need to disable modules for this to not pollute go.mod
@GO111MODULE=off go get -u github.com/mitchellh/gox
bin/github-release:
@mkdir -p bin
@curl -sL 'https://github.com/aktau/github-release/releases/download/v0.6.2/linux-amd64-github-release.tar.bz2' | tar xjf - --strip-components 3 -C bin
.PHONY: all build crossbuild test release