-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathMakefile
More file actions
173 lines (140 loc) · 6.06 KB
/
Makefile
File metadata and controls
173 lines (140 loc) · 6.06 KB
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
SHELL := /bin/bash
# Within devbox
ifneq "$(DEVBOX_CONFIG_DIR)" ""
RUN_DEVBOX:=
else # Normal shell
RUN_DEVBOX:=devbox run
endif
##@ General
# The help target prints out all targets with their descriptions organized
# beneath their categories. The categories are represented by '##@' and the
# target descriptions by '##'. The awk commands is responsible for reading the
# entire set of makefiles included in this invocation, looking for lines of the
# file as xyz: ## something, and then pretty-format the target and help. Then,
# if there's a line with ##@ something, that gets pretty-printed as a category.
# More info on the usage of ANSI control characters for terminal formatting:
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
# More info on the awk command:
# http://linuxcommand.org/lc3_adv_awk.php
.PHONY: help
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
##@ Development
.PHONY: all
all: lint tests build docs ## Lints, tests, builds, and generates the documentation.
.PHONY: lint
lint: check-binaries ## Lints the code base.
$(RUN_DEVBOX) golangci-lint run -c .golangci.yaml
.PHONY: tests
tests: check-binaries ## Runs the tests.
$(RUN_DEVBOX) go test -v ./...
GIT_REVISION ?= $(shell git rev-parse --short HEAD)
GIT_VERSION ?= $(shell git describe --tags --exact-match 2>/dev/null || echo "")
BUILD_DATE ?= $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
VERSION_FLAGS := -X main.version=${GIT_VERSION} -X main.commit=${GIT_REVISION} -X main.date=${BUILD_DATE}
.PHONY: build
build: check-binaries ## Builds the binary into the `./bin/grafanactl`.
$(RUN_DEVBOX) go build \
-buildvcs=false \
-ldflags="${VERSION_FLAGS}" \
-o bin/grafanactl \
./cmd/grafanactl
.PHONY: install
install: build ## Installs the binary into `$GOPATH/bin`.
ifndef GOPATH
@echo "GOPATH is not defined"
exit 1
endif
@cp "bin/grafanactl" "${GOPATH}/bin/grafanactl"
.PHONY: deps
deps: check-binaries ## Installs the dependencies.
$(RUN_DEVBOX) go mod vendor
$(RUN_DEVBOX) pip install -qq -r requirements.txt
.PHONY: clean
clean: ## Cleans the project.
rm -rf bin
rm -rf vendor
rm -rf .devbox
rm -rf .venv
.PHONY: check-binaries
check-binaries: ## Check that the required binaries are present.
@devbox version >/dev/null 2>&1 || (echo "ERROR: devbox is required. See https://www.jetify.com/devbox/docs/quickstart/"; exit 1)
##@ Documentation
.PHONY: docs
docs: check-binaries reference ## Generates the documentation.
$(RUN_DEVBOX) mkdocs build -f mkdocs.yml -d ./build/documentation
.PHONY: reference
reference: cli-reference env-var-reference config-reference ## Generates all references documentation pages.
.PHONY: reference-drift
reference-drift: cli-reference-drift env-var-reference-drift config-reference-drift ## Checks for drift in all references documentation pages.
.PHONY: cli-reference
cli-reference: check-binaries ## Generates a reference for the CLI.
@rm -rf ./docs/reference/cli
@$(RUN_DEVBOX) go run scripts/cmd-reference/*.go "./docs/reference/cli"
.PHONY: env-var-reference
env-var-reference: check-binaries ## Generates an environment variables reference.
@rm -rf ./docs/reference/environment-variables
@$(RUN_DEVBOX) go run scripts/env-vars-reference/*.go "./docs/reference/environment-variables"
.PHONY: config-reference
config-reference: check-binaries ## Generates a reference for the configuration file.
@rm -rf ./docs/reference/configuration
@$(RUN_DEVBOX) go run scripts/config-reference/*.go "./docs/reference/configuration"
.PHONY: cli-reference-drift
cli-reference-drift: cli-reference ## Checks for drift in the generated CLI reference.
@if ! git diff --exit-code --quiet HEAD ./docs/reference/cli/ ; then \
echo "Drift detected in the generated CLI reference."; \
echo 'Run `make cli-reference` and commit the modified files.'; \
exit 1; \
fi
.PHONY: env-var-reference-drift
env-var-reference-drift: env-var-reference ## Checks for drift in the generated environment variables reference.
@if ! git diff --exit-code --quiet HEAD ./docs/reference/environment-variables/ ; then \
echo "Drift detected in the generated environment variables reference."; \
echo 'Run `make env-var-reference` and commit the modified files.'; \
exit 1; \
fi
.PHONY: config-reference-drift
config-reference-drift: config-reference ## Checks for drift in the generated config file reference.
@if ! git diff --exit-code --quiet HEAD ./docs/reference/configuration/ ; then \
echo "Drift detected in the generated config reference."; \
echo 'Run `make config-reference` and commit the modified files.'; \
exit 1; \
fi
.PHONY: serve-docs
serve-docs: check-binaries ## Serves the documentation and watches for changes.
$(RUN_DEVBOX) mkdocs serve -f mkdocs.yml
##@ Integration Testing
.PHONY: test-env-up
test-env-up: ## Starts the docker-compose test environment (Grafana + MySQL).
@echo "Starting test environment..."
@docker-compose up -d
@echo "Waiting for services to be healthy..."
@for i in {1..30}; do \
if docker-compose ps | grep -q "healthy"; then \
echo "Services are healthy!"; \
echo ""; \
echo "Grafana is available at: http://localhost:3000"; \
echo "Credentials: admin/admin"; \
echo ""; \
echo "Test with: make test-env-status"; \
exit 0; \
fi; \
echo -n "."; \
sleep 1; \
done; \
echo ""; \
echo "Warning: Services may still be starting up. Check with: docker-compose ps"
.PHONY: test-env-down
test-env-down: ## Stops and removes the docker-compose test environment.
@echo "Stopping test environment..."
@docker-compose down
.PHONY: test-env-clean
test-env-clean: ## Stops the test environment and removes all volumes.
@echo "Stopping test environment and removing volumes..."
@docker-compose down -v
.PHONY: test-env-status
test-env-status: ## Shows the status of the test environment services.
@docker-compose ps
.PHONY: test-env-logs
test-env-logs: ## Shows logs from the test environment (Grafana and MySQL).
@docker-compose logs -f