forked from evergreen-ci/gimlet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile
More file actions
164 lines (140 loc) · 5.73 KB
/
makefile
File metadata and controls
164 lines (140 loc) · 5.73 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# start project configuration
name := gimlet
buildDir := build
packages := $(name) acl ldap okta rolemanager
orgPath := github.com/evergreen-ci
projectPath := $(orgPath)/$(name)
# end project configuration
# start environment setup
gobin := $(GO_BIN_PATH)
ifeq ($(gobin),)
gobin := go
endif
gopath := $(GOPATH)
gocache := $(abspath $(buildDir)/.cache)
goroot := $(GOROOT)
ifeq ($(OS),Windows_NT)
gocache := $(shell cygpath -m $(gocache))
gopath := $(shell cygpath -m $(gopath))
goroot := $(shell cygpath -m $(goroot))
endif
export GOPATH := $(gopath)
export GOCACHE := $(gocache)
export GOROOT := $(goroot)
export GO111MODULE := off
# end environment setup
# Ensure the build directory exists, since most targets require it.
$(shell mkdir -p $(buildDir))
# start lint setup targets
lintDeps := $(buildDir)/run-linter $(buildDir)/golangci-lint
$(buildDir)/golangci-lint:
@curl --retry 10 --retry-max-time 60 -sSfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(buildDir) v1.40.0 >/dev/null 2>&1
$(buildDir)/run-linter:cmd/run-linter/run-linter.go $(buildDir)/golangci-lint
@$(gobin) build -o $@ $<
# end lint setup targets
######################################################################
##
## Everything below this point is generic, and does not contain
## project specific configuration. (with one noted case in the "build"
## target for library-only projects)
##
######################################################################
# start dependency installation tools
# implementation details for being able to lazily install dependencies
testOutput := $(subst -,/,$(foreach target,$(packages),$(buildDir)/output.$(target).test))
lintOutput := $(subst -,/,$(foreach target,$(packages),$(buildDir)/output.$(target).lint))
coverageOutput := $(subst -,/,$(foreach target,$(packages),$(buildDir)/output.$(target).coverage))
coverageHtmlOutput := $(subst -,/,$(foreach target,$(packages),$(buildDir)/output.$(target).coverage.html))
# end dependency installation tools
# lint setup targets
# end lint setup targets
# userfacing targets for basic build and development operations
lint:$(lintOutput)
compile $(buildDir):
$(gobin) build ./.
test:$(testOutput)
coverage:$(coverageOutput)
coverage-html:$(coverageHtmlOutput)
phony := build test coverage coverage-html
.PRECIOUS: $(testOutput) $(lintOuptut) $(coverageOutput) $(coverageHtmlOutput)
# end front-ends
# convenience targets for runing tests and coverage tasks on a
# specific package.
test-%:$(buildDir)/output.%.test
@grep -s -q -e "^PASS" $<
coverage-%:$(buildDir)/output.%.coverage
html-coverage-%:$(buildDir)/output.%.coverage.html
lint-%:$(buildDir)/output.%.lint
@grep -v -s -q "^--- FAIL" $<
# end convienence targets
# start test and coverage artifacts
# tests have compile and runtime deps. This varable has everything
# that the tests actually need to run. (The "build" target is
# intentional and makes these targets rerun as expected.)
testArgs := -v
ifeq (,$(DISABLE_COVERAGE))
testArgs += -cover
endif
ifneq (,$(RACE_DETECTOR))
testArgs += -race
endif
ifneq (,$(RUN_TEST))
testArgs += -run='$(RUN_TEST)'
endif
ifneq (,$(RUN_COUNT))
testArgs += -count=$(RUN_COUNT)
endif
ifneq (,$(TEST_TIMEOUT))
testArgs += -timeout=$(TEST_TIMEOUT)
endif
# implementation for package coverage and test running,mongodb to produce
# and save test output.
$(buildDir)/output.%.coverage: .FORCE
$(gobin) test $(testArgs) ./$(if $(subst $(name),,$*),$(subst -,/,$*),) -covermode=count -coverprofile $@ | tee $(buildDir)/output.$*.test
@-[ -f $@ ] && $(gobin) tool cover -func=$@ | sed 's%$(projectPath)/%%' | column -t
$(buildDir)/output.%.coverage.html: $(buildDir)/output.%.coverage .FORCE
$(gobin) tool cover -html=$< -o $@
$(buildDir)/output.%.test: .FORCE
$(gobin) test $(testArgs) ./$(if $(subst $(name),,$*),$(subst -,/,$*),) | tee $(buildDir)/output.$(subst /,-,$*).test
# targets to generate gotest output from the linter.
# We have to handle the PATH specially for CI, because if the PATH has a different version of Go in it, it'll break.
$(buildDir)/output.%.lint: $(buildDir)/run-linter .FORCE
@$(if $(GO_BIN_PATH), PATH="$(shell dirname $(GO_BIN_PATH)):$(PATH)") ./$< --output=$@ --lintBin=$(buildDir)/golangci-lint --packages='$*'
# end test and coverage artifacts
# start vendoring configuration
vendor-clean:
rm -rf vendor/github.com/mongodb/grip/vendor/github.com/pkg/
rm -rf vendor/github.com/mongodb/grip/vendor/github.com/stretchr/
rm -rf vendor/gopkg.in/asn1-ber.v1/tests/
rm -rf vendor/github.com/rs/cors/examples/
find vendor/ -name "*.gif" -o -name "*.gz" -o -name "*.png" -o -name "*.ico" -o -name "*.dat" -o -name "*testdata" | xargs rm -rf
find vendor/ -type d -name '.git' | xargs rm -rf
phony += vendor-clean
# end vendoring tooling configuration
# clean and other utility targets
clean:
rm -rf $(lintDeps)
clean-results:
rm -rf $(buildDir)/output.*
phony += clean
# end dependency targets
# mongodb utility targets
mongodb/.get-mongodb:
rm -rf mongodb
mkdir -p mongodb
cd mongodb && curl "$(MONGODB_URL)" -o mongodb.tgz && $(DECOMPRESS) mongodb.tgz && chmod +x ./mongodb-*/bin/*
cd mongodb && mv ./mongodb-*/bin/* . && rm -rf db_files && rm -rf db_logs && mkdir -p db_files && mkdir -p db_logs
get-mongodb: mongodb/.get-mongodb
@touch $<
start-mongod: mongodb/.get-mongodb
./mongodb/mongod --dbpath ./mongodb/db_files --port 27017 --replSet evg --smallfiles --oplogSize 10
@echo "waiting for mongod to start up"
init-rs:mongodb/.get-mongodb
./mongodb/mongo --eval 'rs.initiate()'
check-mongod: mongodb/.get-mongodb
./mongodb/mongo --nodb --eval "assert.soon(function(x){try{var d = new Mongo(\"localhost:27017\"); return true}catch(e){return false}}, \"timed out connecting\")"
@echo "mongod is up"
# end mongodb targets
# configure phony targets
.FORCE:
.PHONY:$(phony)