| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
SHELL := $(shell which bash) |
| 8 |
CWD_DIR := $(shell pwd) |
| 9 |
GITHUB_API_URL ?= https://api.github.com |
| 10 |
|
| 11 |
LINT_FILES := ./... |
| 12 |
|
| 13 |
|
| 14 |
define goformat |
| 15 |
files="$$(go fmt ./...)"; \ |
| 16 |
if [ -n "$${files}" ]; then \ |
| 17 |
echo "❌ ERROR: go files are not properly formatted:"; \ |
| 18 |
echo "$$files"; \ |
| 19 |
echo ""; \ |
| 20 |
echo "run the 'go fmt ./..' command or configure your editor"; \ |
| 21 |
exit 1; \ |
| 22 |
fi; |
| 23 |
endef |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
.PHONY: tidy |
| 40 |
tidy: |
| 41 |
@echo "==> starting tidy" |
| 42 |
go mod tidy |
| 43 |
|
| 44 |
|
| 45 |
.PHONY: format |
| 46 |
format: |
| 47 |
@echo "==> starting format" |
| 48 |
@$(call goformat) |
| 49 |
|
| 50 |
|
| 51 |
.PHONY: test |
| 52 |
test: |
| 53 |
@echo "==> starting test" |
| 54 |
go test ./... |
| 55 |
|
| 56 |
|
| 57 |
.PHONY: lint-all |
| 58 |
lint-all: |
| 59 |
@echo "==> starting lint for directory: ${LINT_FILES}" |
| 60 |
golangci-lint run ${LINT_FILES} |
| 61 |
|
| 62 |
|
| 63 |
.PHONY: lint |
| 64 |
lint: |
| 65 |
@echo "==> starting lint for changed files" |
| 66 |
golangci-lint run --whole-files --new-from-rev=origin/main |
| 67 |
|
| 68 |
.PHONY: help |
| 69 |
help: |
| 70 |
@echo "Usage: make <target>" |
| 71 |
@echo "" |
| 72 |
@echo "Targets:" |
| 73 |
@echo " tidy - clean up the go modules files" |
| 74 |
@echo " format - go format this project" |
| 75 |
@echo " test - run some go test" |
| 76 |
@echo " lint-all - runs linter for all files (optional pass in LINT_FILES=path_to_dir_or_file_to_check)" |
| 77 |
@echo " lint - runs linter for only files with diffs from origin/main (useful for PRs)" |
| 78 |
@echo " help - this help message" |