-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
110 lines (91 loc) · 3.18 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
############################################################################################################
# Few rules to follow when editing this file:
#
# 1. Shell commands must be indented with a tab
# 2. Before each target add ".PHONY: target_name" to disable default file target
# 3. Add target description prefixed with "##" on the same line as target definition for "help" target to work
# 4. Be aware that each make command is executed in separate shell
#
# Tips:
#
# * Add an @ sign to suppress output of the command that is executed
# * Define variable like: VAR := value
# * Reference variable like: $(VAR)
# * Reference environment variables like: $(ENV_VARIABLE)
#
#############################################################################################################
.DELETE_ON_ERROR:
.SHELLFLAGS := -eu -o pipefail -c
SHELL = /bin/bash
BIN := .bin
BUILDOUT = ./bin
MAKEFLAGS += --warn-undefined-variables
MAKEFLAGS += --no-builtin-rules
MAKEFLAGS += --no-print-directory
GOPATH ?= ${shell go env GOPATH}
export GOBIN := $(abspath $(BIN))
BOLD = \033[1m
CLEAR = \033[0m
CYAN = \033[36m
GREEN = \033[32m
##@: Default
.PHONY: help
help: ## Display this help
@awk '\
BEGIN {FS = ":.*##"; printf "Usage: make $(CYAN)<target>$(CLEAR)\n"} \
/^[0-9a-zA-Z_\-\/]+?:[^#]*?## .*$$/ { printf "\t$(CYAN)%-20s$(CLEAR) %s\n", $$1, $$2 } \
/^##@/ { printf "$(BOLD)%s$(CLEAR)\n", substr($$0, 5); }' \
$(MAKEFILE_LIST)
##@: Build/Run
all: clean go/gen go/tidy go/format lint build test ## ALL, builds the world
.PHONY: clean
clean: ## Clean-up build artifacts
@echo -e "$(CYAN)--- clean...$(CLEAR)"
@go clean
@rm -rf ${BUILDOUT}
.PHONY: gen
gen: go/gen ## Runs all codegen
.PHONY: test
test: clean go/test ## Runs all tests
.PHONY: lint
lint: go/lint ## Runs all linters
.PHONY: build
build: go/build ## Build
.PHONY: run
run: ## Runs golox. Use ARGS="" make run to pass arguments
@echo -e "$(CYAN)--- run ...$(CLEAR)"
go run ./main.go $(ARGS)
###@: Go
.PHONY: go/format
go/format: $(BIN)/gofumpt ### Format all go files
@echo -e "$(CYAN)--- format go files...$(CLEAR)"
$(BIN)/gofumpt -w .
go/tidy: go.mod go.sum ### Tidy all Go dependencies
@echo -e "$(CYAN)--- tidy go dependencies...$(CLEAR)"
go mod tidy -v -x
.PHONY: go/lint
go/lint: $(BIN)/golangci-lint ### Lints the codebase using golangci-lint
@echo -e "$(CYAN)--- lint codebase...$(CLEAR)"
$(BIN)/golangci-lint run --modules-download-mode=readonly --config .golangci.yml
.PHONY: go/test
go/test: $(BIN)/gotestsum ### Runs all tests
@echo -e "$(CYAN)--- go test ...$(CLEAR)"
@$(BIN)/gotestsum --debug --format-hide-empty-pkg --format=testdox -- -shuffle=on -race -timeout=60s -count 1 -parallel 3 -v ./...
.PHONY: go/gen
go/gen: ### Generate go code
@echo -e "$(CYAN)--- go/gen...$(CLEAR)"
@go generate ./internal/...
.PHONY: go/build
go/build: ### Build
@echo -e "$(CYAN)--- go/build ...$(CLEAR)"
go build -o ${BUILDOUT}/golox ./main.go
# TOOLS
$(BIN)/golangci-lint: Makefile
@mkdir -p $(@D)
go install github.com/golangci/golangci-lint/cmd/[email protected]
$(BIN)/gofumpt: Makefile
@mkdir -p $(@D)
go install mvdan.cc/[email protected]
$(BIN)/gotestsum: Makefile
@mkdir -p $(@D)
go install gotest.tools/[email protected]