-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
34 lines (27 loc) · 1.04 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
SHELL=/bin/bash
APP=CreateParcelApi
APP_EXECUTABLE="./build/$(APP)"
APP_COMMIT=$(shell git rev-parse HEAD)
ALL_PACKAGES=$(shell go list ./... | grep -v "vendor")
SOURCE_DIRS=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
COVERAGE_MIN=95
.PHONY: build
all: clean test
clean:
@echo "> cleaning up the mess"
@rm -rf build && mkdir -p build
lint:
@echo "> running linter $(SOURCE_DIRS)/..."
@golangci-lint run -v --timeout 5m $(SOURCE_DIRS)/...
build:
@echo "> building binary"
@go build -o $(APP_EXECUTABLE) -ldflags "-X main.commit=$(APP_COMMIT)"
server: build
@echo "> running server command"
@${APP_EXECUTABLE} server
test:
@echo "> running test and creating coverage report"
go test -race -p=1 -cover -coverprofile=coverage.txt -covermode=atomic $(ALL_PACKAGES)
@go tool cover -html=coverage.txt -o coverage.html
@go tool cover -func=coverage.txt | grep -i total:
@go tool cover -func=coverage.txt | gawk '/total:.*statements/ {if (strtonum($$3) < $(COVERAGE_MIN)) {print "ERR: coverage is lower than $(COVERAGE_MIN)"; exit 1}}'