-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
208 lines (169 loc) · 7.67 KB
/
Makefile
File metadata and controls
208 lines (169 loc) · 7.67 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
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
208
SHELL := /bin/bash
ifneq "$(DEVBOX_CONFIG_DIR)" ""
# Within devbox
RUN_DEVBOX:=
else ifneq ($(shell which devbox 2>/dev/null),)
# Devbox available, use it.
RUN_DEVBOX:=devbox run
else
# No devbox, fall back to regular commands.
RUN_DEVBOX:=
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: tag
tag: ## Bumps version, generates changelog, tags, and pushes. Usage: make tag BUMP=<major|minor|patch>
@./scripts/tag.sh $(BUMP)
.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: cli-tests linter-tests ## Runs the tests.
.PHONY: cli-tests
cli-tests: check-binaries ## Runs the CLI tests.
$(RUN_DEVBOX) go test -v ./...
.PHONY: linter-tests
linter-tests: check-binaries ## Runs the linter rules tests.
$(RUN_DEVBOX) go run ./cmd/gcx/ dev lint test ./internal/linter/bundle/gcx/
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/gcx`.
$(RUN_DEVBOX) go build \
-buildvcs=false \
-ldflags="${VERSION_FLAGS}" \
-o bin/gcx \
./cmd/gcx
.PHONY: install
install: build ## Installs the binary into `$GOPATH/bin`.
$(eval GOPATH := $(or $(GOPATH),$(shell go env GOPATH)))
@test -n "$(GOPATH)" || { echo "GOPATH is not defined and 'go env GOPATH' returned empty"; exit 1; }
@mkdir -p "$(GOPATH)/bin"
@cp "bin/gcx" "$(GOPATH)/bin/gcx"
ifeq ($(shell uname),Darwin)
@codesign -s - "${GOPATH}/bin/gcx"
endif
.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: setup
setup: ## Sets up the local development environment (commit template, etc).
git config commit.template .gitmessage
@echo "Git commit template configured"
.PHONY: check-binaries
check-binaries: ## Check that the required binaries are present.
@go version >/dev/null 2>&1 || devbox version >/dev/null 2>&1 || (echo "ERROR: go or 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 linter-rules-reference ## Generates all references documentation pages.
.PHONY: reference-drift
reference-drift: cli-reference-drift env-var-reference-drift config-reference-drift linter-rules-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
@GCX_AGENT_MODE=false $(RUN_DEVBOX) CGO_ENABLED=0 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) CGO_ENABLED=0 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) CGO_ENABLED=0 go run scripts/config-reference/*.go "./docs/reference/configuration"
.PHONY: linter-rules-reference
linter-rules-reference: check-binaries ## Generates a reference for the built-in linter rules.
@rm ./docs/reference/linter-rules/index.md
@$(RUN_DEVBOX) CGO_ENABLED=0 go run scripts/linter-rules-reference/*.go "./docs/reference/linter-rules"
.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: linter-rules-reference-drift
linter-rules-reference-drift: linter-rules-reference ## Checks for drift in the generated linter rules reference.
@if ! git diff --exit-code --quiet HEAD ./docs/reference/linter-rules/ ; then \
echo "Drift detected in the linter rules reference."; \
echo 'Run `make linter-rules-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