-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
42 lines (33 loc) · 1.18 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
SHELL=/bin/bash
APP=auth-service
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=70
.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)"
migrate: build
@echo "> running database migration"
@${APP_EXECUTABLE} migrate
copy-config:
@echo "> copying configuration file"
@cp .env.example .env
server: build
@echo "> starting server"
@${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}}'