forked from Furkan-Gulsen/golang-url-shortener
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
64 lines (50 loc) · 1.74 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
STACK_NAME ?= golang-url-shortener
FUNCTIONS := generate redirect stats notification delete
REGION := eu-central-1
GO := go
build:
${MAKE} ${MAKEOPTS} $(foreach function,${FUNCTIONS}, build-${function})
build-%:
cd internal/adapters/functions/$* && GOOS=linux GOARCH=arm64 CGO_ENABLED=0 ${GO} build -o bootstrap
clean:
@rm $(foreach function,${FUNCTIONS}, internal/adapters/functions/${function}/bootstrap)
deploy:
if [ -f samconfig.toml ]; \
then sam deploy --stack-name ${STACK_NAME}; \
else sam deploy -g --stack-name ${STACK_NAME}; \
fi
unit-test:
cd internal/tests/unit/$* && ${GO} test -v .
benchmark-test:
cd internal/tests/benchmark/$* && ${GO} test -v -bench=.
delete:
sam delete --stack-name ${STACK_NAME}
STATICCHECK = $(GOBIN)/staticcheck
GO_FILES := $(shell \
find . '(' -path '*/.*' -o -path './vendor' ')' -prune \
-o -name '*.go' -print | cut -b3-)
MODULE_DIRS = .
.PHONY: lint
lint: $(STATICCHECK)
@rm -rf lint.log
@echo "Checking formatting..."
@gofmt -d -s $(GO_FILES) 2>&1 | tee lint.log
@echo "Checking vet..."
@$(foreach dir,$(MODULE_DIRS),(cd $(dir) && go vet ./... 2>&1) &&) true | tee -a lint.log
@echo "Checking staticcheck..."
@$(foreach dir,$(MODULE_DIRS),(cd $(dir) && $(STATICCHECK) ./... 2>&1) &&) true | tee -a lint.log
@echo "Checking for unresolved FIXMEs..."
@git grep -i fixme | grep -v -e Makefile | tee -a lint.log
@[ ! -s lint.log ]
@rm lint.log
@echo "Checking 'go mod tidy'..."
@make tidy
@if ! git diff --quiet; then \
echo "'go diff tidy' resulted in chnges or working tree is dirty:"; \
git --no-pager diff; \
fi
$(STATICCHECK):
cd tools && go install honnef.co/go/tools/cmd/staticcheck
.PHONY: tidy
tidy:
@$(foreach dir,$(MODULE_DIRS),(cd $(dir) && go mod tidy) &&) true