generated from takumin/boilerplate-golang-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
96 lines (75 loc) · 1.78 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
APPNAME := $(shell basename $(CURDIR))
VERSION := $(shell git describe --abbrev=0 --tags 2>/dev/null)
REVISION := $(shell git rev-parse HEAD 2>/dev/null)
ifeq ($(VERSION),)
VERSION := dev
endif
ifeq ($(REVISION),)
REVISION := unknown
endif
SRCS := $(shell find . -type f -name '*.go')
LDFLAGS_APPNAME := -X "main.AppName=$(APPNAME)"
LDFLAGS_VERSION := -X "main.Version=$(VERSION)"
LDFLAGS_REVISION := -X "main.Revision=$(REVISION)"
LDFLAGS := -s -w -buildid= $(LDFLAGS_APPNAME) $(LDFLAGS_VERSION) $(LDFLAGS_REVISION) -extldflags -static
BUILDFLAGS := -trimpath -ldflags '$(LDFLAGS)'
.PHONY: all
all: clean tools generate fmt vet sec vuln lint test build
.PHONY: docs
docs:
mdbook build
.PHONY: docs-serve
docs-serve:
mdbook serve -o
.PHONY: tools
tools:
aqua install --all
.PHONY: generate
generate:
go generate ./...
.PHONY: fmt
fmt:
gofmt -e -d .
.PHONY: vet
vet:
go vet ./...
.PHONY: sec
sec:
gosec -quiet -fmt golint ./...
.PHONY: vuln
vuln:
trivy fs -q -s HIGH,CRITICAL --scanners vuln,config,secret,license .
.PHONY: lint
lint:
staticcheck ./...
.PHONY: test
test:
go test -trimpath -cover -covermode atomic ./...
.PHONY: coverage
coverage: coverage.out coverage.html
coverage.out: $(SRCS)
go test -trimpath -cover -covermode atomic -coverprofile coverage.out ./...
coverage.html: coverage.out
go tool cover -html coverage.out -o coverage.html
.PHONY: build
build: bin/$(APPNAME)
bin/$(APPNAME): $(SRCS)
CGO_ENABLED=0 go build $(BUILDFLAGS) -o $@
.PHONY: install
install: build
CGO_ENABLED=0 go install $(BUILDFLAGS)
.PHONY: snapshot
snapshot:
goreleaser release --clean --snapshot
.PHONY: release
release:
ifneq ($(GITHUB_TOKEN),)
goreleaser release --clean
endif
.PHONY: clean
clean:
rm -rf bin
rm -rf dist
rm -rf book
rm -f coverage.out
rm -f coverage.html