forked from Azuka/keycloak-admin-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
106 lines (91 loc) · 3.2 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
################################################################
## Color definition
################################################################
NO_COLOR = \x1b[0m
OK_COLOR = \x1b[32;01m
WARN_COLOR = \x1b[33;01m
ERROR_COLOR = \x1b[31;01m
################################################################
## Helpers
################################################################
PWD := $(shell pwd)
GO_PACKAGES = $(shell go list ./... | grep -v vendor | grep -v integration)
GO_INTEGRATION_PACKAGES = $(shell go list ./... | grep integration)
GO_FILES = $(shell find . -name "*.go" | grep -v vendor | uniq)
CI_TEST_REPORTS ?= /tmp/test-results
.PHONY: init-ci
init-ci:
@echo "$(OK_COLOR)==> Installing minimal build requirements$(NO_COLOR)"
go get -u github.com/alecthomas/gometalinter
gometalinter --install
go get -u github.com/jstemmer/go-junit-report
dep ensure
.PHONY: init
init: init-ci
@echo "$(OK_COLOR)==> Installing dev build requirements$(NO_COLOR)"
go get -u github.com/fatih/gomodifytags
go get -u github.com/mailru/easyjson/...
# Format files
.PHONY: format
format:
@echo "$(OK_COLOR)==> Formatting$(NO_COLOR)"
gofmt -s -l -w $(GO_FILES)
# Generate files
.PHONY: generate
generate:
@echo "$(OK_COLOR)==> Generating code$(NO_COLOR)"
@rm -rf $(PWD)/keycloak/*_easyjson.go
@go generate ./...
# Lint
.PHONY: lint
lint:
@echo "$(OK_COLOR)==> Linting$(NO_COLOR)$(NO_COLOR)"
@go list -f '{{.Dir}}' ./... | grep -v 'vendor' | \
xargs gometalinter
# Test
.PHONY: test
test: format lint
@echo "$(OK_COLOR)==> Testing $(NO_COLOR)"
go test -race -cover $(GO_PACKAGES)
# Test integration
.PHONY: integration
integration:
@echo "$(OK_COLOR)==> Integration testing $(NO_COLOR)"
docker-compose -f $(PWD)/integration/docker-compose.yml up -d
go test -race $(GO_INTEGRATION_PACKAGES)
make integration-clean
.PHONY: integration-clean
integration-clean:
docker-compose -f $(PWD)/integration/docker-compose.yml down
# Generate coverage
.PHONY: coverage
coverage:
@echo "$(OK_COLOR)==> Generating Coverage Report$(NO_COLOR)"
mkdir -p $(CI_ARTIFACTS)/htmlcov
overalls -project=$(PKG) -covermode=count
go tool cover -html=overalls.coverprofile -o $(COVER_HTML)
# CI test
.PHONY: test-ci
#code coverage regex for Gitlab: ^total:(\s+)\(statements\)(\s+)(\d+(?:\.\d+)?%)
test-ci:
@echo "$(OK_COLOR)==> Running ci test$(NO_COLOR)"
mkdir -p $(CI_TEST_REPORTS)
/bin/bash -c "set -euxo pipefail; \
go test -v -short -race -cover -coverprofile .testCoverage.txt $(GO_PACKAGES) | tee >(go-junit-report > $(CI_TEST_REPORTS)/report.xml); \
sed '/_easyjson.go/d' .testCoverage.txt > .testCoverage.txt.bak; mv .testCoverage.txt.bak .testCoverage.txt; go tool cover -func=.testCoverage.txt"
# CI Lint
.PHONY: lint-ci
lint-ci:
@echo "$(OK_COLOR)==> Running CI lint$(NO_COLOR)"
go list -f '{{.Dir}}' ./... | grep -v 'vendor' | xargs gometalinter --json > lint.json
# Quick test for rapid dev-feedback cycles
.PHONY: qt
qt:
@echo "$(OK_COLOR)==> Running quick test$(NO_COLOR)"
go test -short $(GO_PACKAGES)
.PHONY: local-ci
local-ci:
@echo "$(OK_COLOR)==> Running CI locally. Did you run brew install gitlab-runner?$(NO_COLOR)"
brew services start gitlab-runner
gitlab-runner exec docker unit
gitlab-runner exec docker lint