-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
132 lines (103 loc) · 4.32 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
123
124
125
126
127
128
129
130
131
132
# --- Required ----------------------------------------------------------------
export PATH := $(PWD)/bin:$(PATH) # ./bin to $PATH
export SHELL := bash # Default Shell
define install_go_bin
@ which $(1) 2>&1 1>/dev/null || GOBIN=$(PWD)/bin go install $(2)
endef
.DEFAULT_GOAL := help
# Generate Artifacts ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
generate: ## Generate Assets
$(MAKE) generate-tests
$(MAKE) generate-mirror-table
generate-tests: ## Generates Assets at testdata
go run ./cmd/internal/tests/ "$(PWD)/testdata"
generate-mirror-table: ## Generate Asset MIRROR_FUNCS.md
go run ./cmd/internal/mirror-table/ > "$(PWD)/MIRROR_FUNCS.md"
# Build Artifacts ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
build: ## Build binary
@ go build -trimpath -ldflags="-w -s" -o bin/mirror ./cmd/mirror/
build-race: ## Build binary with race flag
@ go build -race -trimpath -ldflags="-w -s" -o bin/mirror ./cmd/mirror/
install: ## Installs binary
@ go install -trimpath -v -ldflags="-w -s" ./cmd/mirror
# Run Tests ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tests: ## Run Tests (Summary)
@ go test -v -count=1 -race \
-failfast \
-parallel=2 \
-timeout=1m \
-covermode=atomic \
-coverprofile=coverage.cov ./...
tests-summary: ## Run Tests, but shows summary
tests-summary: bin/tparse
@ go test -v -count=1 -race \
-failfast \
-parallel=2 \
-timeout=1m \
-covermode=atomic \
-coverprofile=coverage.cov --json ./... | tparse -all
# Linter ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lints: ## Run golangci-lint
lints: bin/golangci-lint
lints:
golangci-lint run --no-config ./... --exclude-dirs "^(cmd|testdata)"
cover: ## Run Coverage
@ go tool cover -html=coverage.cov
# Other ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test-release: bin/goreleaser
goreleaser release --help
goreleaser release --skip=publish --skip=validate --clean
# Install ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bin/tparse: ## Installs [email protected] (if not exists)
bin/tparse: INSTALL_URL=github.com/mfridman/[email protected]
bin/tparse:
$(call install_go_bin, tparse, $(INSTALL_URL))
bin/golangci-lint: ## Installs [email protected] (if not exists)
bin/golangci-lint: INSTALL_URL=github.com/golangci/[email protected]
bin/golangci-lint:
$(call install_go_bin, golangci-lint, $(INSTALL_URL))
bin/goreleaser: ## Installs [email protected] (if not exists)
bin/goreleaser: INSTALL_URL=github.com/goreleaser/[email protected]
bin/goreleaser:
$(call install_go_bin, goreleaser, $(INSTALL_URL))
# Help ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
help: dep-gawk
@ echo "=============================================================================="
@ echo " Makefile: github.com/butuzov/mirror "
@ echo "=============================================================================="
@ cat $(MAKEFILE_LIST) | \
grep -E '^# ~~~ .*? [~]+$$|^[a-zA-Z0-9_-]+:.*?## .*$$' | \
gawk '{if ( $$1=="#" ) { \
match($$0, /^# ~~~ (.+?) [~]+$$/, a);\
{print "\n", a[1], ""}\
} else { \
match($$0, /^([a-zA-Z/_-]+):.*?## (.*)$$/, a); \
{printf " - \033[32m%-20s\033[0m %s\n", a[1], a[2]} \
}}'
@ echo ""
# Helper Methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dep-gawk:
@ if [ -z "$(shell command -v gawk)" ]; then \
if [ -x /usr/local/bin/brew ]; then $(MAKE) _brew_gawk_install; exit 0; fi; \
if [ -x /usr/bin/apt-get ]; then $(MAKE) _ubuntu_gawk_install; exit 0; fi; \
if [ -x /usr/bin/yum ]; then $(MAKE) _centos_gawk_install; exit 0; fi; \
if [ -x /sbin/apk ]; then $(MAKE) _alpine_gawk_install; exit 0; fi; \
echo "GNU Awk Required.";\
exit 1; \
fi
_brew_gawk_install:
@ echo "Installing gawk using brew... "
@ brew install gawk --quiet
@ echo "done"
_ubuntu_gawk_install:
@ echo "Installing gawk using apt-get... "
@ apt-get -q install gawk -y
@ echo "done"
_alpine_gawk_install:
@ echo "Installing gawk using yum... "
@ apk add --update --no-cache gawk
@ echo "done"
_centos_gawk_install:
@ echo "Installing gawk using yum... "
@ yum install -q -y gawk;
@ echo "done"