-
Notifications
You must be signed in to change notification settings - Fork 18
/
Makefile
181 lines (142 loc) · 6.26 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
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
GOLANGCI_LINT_VERSION=v1.60.1
LINTER=./bin/golangci-lint
LINTER_VERSION_FILE=./bin/.golangci-lint-version-$(GOLANGCI_LINT_VERSION)
GO_WORK_FILE=go.work
GO_WORK_SUM=go.work.sum
TEST_BINARY=./go-server-sdk.test
ALLOCATIONS_LOG=./build/allocations.out
OUTPUT_DIR=./build
ALL_SOURCES := $(shell find * -type f -name "*.go")
COVERAGE_PROFILE_RAW=./build/coverage_raw.out
COVERAGE_PROFILE_RAW_HTML=./build/coverage_raw.html
COVERAGE_PROFILE_FILTERED=./build/coverage.out
COVERAGE_PROFILE_FILTERED_HTML=./build/coverage.html
COVERAGE_ENFORCER_FLAGS=-package github.com/launchdarkly/go-server-sdk/v7 \
-skipfiles '(internal/sharedtest/$(COVERAGE_ENFORCER_SKIP_FILES_EXTRA))' \
-skipcode "// COVERAGE" \
-packagestats -filestats -showcode
ALL_BUILD_TARGETS=sdk ldotel ldai
ALL_TEST_TARGETS = $(addsuffix -test, $(ALL_BUILD_TARGETS))
ALL_LINT_TARGETS = $(addsuffix -lint, $(ALL_BUILD_TARGETS))
.PHONY: all build clean test test-coverage benchmarks benchmark-allocs lint workspace workspace-clean $(ALL_BUILD_TARGETS) $(ALL_TEST_TARGETS) $(ALL_LINT_TARGETS)
all: $(ALL_BUILD_TARGETS)
test: $(ALL_TEST_TARGETS)
bump-min-go-version:
go mod edit -go=$(MIN_GO_VERSION) go.mod
cd ldotel && go mod edit -go=$(MIN_GO_VERSION) go.mod
cd ldai && go mod edit -go=$(MIN_GO_VERSION) go.mod
cd testservice && go mod edit -go=$(MIN_GO_VERSION) go.mod
cd ./.github/variables && sed -i.bak "s#min=[^ ]*#min=$(MIN_GO_VERSION)#g" go-versions.env && rm go-versions.env.bak
clean: workspace-clean
rm -rf ./bin/
sdk:
go build ./...
sdk-test:
go test -v -race ./...
@# The proxy tests must be run separately because Go caches the global proxy environment variables. We use
@# build tags to isolate these tests from the main test run so that if you do "go test ./..." you won't
@# get unexpected errors.
for tag in proxytest1 proxytest2; do go test -race -v -tags=$$tag ./proxytest; done
sdk-lint:
$(LINTER) run ./...
ldotel:
@if [ -f go.work ]; then \
echo "Building ldotel with workspace" \
go build ./ldotel; \
else \
echo "Building ldotel without workspace" \
cd ldotel && go build .; \
fi
ldotel-test:
@if [ -f go.work ]; then \
echo "Testing ldotel with workspace" \
go test -v -race ./ldotel; \
else \
echo "Testing ldotel without workspace" \
cd ldotel && go test -v -race .; \
fi
ldotel-lint:
@if [ -f go.work ]; then \
echo "Linting ldotel with workspace" \
$(LINTER) run ./ldotel; \
else \
echo "Linting ldotel without workspace" \
cd ldotel && $(LINTER) run .; \
fi
ldai:
@if [ -f go.work ]; then \
echo "Building ldai with workspace" \
go build ./ldai; \
else \
echo "Building ldai without workspace" \
cd ldai && go build .; \
fi
ldai-test:
@if [ -f go.work ]; then \
echo "Testing ldai with workspace" \
go test -v -race ./ldai; \
else \
echo "Testing ldai without workspace" \
cd ldai && go test -v -race .; \
fi
ldai-lint:
@if [ -f go.work ]; then \
echo "Linting ldai with workspace" \
$(LINTER) run ./ldai; \
else \
echo "Linting ldai without workspace" \
cd ldai && $(LINTER) run .; \
fi
test-coverage: $(COVERAGE_PROFILE_RAW)
go run github.com/launchdarkly-labs/go-coverage-enforcer@latest $(COVERAGE_ENFORCER_FLAGS) -outprofile $(COVERAGE_PROFILE_FILTERED) $(COVERAGE_PROFILE_RAW)
go tool cover -html $(COVERAGE_PROFILE_FILTERED) -o $(COVERAGE_PROFILE_FILTERED_HTML)
go tool cover -html $(COVERAGE_PROFILE_RAW) -o $(COVERAGE_PROFILE_RAW_HTML)
$(COVERAGE_PROFILE_RAW): $(ALL_SOURCES)
@mkdir -p ./build
go test -coverprofile $(COVERAGE_PROFILE_RAW) -coverpkg=./... ./... >/dev/null
# note that -coverpkg=./... is necessary so it aggregates coverage to include inter-package references
benchmarks:
@mkdir -p ./build
go test -benchmem '-run=^$$' -bench . ./... | tee build/benchmarks.out
@if grep <build/benchmarks.out 'NoAlloc.*[1-9][0-9]* allocs/op'; then echo "Unexpected heap allocations detected in benchmarks!"; exit 1; fi
# See CONTRIBUTING.md regarding the use of the benchmark-allocs target. Notes about this implementation:
# 1. We precompile the test code because otherwise the allocation traces will include the actions of the compiler itself.
# 2. "benchtime=3x" means the run count (b.N) is set to 3. Setting it to 1 would produce less redundant output, but the
# benchmark statistics seem to be less reliable if the run count is less than 3 - they will report a higher allocation
# count per run, possibly because the first run
benchmark-allocs:
@if [ -z "$$BENCHMARK" ]; then echo "must specify BENCHMARK=" && exit 1; fi
@mkdir -p $(OUTPUT_DIR)
@echo Precompiling test code to $(TEST_BINARY)
@go test -c -o $(TEST_BINARY) >/dev/null 2>&1
@echo "Generating heap allocation traces in $(ALLOCATIONS_LOG) for benchmark(s): $$BENCHMARK"
@echo "You should see some benchmark result output; if you do not, you may have misspelled the benchmark name/regex"
@GODEBUG=allocfreetrace=1 LD_TEST_ALLOCATIONS= $(TEST_BINARY) -test.run=none -test.bench=$$BENCHMARK -test.benchmem -test.benchtime=1x 2>$(ALLOCATIONS_LOG)
$(LINTER_VERSION_FILE):
rm -f $(LINTER)
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s $(GOLANGCI_LINT_VERSION)
touch $(LINTER_VERSION_FILE)
lint: $(LINTER_VERSION_FILE) $(ALL_LINT_TARGETS)
TEMP_TEST_OUTPUT=/tmp/sdk-contract-test-service.log
# TEST_HARNESS_PARAMS can be set to add -skip parameters for any contract tests that cannot yet pass
TEST_HARNESS_PARAMS=
workspace: go.work
go.work:
go work init ./
go work use ./ldotel
go work use ./ldai
go work use ./testservice
workspace-clean:
rm -f $(GO_WORK_FILE) $(GO_WORK_SUM)
build-contract-tests:
@go build -o ./testservice/testservice ./testservice
start-contract-test-service: build-contract-tests
@./testservice/testservice
start-contract-test-service-bg:
@echo "Test service output will be captured in $(TEMP_TEST_OUTPUT)"
@make start-contract-test-service >$(TEMP_TEST_OUTPUT) 2>&1 &
run-contract-tests:
@curl -s https://raw.githubusercontent.com/launchdarkly/sdk-test-harness/v2/downloader/run.sh \
| VERSION=v2 PARAMS="-url http://localhost:10000 -debug -stop-service-at-end $(TEST_HARNESS_PARAMS)" sh
contract-tests: build-contract-tests start-contract-test-service-bg run-contract-tests
.PHONY: build-contract-tests start-contract-test-service start-contract-test-service-bg run-contract-tests contract-tests bump-min-go-version