-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
55 lines (46 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
NAME=snoo
VERSION=0.1.0
COMMIT=$(shell git rev-parse --short=7 HEAD)
TIMESTAMP:=$(shell date -u '+%Y-%m-%dT%I:%M:%SZ')
LDFLAGS += -X main.BuildTime=${TIMESTAMP}
LDFLAGS += -X main.BuildSHA=${COMMIT}
LDFLAGS += -X main.Version=${VERSION}
PREFIX?=${PWD}/
DOCKER=$(shell command -v docker;)
TEST_FLAGS?=-race
.PHONY: all
all: quality test
.PHONY: quality
quality:
go vet
go fmt
go mod tidy
ifneq (${DOCKER},)
docker run -v ${PWD}:/src -w /src -it golangci/golangci-lint golangci-lint run --true gocritic --true gosec --true golint --true stylecheck --exclude-use-default=false
endif
.PHONY: test
test:
go test ${TEST_FLAGS} -coverprofile=coverage
.PHONY: clean
clean:
rm -f ${NAME}*
.PHONY: build
build: clean build-darwin build-linux
build-%:
GOOS=$* GOARCH=amd64 go build -ldflags '${LDFLAGS}' -o ${PREFIX}${NAME}-$*
.PHONY: docker
docker:
ifeq (${DOCKER},)
@echo Skipping Docker build because Docker is not installed
else
docker run --rm -i hadolint/hadolint < Dockerfile
docker build \
--build-arg NAME="${NAME}" \
--build-arg VERSION="${VERSION}" \
--build-arg COMMIT="${COMMIT}" \
--build-arg BUILD_DATE="${TIMESTAMP}" \
--build-arg LDFLAGS='${LDFLAGS}' \
--tag ${NAME} .
docker tag ${NAME} ${NAME}:${VERSION}
docker run -it ${NAME}:${VERSION} -- -help 2>&1 | grep -F '${NAME} v${VERSION} ${TIMESTAMP} ${COMMIT}'
endif