-
-
Notifications
You must be signed in to change notification settings - Fork 46
/
Makefile
100 lines (78 loc) · 2.89 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
97
98
99
100
COMMIT := $(shell if [ -d .git ]; then git rev-parse HEAD; else echo "unknown"; fi)
SHORTCOMMIT := $(shell echo $(COMMIT) | head -c 7)
BRANCH := $(shell if [ -d .git ]; then git rev-parse --abbrev-ref HEAD; else echo "master"; fi)
BUILD := $(shell date -u "+%Y-%m-%dT%H:%M:%SZ")
BINSUFFIX := $(shell if [ "${GOOS}" -a "${GOARCH}" ]; then echo "-${GOOS}-${GOARCH}"; else echo ""; fi)
GOARM := $(subst v,$e,$(GOARM))
all: build
## init: Install required apps
init:
go install honnef.co/go/tools/cmd/staticcheck@latest
go install github.com/swaggo/swag/cmd/swag@latest
go install github.com/99designs/gqlgen@latest
go install golang.org/x/vuln/cmd/govulncheck@latest
## build: Build core (default)
build:
CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} GOARM=${GOARM} go build -o core$(BINSUFFIX) -trimpath
## swagger: Update swagger API documentation (requires github.com/swaggo/swag)
swagger:
swag init -g http/server.go
## gqlgen: Regenerate GraphQL server from schema
gqlgen:
go run github.com/99designs/gqlgen generate --config http/graph/gqlgen.yml
## test: Run all tests
test:
go test -race -coverprofile=/dev/null -v ./...
## vet: Analyze code for potential errors
vet:
go vet ./...
## fmt: Format code
fmt:
go fmt ./...
## vulncheck: Check for known vulnerabilities in dependencies
vulncheck:
govulncheck ./...
## update: Update dependencies
update:
go get -u
@-$(MAKE) tidy
@-$(MAKE) vendor
## tidy: Tidy up go.mod
tidy:
go mod tidy
## vendor: Update vendored packages
vendor:
go mod vendor
## run: Build and run core
run: build
./core
## lint: Static analysis with staticcheck
lint:
staticcheck ./...
## import: Build import binary
import:
cd app/import && CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} GOARM=$(GOARM) go build -o ../../import -trimpath -ldflags="-s -w"
## ffmigrate: Build ffmpeg migration binary
ffmigrate:
cd app/ffmigrate && CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} GOARM=$(GOARM) go build -o ../../ffmigrate -trimpath -ldflags="-s -w"
## coverage: Generate code coverage analysis
coverage:
go test -race -coverprofile test/cover.out ./...
go tool cover -html=test/cover.out -o test/cover.html
## commit: Prepare code for commit (vet, fmt, test)
commit: vet fmt lint test build
@echo "No errors found. Ready for a commit."
## release: Build a release binary of core
release:
CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} GOARM=$(GOARM) go build -o core -trimpath -ldflags="-s -w -X github.com/datarhei/core/v16/app.Commit=$(COMMIT) -X github.com/datarhei/core/v16/app.Branch=$(BRANCH) -X github.com/datarhei/core/v16/app.Build=$(BUILD)"
## docker: Build standard Docker image
docker:
docker build -t core:$(SHORTCOMMIT) .
.PHONY: help init build swagger test vet fmt vulncheck vendor commit coverage lint release import ffmigrate update
## help: Show all commands
help: Makefile
@echo
@echo " Choose a command:"
@echo
@sed -n 's/^##//p' $< | column -t -s ':' | sed -e 's/^/ /'
@echo