-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
69 lines (56 loc) · 2.43 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
help: ## show this message
@echo "All commands can be run on local machine as well as inside dev container."
@echo ""
@sed -nE 's/^ *([^[:blank:]]+)[[:blank:]]*:[^#]*##[[:blank:]]*(.+)/\1\n\2/p' $(MAKEFILE_LIST) | tr '\n' '\0' | xargs -0 -n 2 printf '%-25s%s\n'
.PHONY: help
.DEFAULT_GOAL := help
test: ## run all tests
@echo "+ $@"
go test -race -count 1 -p 8 -parallel 8 -timeout 1m ./...
.PHONY: test
test-cover: ## run all tests with code coverage
@echo "+ $@"
go test -race -count 1 -p 8 -parallel 8 -timeout 1m -coverpkg ./... -coverprofile coverage.out ./...
.PHONY: test-cover
test-latest-deps: ## run all tests with latest dependencies
@echo "+ $@"
go test -modfile .github/latest-deps/go.mod -race -p 8 -parallel 8 -timeout 1m ./...
.PHONY: test
lint: build-docker-dev ## run linter
@echo "+ $@"
$(RUN_IN_DOCKER) golangci-lint run
.PHONY: lint
bash: build-docker-dev ## run bash inside container for development
ifndef INSIDE_DEV_CONTAINER
@echo "+ $@"
$(RUN_IN_DOCKER) bash
endif
.PHONY: bash
IMPORTS = find . -name '*.go' -not -path './.github/*' -exec sed -e '/^import (/,/^)/!d' {} + | sed -e '/\./!d' | grep -v "`head -n 1 go.mod | sed -e 's/module //'`" | sed -E -e 's/\t(.+ )?"/\t_ "/' | sort | uniq | xargs -0 printf 'package imports\n\nimport (\n%s)\n'
tidy: ## keep go.mod and .github/latest-deps tidy
@echo "+ $@"
go mod tidy
$(IMPORTS) > .github/latest-deps/imports.go
go mod tidy -modfile=.github/latest-deps/go.mod
.PHONY: check
check-tidy: ## ensure go.mod is tidy
@echo "+ $@"
go mod tidy -diff
$(IMPORTS) > .github/latest-deps/imports.check.go
diff -u .github/latest-deps/imports.go .github/latest-deps/imports.check.go
rm .github/latest-deps/imports.check.go
go mod tidy -diff -modfile=.github/latest-deps/go.mod
.PHONY: check-tidy
build-docker-dev: ## build development image from Dockerfile.dev
ifndef INSIDE_DEV_CONTAINER
@echo "+ $@"
DOCKER_BUILDKIT=1 docker build --tag testpackege:dev - < Dockerfile.dev
endif
.PHONY: build-docker-dev
ifndef INSIDE_DEV_CONTAINER
RUN_IN_DOCKER = docker run --rm \
-it \
-w /app \
--mount type=bind,consistency=delegated,source="`pwd`",target=/app \
testpackege:dev
endif