-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
192 lines (161 loc) · 5.14 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
BIN_LOCATION ?= release/vela-k6
BIN_NAME ?= github.com/go-vela/vela-k6/cmd/vela-k6
MAIN_LOCATION ?= ./cmd/vela-k6
# capture the current date we build the application from
BUILD_DATE = $(shell date +%Y-%m-%dT%H:%M:%SZ)
# check if a git commit sha is already set
ifndef GITHUB_SHA
# capture the current git commit sha we build the application from
GITHUB_SHA = $(shell git rev-parse HEAD)
endif
# check if a git tag is already set
ifndef GITHUB_TAG
# capture the current git tag we build the application from
GITHUB_TAG = $(shell git describe --tag --abbrev=0)
endif
# check if a go version is already set
ifndef GOLANG_VERSION
# capture the current go version we build the application from
GOLANG_VERSION = $(shell go version | awk '{ print $$3 }')
endif
ifeq ($(shell uname -s), Darwin)
GO_ENVS = GOOS=darwin
else
GO_ENVS = GOOS=linux GOARCH=amd64
endif
# create a list of linker flags for building the golang application
LD_FLAGS = -X github.com/go-vela/vela-k6/version.Commit=${GITHUB_SHA} -X github.com/go-vela/vela-k6/version.Date=${BUILD_DATE} -X github.com/go-vela/vela-k6/version.Go=${GOLANG_VERSION} -X github.com/go-vela/vela-k6/version.Tag=${GITHUB_TAG}
.PHONY: deps
deps: go-tidy golangci-lint ## Install golang dependencies for the application
.PHONY: check
check: go-tidy check-all lint-all ## Run all lint checks
.PHONY: clean
clean: clean-all go-tidy ## Clean up the application and test output
.PHONY: build
build: build-all ## Compile the application
.PHONY: docker
docker: build-linux docker-build ## Build a Docker image for local testing
.PHONY: test
test: test-all ## Run all unit tests
.PHONY: coverage
coverage: test-all coverage-all ## Run tests and coverage visualization (only for local dev)
.PHONY: help
help: ## Show all valid options
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[a-zA-Z0-9_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
.PHONY: start
start: ## Run application
@go run $(MAIN_LOCATION)
.PHONY: check-all
check-all:
@go vet ./...
@go fmt ./...
.PHONY: lint-all
lint-all: golangci-lint mdl yamllint hadolint shellcheck codespell
.PHONY: clean-all
clean-all:
@rm -f perf-test.json
@rm -f ./$(BIN_NAME)
@rm -f coverage.*
@rm -f unit-tests.xml
.PHONY: test-all
test-all:
@go test ./... -coverprofile=coverage.out
.PHONY: coverage-all
coverage-all:
@go tool cover -html=coverage.out
.PHONY: go-tidy
go-tidy:
@go mod tidy
.PHONY: golangci-lint
golangci-lint:
ifeq ($(strip $(shell which golangci-lint)),)
ifeq ($(shell uname -s), Darwin)
@brew install golangci-lint
endif
endif
@golangci-lint run ./...
@echo finished running golangci-lint
.PHONY: codespell
codespell:
ifeq ($(strip $(shell which codespell)),)
ifneq ($(strip $(shell which pip)),)
@pip install codespell
endif
endif
@codespell --skip node_modules,.git,public,package-lock.json,vendor
@echo finished running codespell
.PHONY: yamllint
yamllint:
ifeq ($(strip $(shell which yamllint)),)
ifneq ($(strip $(shell which pip)),)
@pip install yamllint
endif
endif
@yamllint -f colored -c .yamllint.yml .
@echo finished running yamllint
.PHONY: hadolint
hadolint:
ifeq ($(strip $(shell which hadolint)),)
ifeq ($(shell uname -s), Darwin)
@brew install hadolint
endif
endif
@hadolint --ignore DL3018 --ignore DL3007 ./Dockerfile
@echo finished running hadolint
.PHONY: shellcheck
shellcheck:
ifeq ($(strip $(shell which shellcheck)),)
ifeq ($(shell uname -s), Darwin)
@brew install shellcheck
endif
endif
@find . -name \*.sh ! -path "./vendor/*" | xargs -I {} shellcheck {}
@echo finished running shellcheck
.PHONY: mdl
mdl:
ifeq ($(strip $(shell which mdl)),)
ifneq ($(strip $(shell which gem)),)
@gem install mdl
endif
endif
@find . -name '*.md' ! -name "DOCS.md" ! -path "./vendor/*" | xargs mdl --rules ~MD007,~MD013
# ignore top level header for docs
@mdl DOCS.md --rules ~MD007,~MD013,~MD002
@echo finished running mdl
# The `build-all` target is intended to compile
# the Go source code into a binary.
#
# Usage: `make build`
.PHONY: build-all
build-all:
@echo
@echo "### Building release/vela-k6 binary"
${GO_ENVS} CGO_ENABLED=0 go build -a -ldflags '${LD_FLAGS}' -o $(BIN_LOCATION) $(BIN_NAME)
# The `build-static-ci` target is intended to compile
# the Go source code into a statically linked binary
# when used within a CI environment.
#
# Usage: `make build-static-ci`
.PHONY: build-static-ci
build-static-ci:
@echo
@echo "### Building CI static release/vela-k6 binary"
go build -a -ldflags '-s -w -extldflags "-static" ${LD_FLAGS}' -o $(BIN_LOCATION) $(BIN_NAME)
# The `build-linux` target is intended to compile
# the Go source code into a linux-compatible binary.
#
# Usage: `make build-linux`
.PHONY: build-linux
build-linux:
@echo
@echo "### Building release/vela-k6 binary for linux"
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -a -ldflags '${LD_FLAGS}' -o $(BIN_LOCATION) $(BIN_NAME)
# The `docker-build` target is intended to build
# the Docker image for the plugin.
#
# Usage: `make docker-build`
.PHONY: docker-build
docker-build: build-linux
@echo
@echo "### Building vela-k6:local image"
@docker build --no-cache -t vela-k6:local .