-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
91 lines (75 loc) · 2.48 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
# VARIABLES
PROJECTNAME ?= ${shell basename "${PWD}"}
export GOBIN = $(CURDIR)/bin
export PATH := $(GOBIN):$(PATH)
# TARGETS
# First target, is the default command run if 'make' is invoked without any targets
all: install
## coverage: Runs tests and reports coverage
.PHONY: coverage
coverage: create-coverage
@echo "=============================== Coverage Summary ==============================="
@go tool cover -func=coverage.out
@echo "================================================================================"
## coverage-html: Runs tests and opens a browser window to visualize test coverage
.PHONY: coverage-html
coverage-html: create-coverage
@echo "📊 Opening coverage report in browser..."
@go tool cover -html=coverage.out
## create-coverage: Outputs test coverage to 'coverage.out'
.PHONY: create-coverage
create-coverage:
@echo "🏃 Running tests and creating coverage report..."
@GO_ENV=test go test -race -coverprofile=coverage.out ./...
@echo "✅ Done."
## install: Downloads/installs all app dependencies
.PHONY: install
install:
@echo "🚚 Downloading dependencies..."
@go mod download
@echo "🛠 Building Go dependencies..."
@go install github.com/cortesi/modd/cmd/modd
@go install github.com/golangci/golangci-lint/cmd/golangci-lint
@go install github.com/psampaz/go-mod-outdated
@echo "✨ Done."
## install: Downloads/installs all app dependencies
.PHONY: install-ci
install-ci:
@echo "🚚 Downloading dependencies..."
@go mod download
@echo "🛠 Building Go dependencies..."
@go install github.com/golangci/golangci-lint/cmd/golangci-lint
@echo "✨ Done."
## lint: Runs linter against Go files
.PHONY: lint
lint:
@echo "🔍 Linting Go files..."
@golangci-lint run $(flags)
@go mod tidy
@git diff --exit-code -- go.mod go.sum
@echo "✨ Done."
## mod-outdated: Checks for updates to direct go.mod dependencies
.PHONY: mod-outdated
mod-outdated:
@go list -u -m -json all | go-mod-outdated -update -direct
## test: Runs all tests
.PHONY: test
test:
${eval flags ?= -race}
${eval packages ?= ./...}
@echo "🏃 Running all Go tests..."
GO_ENV=test go test ${flags} ${packages}
@echo "✅ Done."
## test-watch: Runs tests and watches for changes
.PHONY: test-watch
test-watch:
@echo "🏃 Running test watcher..."
@modd --file=./internal/tools/modd.test.conf
## help: List available commands
.PHONY: help
help: Makefile
@echo
@echo " Choose a command to run in "${PROJECTNAME}":"
@echo
@sed -n 's/^##//p' $< | column -t -s ':' | sed -e 's/^/ /'
@echo