-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
96 lines (77 loc) · 2.61 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
# -------------------------------------------------------------------------------------------------
# main
# -------------------------------------------------------------------------------------------------
all: help
## build: Compile templ files and build application
.PHONY: build
build: get-deps generate-web
CGO_ENABLED=0 go build -ldflags="-s -w -extldflags '-static'" -trimpath -o 'bin/app' ./cmd/app
## start: Build and start application
.PHONY: start
start: get-deps generate-web
go run ./cmd/app
## build-docker: Build Docker container image with this app
.PHONY: build-docker
build-docker:
docker build -t $(shell basename $(PWD)):latest --no-cache -f Dockerfile .
## run-docker: Run Docker container image with this app
.PHONY: run-docker
run-docker:
docker run --rm -it -p 8080:8080 $(shell basename $(PWD)):latest
# -------------------------------------------------------------------------------------------------
# testing
# -------------------------------------------------------------------------------------------------
## test: Run unit tests
.PHONY: test
test: check-go
@go test -v -count=1 ./...
# -------------------------------------------------------------------------------------------------
# tools && shared
# -------------------------------------------------------------------------------------------------
## tidy: Removes unused dependencies and adds missing ones
.PHONY: tidy
tidy: check-go
go mod tidy
## update-deps: Update go dependencies
.PHONY: update-deps
update-deps: check-go
go get -u ./...
-@$(MAKE) tidy
## get-deps: Download go dependencies
.PHONY: get-deps
get-deps: check-go
go mod download
## generate-web: Compile templ files via github.com/a-h/templ/cmd/templ
.PHONY: generate-web
generate-web: check-go
go install github.com/a-h/templ/cmd/templ@latest
~/go/bin/templ generate
## air: Build and start application in live reload mode via air
.PHONY: air
air: get-deps generate-web
go install github.com/air-verse/air@latest
air
## format: Fix code format issues
.PHONY: format
format:
go run mvdan.cc/gofumpt@latest -w -l .
## deadcode: Run deadcode tool for find unreachable functions
deadcode:
go run golang.org/x/tools/cmd/deadcode@latest -test ./...
## audit: Quality checks
.PHONY: audit
audit:
go mod verify
go vet ./...
go run golang.org/x/vuln/cmd/govulncheck@latest ./...
## check-go: Check that Go is installed
.PHONY: check-go
check-go:
@command -v go &> /dev/null || (echo "Please install GoLang" && false)
## help: Display help
.PHONY: help
help: Makefile
@echo "Usage: make COMMAND"
@echo
@echo "Commands:"
@sed -n 's/^##//p' $< | column -ts ':' | sed -e 's/^/ /'