-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Makefile
79 lines (66 loc) · 1.91 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
# Variables with default values
GOCMD ?= go
GOBUILD = $(GOCMD) build
GOTEST = $(GOCMD) test
GOCLEAN = $(GOCMD) clean
GOIMPORTS = goimports
GOFMT = gofmt
LINT = golangci-lint
VULNCHECK = govulncheck
default: help
# Targets
# Check for required commands
check-deps:
@which $(GOCMD) > /dev/null || (echo "Go is not installed. Visit https://golang.org/doc/install for instructions." && exit 1)
# Compile the project
.PHONY: build
build: check-deps
$(GOBUILD) -o build/fast-shop ./...
# Run tests
.PHONY: test
test: check-deps
$(GOTEST) -v ./...
# Run tests with coverage
.PHONY: test-coverage
test-coverage: check-deps
$(GOTEST) -race -covermode=atomic
# Format code
.PHONY: fmt
fmt: check-deps goimports
$(GOFMT) -w .
# Check for goimports
.PHONY: goimports
goimports:
@which $(GOIMPORTS) > /dev/null || (echo "goimports is not installed. Run 'go install golang.org/x/tools/cmd/goimports@latest' to install." && exit 1)
$(GOIMPORTS) -w .
# Lint code
.PHONY: lint
lint: check-deps
@which $(LINT) > /dev/null || (echo "golangci-lint is not installed. Run 'go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest' to install." && exit 1)
$(LINT) run
# Run security checks
.PHONY: security
security: check-deps
@which $(VULNCHECK) > /dev/null || (echo "govulncheck is not installed. Run 'go install golang.org/x/vuln/cmd/govulncheck@latest' to install." && exit 1)
$(VULNCHECK) ./...
# Run all checks
.PHONY: ci
ci: check-deps fmt lint test security
# Remove build artifacts
.PHONY: clean
clean:
$(GOCLEAN)
rm -rf build
# Show help
.PHONY: help
help:
@echo "Usage:"
@echo " make <target>"
@echo "Targets:"
@echo " build Compile the project"
@echo " test Run tests"
@echo " fmt Run goimports and gofmt on all source files"
@echo " lint Run linter"
@echo " security Run security checks"
@echo " ci Run all checks"
@echo " clean Remove any build artifacts"