-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
51 lines (41 loc) · 1.58 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
# Definitions
ROOT := $(PWD)
GO_HTML_COV := ./coverage.html
GO_TEST_OUTFILE := ./c.out
GOLANG_DOCKER_IMAGE := golang:1.15
CC_TEST_REPORTER_ID := ${CC_TEST_REPORTER_ID}
CC_PREFIX := github.com/sapawarga/userpost-service
.PHONY: clean build packing
# custom logic for code climate, gross but necessary
coverage:
# download CC test reported
docker run -w /app -v ${ROOT}:/app ${GOLANG_DOCKER_IMAGE} \
/bin/bash -c \
"curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter"
# update perms
docker run -w /app -v ${ROOT}:/app ${GOLANG_DOCKER_IMAGE} chmod +x ./cc-test-reporter
# run before build
docker run -w /app -v ${ROOT}:/app \
-e CC_TEST_REPORTER_ID=${CC_TEST_REPORTER_ID} \
${GOLANG_DOCKER_IMAGE} ./cc-test-reporter before-build
# run testing
docker run -w /app -v ${ROOT}:/app ${GOLANG_DOCKER_IMAGE} go test ./... -coverprofile=${GO_TEST_OUTFILE}
docker run -w /app -v ${ROOT}:/app ${GOLANG_DOCKER_IMAGE} go tool cover -html=${GO_TEST_OUTFILE} -o ${GO_HTML_COV}
#upload coverage result
$(eval PREFIX=${CC_PREFIX})
ifdef prefix
$(eval PREFIX=${prefix})
endif
# upload data to CC
docker run -w /app -v ${ROOT}:/app \
-e CC_TEST_REPORTER_ID=${CC_TEST_REPORTER_ID} \
${GOLANG_DOCKER_IMAGE} ./cc-test-reporter after-build --prefix ${PREFIX}
test:
@go test ./... -coverprofile=./coverage.out & go tool cover -html=./coverage.out
build:
@GOOS=linux GOARCH=amd64
@echo ">> Building SERVER..."
@go build -o userpost-service ./cmd/server
@echo ">> Finished"
run:
@./userpost-service