Skip to content

Commit 81fd8f4

Browse files
authored
Makefile: refactoring .PHONY (#85440)
1 parent f8275b5 commit 81fd8f4

File tree

1 file changed

+44
-2
lines changed

1 file changed

+44
-2
lines changed

Makefile

+44-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ WIRE_TAGS = "oss"
77
-include local/Makefile
88
include .bingo/Variables.mk
99

10-
.PHONY: all deps-go deps-js deps build-go build-backend build-server build-cli build-js build build-docker-full build-docker-full-ubuntu lint-go golangci-lint test-go test-js gen-ts test run run-frontend clean devenv devenv-down protobuf drone help gen-go gen-cue fix-cue gen-feature-toggles
1110

1211
GO = go
1312
GO_FILES ?= ./pkg/... ./pkg/apiserver/... ./pkg/apimachinery/... ./pkg/promlib/...
@@ -19,17 +18,22 @@ targets := $(shell echo '$(sources)' | tr "," " ")
1918

2019
GO_INTEGRATION_TESTS := $(shell find ./pkg -type f -name '*_test.go' -exec grep -l '^func TestIntegration' '{}' '+' | grep -o '\(.*\)/' | sort -u)
2120

21+
.PHONY: all
2222
all: deps build
2323

2424
##@ Dependencies
2525

26+
.PHONY: deps-go
2627
deps-go: ## Install backend dependencies.
2728
$(GO) run build.go setup
2829

30+
.PHONY: deps-js
2931
deps-js: node_modules ## Install frontend dependencies.
3032

33+
.PHONY: deps
3134
deps: deps-js ## Install all dependencies.
3235

36+
.PHONY: node_modules
3337
node_modules: package.json yarn.lock ## Install node modules.
3438
@echo "install frontend dependencies"
3539
YARN_ENABLE_PROGRESS_BARS=false yarn install --immutable
@@ -47,6 +51,7 @@ $(MERGED_SPEC_TARGET): swagger-oss-gen swagger-enterprise-gen $(NGALERT_SPEC_TAR
4751
# known conflicts DsPermissionType, AddApiKeyCommand, Json, Duration (identical models referenced by both specs)
4852
$(SWAGGER) mixin -q $(SPEC_TARGET) $(ENTERPRISE_SPEC_TARGET) $(NGALERT_SPEC_TARGET) --ignore-conflicts -o $(MERGED_SPEC_TARGET)
4953

54+
.PHONY: swagger-oss-gen
5055
swagger-oss-gen: $(SWAGGER) ## Generate API Swagger specification
5156
@echo "re-generating swagger for OSS"
5257
rm -f $(SPEC_TARGET)
@@ -58,6 +63,7 @@ swagger-oss-gen: $(SWAGGER) ## Generate API Swagger specification
5863
--exclude-tag=enterprise
5964

6065
# this file only exists if enterprise is enabled
66+
.PHONY: swagger-enterprise-gen
6167
ENTERPRISE_EXT_FILE = pkg/extensions/ext.go
6268
ifeq ("$(wildcard $(ENTERPRISE_EXT_FILE))","") ## if enterprise is not enabled
6369
swagger-enterprise-gen:
@@ -74,11 +80,14 @@ swagger-enterprise-gen: $(SWAGGER) ## Generate API Swagger specification
7480
--include-tag=enterprise
7581
endif
7682

83+
.PHONY: swagger-gen
7784
swagger-gen: gen-go $(MERGED_SPEC_TARGET) swagger-validate
7885

86+
.PHONY: swagger-validate
7987
swagger-validate: $(MERGED_SPEC_TARGET) $(SWAGGER) ## Validate API spec
8088
$(SWAGGER) validate --skip-warnings $(<)
8189

90+
.PHONY: swagger-clean
8291
swagger-clean:
8392
rm -f $(SPEC_TARGET) $(MERGED_SPEC_TARGET) $(OAPI_SPEC_TARGET)
8493

@@ -97,15 +106,18 @@ lefthook-uninstall: $(LEFTHOOK)
97106
##@ OpenAPI 3
98107
OAPI_SPEC_TARGET = public/openapi3.json
99108

109+
.PHONY: openapi3-gen
100110
openapi3-gen: swagger-gen ## Generates OpenApi 3 specs from the Swagger 2 already generated
101111
$(GO) run scripts/openapi3/openapi3conv.go $(MERGED_SPEC_TARGET) $(OAPI_SPEC_TARGET)
102112

103113
##@ Building
114+
.PHONY: gen-cue
104115
gen-cue: ## Do all CUE/Thema code generation
105116
@echo "generate code from .cue files"
106117
go generate ./kinds/gen.go
107118
go generate ./public/app/plugins/gen.go
108119

120+
.PHONY: gen-feature-toggles
109121
gen-feature-toggles:
110122
## First go test run fails because it will re-generate the feature toggles.
111123
## Second go test run will compare the generated files and pass.
@@ -117,41 +129,50 @@ gen-feature-toggles:
117129
go test -v ./pkg/services/featuremgmt/...; \
118130
fi
119131

132+
.PHONY: gen-go
120133
gen-go:
121134
@echo "generate go files"
122135
$(GO) run ./pkg/build/wire/cmd/wire/main.go gen -tags $(WIRE_TAGS) ./pkg/server
123136

137+
.PHONY: fix-cue
124138
fix-cue: $(CUE)
125139
@echo "formatting cue files"
126140
$(CUE) fix kinds/**/*.cue
127141
$(CUE) fix public/app/plugins/**/**/*.cue
128142

143+
.PHONY: gen-jsonnet
129144
gen-jsonnet:
130145
go generate ./devenv/jsonnet
131146

147+
.PHONY: build-go
132148
build-go: gen-go ## Build all Go binaries.
133149
@echo "build go files"
134150
$(GO) run build.go $(GO_BUILD_FLAGS) build
135151

152+
.PHONY: build-backend
136153
build-backend: ## Build Grafana backend.
137154
@echo "build backend"
138155
$(GO) run build.go $(GO_BUILD_FLAGS) build-backend
139156

157+
.PHONY: build-server
140158
build-server: ## Build Grafana server.
141159
@echo "build server"
142160
$(GO) run build.go $(GO_BUILD_FLAGS) build-server
143161

162+
.PHONY: build-cli
144163
build-cli: ## Build Grafana CLI application.
145164
@echo "build grafana-cli"
146165
$(GO) run build.go $(GO_BUILD_FLAGS) build-cli
147166

167+
.PHONY: build-js
148168
build-js: ## Build frontend assets.
149169
@echo "build frontend"
150170
yarn run build
151171
yarn run plugins:build-bundled
152172

153173
PLUGIN_ID ?=
154174

175+
.PHONY: build-plugin-go
155176
build-plugin-go: ## Build decoupled plugins
156177
@echo "build plugin $(PLUGIN_ID)"
157178
@cd pkg/tsdb; \
@@ -161,11 +182,14 @@ build-plugin-go: ## Build decoupled plugins
161182
fi; \
162183
mage -v buildplugin $(PLUGIN_ID)
163184

185+
.PHONY: build
164186
build: build-go build-js ## Build backend and frontend.
165187

188+
.PHONY: run
166189
run: $(BRA) ## Build and run web server on filesystem changes.
167190
$(BRA) run
168191

192+
.PHONY: run-frontend
169193
run-frontend: deps-js ## Fetch js dependencies and watch frontend for rebuild
170194
yarn start
171195

@@ -217,22 +241,27 @@ test-go-integration-memcached: ## Run integration tests for memcached cache.
217241
$(GO) clean -testcache
218242
MEMCACHED_HOSTS=localhost:11211 $(GO) test -run IntegrationMemcached -covermode=atomic -timeout=2m $(GO_INTEGRATION_TESTS)
219243

244+
.PHONY: test-js
220245
test-js: ## Run tests for frontend.
221246
@echo "test frontend"
222247
yarn test
223248

249+
.PHONY: test
224250
test: test-go test-js ## Run all tests.
225251

226252
##@ Linting
253+
.PHONY: golangci-lint
227254
golangci-lint: $(GOLANGCI_LINT)
228255
@echo "lint via golangci-lint"
229256
$(GOLANGCI_LINT) run \
230257
--config .golangci.toml \
231258
$(GO_FILES)
232259

260+
.PHONY: lint-go
233261
lint-go: golangci-lint ## Run all code checks for backend. You can use GO_FILES to specify exact files to check
234262

235263
# with disabled SC1071 we are ignored some TCL,Expect `/usr/bin/env expect` scripts
264+
.PHONY: shellcheck
236265
shellcheck: $(SH_FILES) ## Run checks for shell scripts.
237266
@docker run --rm -v "$$PWD:/mnt" koalaman/shellcheck:stable \
238267
$(SH_FILES) -e SC1071 -e SC2162
@@ -242,6 +271,7 @@ shellcheck: $(SH_FILES) ## Run checks for shell scripts.
242271
TAG_SUFFIX=$(if $(WIRE_TAGS)!=oss,-$(WIRE_TAGS))
243272
PLATFORM=linux/amd64
244273

274+
.PHONY: build-docker-full
245275
build-docker-full: ## Build Docker image for development.
246276
@echo "build docker container"
247277
tar -ch . | \
@@ -255,6 +285,7 @@ build-docker-full: ## Build Docker image for development.
255285
--tag grafana/grafana$(TAG_SUFFIX):dev \
256286
$(DOCKER_BUILD_ARGS)
257287

288+
.PHONY: build-docker-full-ubuntu
258289
build-docker-full-ubuntu: ## Build Docker image based on Ubuntu for development.
259290
@echo "build docker container"
260291
tar -ch . | \
@@ -274,6 +305,7 @@ build-docker-full-ubuntu: ## Build Docker image based on Ubuntu for development.
274305

275306
# create docker-compose file with provided sources and start them
276307
# example: make devenv sources=postgres,auth/openldap
308+
.PHONY: devenv
277309
ifeq ($(sources),)
278310
devenv:
279311
@printf 'You have to define sources for this command \nexample: make devenv sources=postgres,openldap\n'
@@ -287,15 +319,18 @@ devenv: devenv-down ## Start optional services, e.g. postgres, prometheus, and e
287319
docker-compose up -d --build
288320
endif
289321

322+
.PHONY: devenv-down
290323
devenv-down: ## Stop optional services.
291324
@cd devenv; \
292325
test -f docker-compose.yaml && \
293326
docker-compose down || exit 0;
294327

328+
.PHONY: devenv-postgres
295329
devenv-postgres:
296330
@cd devenv; \
297331
sources=postgres_tests
298332

333+
.PHONY: devenv-mysql
299334
devenv-mysql:
300335
@cd devenv; \
301336
sources=mysql_tests
@@ -307,18 +342,21 @@ devenv-mysql:
307342
# go-gettable dependency and so getting it installed can be inconvenient.
308343
#
309344
# If you are working on changes to protobuf interfaces you may either use
310-
# this target or run the individual scripts below directly.
345+
# this target or run the individual scripts below directly
346+
.PHONY: protobuf
311347
protobuf: ## Compile protobuf definitions
312348
bash scripts/protobuf-check.sh
313349
bash pkg/plugins/backendplugin/pluginextensionv2/generate.sh
314350
bash pkg/plugins/backendplugin/secretsmanagerplugin/generate.sh
315351
bash pkg/services/store/entity/generate.sh
316352

353+
.PHONY: clean
317354
clean: ## Clean up intermediate build artifacts.
318355
@echo "cleaning"
319356
rm -rf node_modules
320357
rm -rf public/build
321358

359+
.PHONY: gen-ts
322360
gen-ts:
323361
@echo "generating TypeScript definitions"
324362
go get github.com/tkrajina/typescriptify-golang-structs/[email protected]
@@ -328,18 +366,22 @@ gen-ts:
328366
# This repository's configuration is protected (https://readme.drone.io/signature/).
329367
# Use this make target to regenerate the configuration YAML files when
330368
# you modify starlark files.
369+
.PHONY: drone
331370
drone: $(DRONE)
332371
bash scripts/drone/env-var-check.sh
333372
$(DRONE) starlark --format
334373
$(DRONE) lint .drone.yml --trusted
335374
$(DRONE) --server https://drone.grafana.net sign --save grafana/grafana
336375

337376
# Generate an Emacs tags table (https://www.gnu.org/software/emacs/manual/html_node/emacs/Tags-Tables.html) for Starlark files.
377+
.PHONY: scripts/drone/TAGS
338378
scripts/drone/TAGS: $(shell find scripts/drone -name '*.star')
339379
etags --lang none --regex="/def \(\w+\)[^:]+:/\1/" --regex="/\s*\(\w+\) =/\1/" $^ -o $@
340380

381+
.PHONY: format-drone
341382
format-drone:
342383
buildifier --lint=fix -r scripts/drone
343384

385+
.PHONY: help
344386
help: ## Display this help.
345387
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

0 commit comments

Comments
 (0)