-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
85 lines (66 loc) · 2.29 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
# https://www.alexedwards.net/blog/a-time-saving-makefile-for-your-go-projects
# Change these variables as necessary.
MAIN_PACKAGE_PATH := ./cmd/sc
BINARY_NAME := sc
# ==================================================================================== #
# HELPERS
# ==================================================================================== #
## help: print this help message
.PHONY: help
help:
@echo 'Usage:'
@sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /'
.PHONY: confirm
confirm:
@echo -n 'Are you sure? [y/N] ' && read ans && [ $${ans:-N} = y ]
.PHONY: no-dirty
no-dirty:
git diff --exit-code
# ==================================================================================== #
# QUALITY CONTROL
# ==================================================================================== #
## tidy: format code and tidy modfile
.PHONY: tidy
tidy:
go fmt ./...
go mod tidy -v
## audit: run quality control checks
.PHONY: audit
audit:
go mod verify
go run github.com/golangci/golangci-lint/cmd/golangci-lint@latest run ./...
go run golang.org/x/vuln/cmd/govulncheck@latest ./...
go run github.com/google/go-licenses@latest check --disallowed_types restricted ./...
# ==================================================================================== #
# DEVELOPMENT
# ==================================================================================== #
## test: run all tests
.PHONY: test
test:
go test -v -race -buildvcs ./...
## test/cover: run all tests and display coverage
.PHONY: test/cover
test/cover:
go test -v -race -buildvcs -coverprofile=/tmp/coverage.out ./...
go tool cover -html=/tmp/coverage.out
## build: build the application
.PHONY: build
build:
rm -rf dist/*
go generate ./...
go build -o=./dist/${BINARY_NAME} ${MAIN_PACKAGE_PATH}
## run: run the application
.PHONY: run
run:
go run ${MAIN_PACKAGE_PATH}
# ==================================================================================== #
# OPERATIONS
# ==================================================================================== #
## release-local: creates a new LOCAL release
.PHONY: release-local
release-local: tidy audit no-dirty
go run github.com/goreleaser/goreleaser@latest
## push: push changes to the remote Git repository
.PHONY: push
push: tidy audit no-dirty
git push