forked from OpenCHAMI/magellan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
122 lines (98 loc) · 3.11 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# import config.
# You can change the default config with `make cnf="config_special.env" build`
cnf ?= config.env
include $(cnf)
export $(shell sed 's/=.*//' $(cnf))
ifndef NAME
$(error NAME is not set. Please review and copy config.env.default to config.env and try again)
endif
ifndef VERSION
$(error VERSION is not set. Please review and copy config.env.default to config.env and try again)
endif
ifndef BUILD
$(error BUILD is not set. Please review and copy config.env.default to config.env and try again)
endif
LDFLAGS="-s -X=$(GIT)main.commit=$(BUILD) -X=$(GIT)main.version=$(VERSION) -X=$(GIT)main.date=$(shell date +%Y-%m-%d:%H:%M:%S)"
SHELL := /bin/bash
GOPATH ?= $(shell echo $${GOPATH:-~/go})
.DEFAULT_GOAL := all
.PHONY: all
all: ## build pipeline
all: mod inst build lint test
.PHONY: ci
ci: ## CI build pipeline
ci: all diff
.PHONY: help
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY: clean
clean: ## remove files created during build pipeline
$(call print-target)
rm -rf dist
rm -f coverage.*
rm -f '"$(shell go env GOCACHE)/../golangci-lint"'
go clean -i -cache -testcache -modcache -fuzzcache -x
.PHONY: mod
mod: ## go mod tidy
$(call print-target)
go mod tidy
.PHONY: inst
inst: ## go install tools
$(call print-target)
go install github.com/client9/misspell/cmd/misspell@v0.3.4
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.52.2
go install github.com/goreleaser/goreleaser/v2@v2.3.2
go install github.com/cpuguy83/go-md2man/v2@latest
.PHONY: release
release: ## goreleaser build
$(call print-target)
$(GOPATH)/bin/goreleaser build --clean --single-target --snapshot
.PHONY: binaries
binaries: build
.PHONY: build
build: ## go build
go build -v --tags=all -ldflags=$(LDFLAGS) -o $(NAME) main.go
.PHONY: docker
container: ## docker build
container:
$(call print-target)
docker build . --build-arg REGISTRY_HOST=${REGISTRY_HOST} --no-cache --pull --tag '${NAME}:${VERSION}'
.PHONY: spell
spell: ## misspell
$(call print-target)
$(GOPATH)/bin/misspell -error -locale=US -w **.md
.PHONY: lint
lint: ## golangci-lint
$(call print-target)
$(GOPATH)/bin/golangci-lint run --fix
.PHONY: test
test: ## go test
$(call print-target)
./emulator/setup.sh &
sleep 10
go test -race -covermode=atomic -coverprofile=coverage.out -coverpkg=./... tests/api_test.go tests/compatibility_test.go
go tool cover -html=coverage.out -o coverage.html
.PHONY: diff
diff: ## git diff
$(call print-target)
git diff --exit-code
RES=$$(git status --porcelain) ; if [ -n "$$RES" ]; then echo $$RES && exit 1 ; fi
.PHONY: docs
docs: ## go docs
$(call print-target)
go doc github.com/davidallendj/magellan/cmd
go doc github.com/davidallendj/magellan/internal
go doc github.com/davidallendj/magellan/pkg/crawler
.PHONY: emulator
emulator:
$(call print-target)
./emulator/setup.sh
magellan.1: README.md inst
$(GOPATH)/bin/go-md2man -in $< -out $@
.PHONY: man
man:
$(call print-target)
$(MAKE) -f $(firstword $(MAKEFILE_LIST)) magellan.1
define print-target
@printf "Executing target: \033[36m$@\033[0m\n"
endef