-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
118 lines (91 loc) · 3.08 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
.PHONY: build clean
.PHONY: lint
.PHONY: mocks
# Get all function binaries for this code base
# Find all directories with .go files
GOFILES := $(shell find . -name "*.go")
TARGETS=$(sort $(dir $(wildcard func/*/*.go)))
FUNCTIONS=$(addsuffix bootstrap,$(TARGETS))
PACKAGES=$(FUNCTIONS:/bootstrap=.zip)
ARTIFACT=bin/
LOCALSTACK_DIR=integration_test/localstack
build-ci: test $(ARTIFACT) $(FUNCTIONS) $(PACKAGES)
build: lint build-ci
tidy: | node_modules/go.mod
go mod tidy
.PHONY: update-dependencies
update-dependencies:
@echo "Updating Go dependencies"
@cat go.mod | grep -E "^\t" | grep -v "// indirect" | cut -f 2 | cut -d ' ' -f 1 | xargs -n 1 -t go get -d -u
@go mod vendor
@go mod tidy
lint: mocks
@if [ -z "$$(command -v golangci-lint)" ]; then \
@go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest; \
fi
@golangci-lint run ./...
test: mocks
go test -v -failfast -cover $$(go list ./... | grep -v node_modules | grep -v integration_test) -coverprofile=coverage.out
mocks:
@if [ -z "$$(command -v mockgen)" ]; then \
go install github.com/golang/mock/mockgen@v1.6.0; \
fi
go generate ./...
%/bootstrap: %/*.go | node_modules/go.mod
go test -v ./$*
env GOARCH=amd64 GOOS=linux go build -tags lambda.norpc -o $@ ./$*
zip -FS -j $*.zip $@
cp $*.zip $(ARTIFACT)
coverage:
go tool cover -html=coverage.out
# node_modules/go.mod used to ignore possible go modules in node_modules.
node_modules/go.mod:
-@touch $@
$(ARTIFACT):
@mkdir -p $(dir $(ARTIFACT))
@echo
@echo ====== Build Successful ========
@echo
clean:
rm -vf coverage.*
rm -vf *.pid
find . -name mocks -type d -exec rm -rf {} +
find . -name gomock_reflect_* -type d -exec rm -rf {} +
$(RM) $(FUNCTIONS) $(PACKAGES)
$(RM) -r $(ARTIFACT)
export STAGE := testing
export LOG_LEVEL := debug
export BOOKMARKS_BUCKET := integration-test-bookmarks
export BOOKMARKS_SUMMARY_BUCKET := integration-test-bookmarks-summary
.PHONY: localstack-start
localstack-start:
export LOCALSTACK_VOLUME_DIR=$(pwd)/.filesystem/var/lib/localstack
docker-compose -f $(LOCALSTACK_DIR)/docker-compose.localstack.yml up -d
go run integration_test/localstack/localstack_infra.go setup
.PHONY: localstack-stop
localstack-stop:
docker-compose -f $(LOCALSTACK_DIR)/docker-compose.localstack.yml stop
.PHONY: localstack-destroy
localstack-destroy:
docker-compose -f $(LOCALSTACK_DIR)/docker-compose.localstack.yml down --rmi all -v --remove-orphans
$(RM) -r $(LOCALSTACK_DIR)/volume
.PHONY: runapi
runapi:
go run ./func/api
INTTEST_PID_FILE := int_test.pid
runapi-bkgrd: $(GITALY_PID_FILE)
go run ./func/api & echo "$$!" > $(INTTEST_PID_FILE);\
sleep 10
.PHONY: int-test
int-test:
go test -timeout 300s -v -failfast -cover $$(go list ./integration_test/integration/...) -coverprofile=coverage.out
runapi-kill:
if [ -f "$(INTTEST_PID_FILE)" ] ; then \
echo "Clean up integration test" ;\
kill -9 $$(cat $(INTTEST_PID_FILE)) ;\
rm $(INTTEST_PID_FILE) ;\
else \
echo "Integration test not running" ;\
fi ;\
.PHONY: run-int-test
run-int-test: runapi-kill localstack-start runapi-bkgrd int-test runapi-kill localstack-stop