forked from agneum/plan-exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
61 lines (44 loc) · 1.32 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
51
52
53
54
55
56
57
58
59
60
.DEFAULT_GOAL = all
BINARY = plan-exporter
GOARCH = amd64
GOOS = linux
VERSION?=0.0.1
BUILD_TIME?=$(shell date -u '+%Y%m%d-%H%M')
COMMIT?=$(shell git rev-parse HEAD)
BRANCH?=$(shell git rev-parse --abbrev-ref HEAD)
# Set up GOPATH if not defined
ifndef $(GOPATH)
GOPATH=$(shell go env GOPATH)
export GOPATH
endif
# Symlink into GOPATH
BUILD_DIR=${GOPATH}/${BINARY}
# Setup the -ldflags option for go build here, interpolate the variable values
LDFLAGS = -ldflags "-s -w \
-X main.version=${VERSION} \
-X main.commit=${COMMIT} \
-X main.branch=${BRANCH}\
-X main.buildTime=${BUILD_TIME}"
# Go tooling command aliases
GOBUILD = GO111MODULE=on CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} go build ${LDFLAGS}
GOTEST = GO111MODULE=on go test
GORUN = GO111MODULE=on go run ${LDFLAGS}
# Build the project
all: clean build
# Install the linter to $GOPATH/bin which is expected to be in $PATH
install-lint:
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b ${GOPATH}/bin v1.23.8
run-lint:
golangci-lint --config .golangci.yml run
lint: install-lint run-lint
build:
${GOBUILD} -o bin/${BINARY} ./main.go
clean:
-rm -f bin/*
run:
${GORUN} ./main.go
test:
${GOTEST} -v ./...
test-race:
${GOTEST} -v -race ./...
.PHONY: all clean build lint run-lint install-lint test test-race