-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
207 lines (161 loc) · 5.98 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
_PROJECT_DIRECTORY = $(dir $(realpath $(firstword $(MAKEFILE_LIST))))
_GOLANG_IMAGE = golang:1.22.0
_PROJECTNAME = furyctl
_GOARCH = "amd64"
_BIN_OPEN = "open"
NETRC_FILE ?= ~/.netrc
ifeq ("$(shell uname -s)", "Linux")
_BIN_OPEN = "xdg-open"
endif
ifeq ("$(shell uname -m)", "arm64")
_GOARCH = "arm64"
endif
#1: docker image
#2: make target
define run-docker
@docker run --rm \
-e CGO_ENABLED=0 \
-e GOARCH=${_GOARCH} \
-e GOOS=linux \
-w /app \
-v ${NETRC_FILE}:/root/.netrc \
-v ${_PROJECT_DIRECTORY}:/app \
$(1) $(2)
endef
#1: message
define yes-or-no
@while true; do \
read -r -p ${1}" [y/n]: " yn ; \
case "$${yn}" in \
[Yy]) break ;; \
[Nn]) echo "Aborted, exiting..."; exit 1 ;; \
esac \
done
endef
.PHONY: env tools
env:
@echo 'export CGO_ENABLED=0'
@echo 'export GOARCH=${_GOARCH}'
@grep -v '^#' .env | sed 's/^/export /'
tools:
@go install github.com/daixiang0/[email protected]
@go install github.com/golangci/golangci-lint/cmd/[email protected]
@go install github.com/google/[email protected]
@go install github.com/nikolaydubina/[email protected]
@go install github.com/onsi/ginkgo/v2/[email protected]
@go install golang.org/x/tools/cmd/[email protected]
@go install mvdan.cc/[email protected]
@go install github.com/momaek/[email protected]
.PHONY: mod-download mod-tidy mod-verify
mod-download:
@go mod download
mod-tidy:
@go mod tidy
mod-verify:
@go mod verify
.PHONY: mod-check-upgrades mod-upgrade
mod-check-upgrades:
@go list -mod=readonly -u -f "{{if (and (not (or .Main .Indirect)) .Update)}}{{.Path}}: {{.Version}} -> {{.Update.Version}}{{end}}" -m all
mod-upgrade:
@go get -u ./... && go mod tidy
.PHONY: license-add license-check
license-add:
@addlicense -c "SIGHUP s.r.l" -y 2017-present -v -l bsd \
-ignore "scripts/e2e/libs/**/*" \
-ignore "vendor/**/*" \
-ignore "*.gen.go" \
-ignore ".idea/*" \
-ignore ".vscode/*" \
-ignore "*.js" \
-ignore "kind-config.yaml" \
-ignore ".husky/**/*" \
-ignore ".go/**/*" \
.
license-check:
@addlicense -c "SIGHUP s.r.l" -y 2017-present -v -l bsd \
-ignore "scripts/e2e/libs/**/*" \
-ignore "vendor/**/*" \
-ignore "*.gen.go" \
-ignore ".idea/*" \
-ignore ".vscode/*" \
-ignore "*.js" \
-ignore "kind-config.yaml" \
-ignore ".husky/**/*" \
-ignore ".go/**/*" \
--check .
.PHONY: format-go fmt fumpt imports gci formattag
format-go: fmt fumpt imports gci formattag
fmt:
@find . -name "*.go" -type f -not -path '*/vendor/*' \
| sed 's/^\.\///g' \
| xargs -I {} -S 5000 sh -c 'echo "formatting {}.." && gofmt -w -s {}'
fumpt:
@find . -name "*.go" -type f -not -path '*/vendor/*' \
| sed 's/^\.\///g' \
| xargs -I {} -S 5000 sh -c 'echo "formatting {}.." && gofumpt -w -extra {}'
imports:
@goimports -v -w -e -local github.com/sighupio main.go
@goimports -v -w -e -local github.com/sighupio cmd/
@goimports -v -w -e -local github.com/sighupio internal/
gci:
@find . -name "*.go" -type f -not -path '*/vendor/*' \
| sed 's/^\.\///g' \
| xargs -I {} -S 5000 sh -c 'echo "formatting imports for {}.." && \
gci write --skip-generated -s standard -s default -s "Prefix(github.com/sighupio)" {}'
formattag:
@find . -name "*.go" -type f -not -path '*/vendor/*' \
| sed 's/^\.\///g' \
| xargs -I {} -S 5000 sh -c 'formattag -file {}'
.PHONY: lint lint-go
lint: lint-go
lint-go:
@GOFLAGS=-mod=mod golangci-lint -v run --color=always --max-same-issues 25 --config=${_PROJECT_DIRECTORY}/.rules/.golangci.yml ./...
.PHONY: test-unit test-integration test-e2e test-all show-coverage
test-unit:
@GOFLAGS=-mod=mod go test -v -tags=unit ./...
test-integration:
@GOFLAGS=-mod=mod go test -v -tags=integration -timeout 120s ./...
test-e2e:
@export KFD_AUTH_DEX_CONNECTORS_GITHUB_CLIENT_ID=dummy && \
export KFD_AUTH_DEX_CONNECTORS_GITHUB_CLIENT_SECRET=dummy && \
export KFD_BASIC_AUTH_PASSWORD=dummy && \
export KFD_AUTH_POMERIUM_COOKIE_SECRET=dummy && \
export KFD_AUTH_POMERIUM_IDP_CLIENT_SECRET=dummy && \
export KFD_AUTH_POMERIUM_SHARED_SECRET=dummy && \
GOFLAGS=-mod=mod ginkgo run -vv --trace -tags=e2e -timeout 600s -p test/e2e
test-expensive:
$(call yes-or-no, "WARNING: This test will create a cluster on AWS. Are you sure you want to continue?")
@GOFLAGS=-mod=mod ginkgo run -vv --trace -tags=expensive -timeout 36000s --procs=4 test/expensive
test-expensive-ekscluster:
$(call yes-or-no, "WARNING: This test will create a cluster on AWS. Are you sure you want to continue?")
@GOFLAGS=-mod=mod ginkgo run -vv --trace -tags=expensive -timeout 36000s --procs=4 test/expensive/ekscluster
test-expensive-kfddistribution:
@GOFLAGS=-mod=mod ginkgo run -vv --trace -tags=expensive -timeout 36000s --procs=4 test/expensive/kfddistribution
test-expensive-onpremises:
@GOFLAGS=-mod=mod ginkgo run -vv --trace -tags=expensive -timeout 36000s --procs=4 test/expensive/onpremises
test-most:
@GOFLAGS=-mod=mod ginkgo run -vv --trace -coverpkg=./... -covermode=count -coverprofile=coverage.out -tags=unit,integration,e2e,expensive --skip-package=expensive -timeout 300s -p ./...
test-all:
$(call yes-or-no, "WARNING: This test will create a cluster on AWS. Are you sure you want to continue?")
@GOFLAGS=-mod=mod ginkgo run -vv --trace -coverpkg=./... -covermode=count -coverprofile=coverage.out -tags=unit,integration,e2e,expensive -timeout 300s --procs=2 ./...
show-coverage:
@go tool cover -html=coverage.out -o coverage.html
@go-cover-treemap -coverprofile coverage.out > coverage.svg && ${_BIN_OPEN} coverage.svg
.PHONY: clean build release
clean: deps
@if [ -d bin ]; then rm -rf bin; fi
@if [ -d dist ]; then rm -rf dist; fi
@if [ -f furyctl ]; then rm furyctl; fi
build:
@export GO_VERSION=$$(go version | cut -d ' ' -f 3) && \
goreleaser check && \
goreleaser release --verbose --snapshot --clean
release:
@export GO_VERSION=$$(go version | cut -d ' ' -f 3) && \
goreleaser check && \
goreleaser release --verbose --clean
# Helpers
%-docker:
$(call run-docker,${_GOLANG_IMAGE},make $*)
check-variable-%: # detection of undefined variables.
@[[ "${${*}}" ]] || (echo '*** Please define variable `${*}` ***' && exit 1)