-
Notifications
You must be signed in to change notification settings - Fork 9
/
Makefile
78 lines (68 loc) · 2.17 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
# Go projects should have a Makefile for commond build-related tasks.
# See help target for a list of targets and their descriptions.
#
# Debug related targets are commented out until they can be tested.
# setup defaults
SHELL := $(shell which bash)
CWD_DIR := $(shell pwd)
GITHUB_API_URL ?= https://api.github.com
# DLV_BIN := $(shell go env GOPATH)/bin/dlv
LINT_FILES := ./...
# provide extra information when format fails
define goformat
files="$$(go fmt ./...)"; \
if [ -n "$${files}" ]; then \
echo "❌ ERROR: go files are not properly formatted:"; \
echo "$$files"; \
echo ""; \
echo "run the 'go fmt ./..' command or configure your editor"; \
exit 1; \
fi;
endef
# # install dlv if it is not already installed
# define dlv
# cat /proc/sys/kernel/yama/ptrace_scope | grep 0 || \
# echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope; \
# echo "Checking if '$(DLV_BIN)' exist"; \
# test -f "$(DLV_BIN)" || \
# echo "Installing dlv..." && \
# go install github.com/go-delve/delve/cmd/dlv@latest && \
# echo "Installed dlv";
# endef
# NOTE: Targets defined with .PHONY are not files, they execute commands.
# clean up the go modules files
.PHONY: tidy
tidy:
@echo "==> starting tidy"
go mod tidy
# go format this project
.PHONY: format
format:
@echo "==> starting format"
@$(call goformat)
# run some go test
.PHONY: test
test:
@echo "==> starting test"
go test ./...
# runs linter for all files
.PHONY: lint-all
lint-all:
@echo "==> starting lint for directory: ${LINT_FILES}"
golangci-lint run ${LINT_FILES}
# runs linter for only files with diffs from origin/main (useful for PRs)
.PHONY: lint
lint:
@echo "==> starting lint for changed files"
golangci-lint run --whole-files --new-from-rev=origin/main
.PHONY: help
help:
@echo "Usage: make <target>"
@echo ""
@echo "Targets:"
@echo " tidy - clean up the go modules files"
@echo " format - go format this project"
@echo " test - run some go test"
@echo " lint-all - runs linter for all files (optional pass in LINT_FILES=path_to_dir_or_file_to_check)"
@echo " lint - runs linter for only files with diffs from origin/main (useful for PRs)"
@echo " help - this help message"