-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathMakefile
More file actions
308 lines (269 loc) · 11.2 KB
/
Copy pathMakefile
File metadata and controls
308 lines (269 loc) · 11.2 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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
SHELL := /bin/bash
VENV := tests/.venv
PIP := $(VENV)/bin/pip
PYTHON := $(VENV)/bin/python3
BUILD_DIR := build
NODE_MODULES := node_modules
NODE_INSTALLED := $(NODE_MODULES)/.installed
.DEFAULT_GOAL := help
# ── Help ────────────────────────────────────────────────────────────
.PHONY: help
help:
@echo ""
@echo "OCP Virtualization Cookbook - Contributor Automation"
@echo "===================================================="
@echo ""
@echo "Setup:"
@echo " make setup Install all dependencies (test + docs)"
@echo " make check-deps Verify required tools are installed"
@echo ""
@echo "Documentation:"
@echo " make build Build HTML documentation"
@echo " make serve Start local preview server"
@echo " make watch Auto-rebuild on changes"
@echo " make dev Watch + serve for development"
@echo ""
@echo "Validation:"
@echo " make lint Check AsciiDoc syntax"
@echo " make check-links Validate links in built HTML"
@echo " make check-xrefs Verify xref links resolve"
@echo " make validate Run all validation checks"
@echo " make test-manifests Validate YAML manifests"
@echo " make test-manifests-dry Test manifests with oc dry-run"
@echo " make review-file FILE= Review a single .adoc file"
@echo " make review Review changed .adoc files"
@echo " make review-all Review all .adoc files"
@echo ""
@echo "Generate & Test:"
@echo " make generate TUTORIAL= Generate attachments from tutorial"
@echo " make generate-all Generate attachments for all tutorials"
@echo " make test Generate attachments, lint, and dry-run test"
@echo ""
@echo "Clean:"
@echo " make clean Remove virtual environment"
@echo " make clean-all Remove venv, build, node_modules"
@echo ""
@echo "Git Helpers:"
@echo " make branch NAME=xyz Create feature branch"
@echo " make pr Push and open PR"
@echo " make sync Rebase on upstream main"
@echo ""
# ── Setup ───────────────────────────────────────────────────────────
.PHONY: setup
setup: $(VENV)/bin/activate $(NODE_INSTALLED)
@echo "Setup complete. Run 'source $(VENV)/bin/activate' or use make targets."
$(VENV)/bin/activate:
python3 -m venv $(VENV)
$(PIP) install --upgrade pip
$(PIP) install -r tests/requirements.txt
@touch $(VENV)/bin/activate
$(NODE_INSTALLED):
@command -v pnpm > /dev/null 2>&1 || \
{ echo "pnpm not found. Installing..."; \
npm install -g pnpm; }
pnpm install
@touch $(NODE_INSTALLED)
.PHONY: check-deps
check-deps:
@echo "Checking required tools..."
@echo ""
@command -v node > /dev/null 2>&1 && \
echo "[OK] node ($$(node --version))" || \
{ echo "[MISSING] node — Install: https://nodejs.org or use nvm/brew"; EXIT=1; }
@command -v pnpm > /dev/null 2>&1 && \
echo "[OK] pnpm ($$(pnpm --version))" || \
{ echo "[MISSING] pnpm — Install: npm install -g pnpm or https://pnpm.io"; EXIT=1; }
@command -v python3 > /dev/null 2>&1 && \
echo "[OK] python3 ($$(python3 --version | cut -d' ' -f2))" || \
{ echo "[MISSING] python3 — Install via system package manager"; EXIT=1; }
@command -v yamllint > /dev/null 2>&1 && \
echo "[OK] yamllint ($$(yamllint --version | cut -d' ' -f2))" || \
{ echo "[MISSING] yamllint — Install: pip install yamllint"; EXIT=1; }
@command -v asciidoctor > /dev/null 2>&1 && \
echo "[OK] asciidoctor ($$(asciidoctor --version | head -1 | awk '{print $$2}'))" || \
{ echo "[MISSING] asciidoctor — Install: gem install asciidoctor (optional)"; }
@command -v oc > /dev/null 2>&1 && \
echo "[OK] oc ($$(oc version --client -o yaml | grep gitVersion | awk '{print $$2}'))" || \
{ echo "[MISSING] oc — Install: https://docs.openshift.com/container-platform/latest/cli_reference/openshift_cli/getting-started-cli.html (for tests)"; }
@echo ""
@[ -z "$$EXIT" ] && echo "All required tools installed!" || { echo "Please install missing tools."; exit 1; }
# ── Generate ────────────────────────────────────────────────────────
.PHONY: generate
generate: setup
ifndef TUTORIAL
$(error TUTORIAL is required. Example: make generate TUTORIAL=modules/vm-configuration/pages/internal-dns-for-vms.adoc)
endif
$(PYTHON) tests/generate-attachments.py $(if $(DRY_RUN),--dry-run) $(if $(FORCE),--force) $(TUTORIAL)
.PHONY: generate-all
generate-all: setup
$(PYTHON) tests/generate-attachments.py --all
.PHONY: generate-dry
generate-dry: setup
ifndef TUTORIAL
$(error TUTORIAL is required. Example: make generate-dry TUTORIAL=modules/vm-configuration/pages/internal-dns-for-vms.adoc)
endif
$(PYTHON) tests/generate-attachments.py --dry-run $(TUTORIAL)
# ── Documentation ───────────────────────────────────────────────────
.PHONY: build
build:
@if [ ! -d "$(NODE_MODULES)" ]; then \
echo "Installing node dependencies..."; \
pnpm install; \
fi
pnpm run build
.PHONY: serve
serve:
pnpm run serve
.PHONY: watch
watch:
@if [ ! -d "$(NODE_MODULES)" ]; then \
echo "Installing node dependencies..."; \
pnpm install; \
fi
pnpm run watch:adoc
.PHONY: dev
dev:
@if [ ! -d "$(NODE_MODULES)" ]; then \
echo "Installing node dependencies..."; \
pnpm install; \
fi
@echo "Starting watch in background..."
@pnpm run watch:adoc > /dev/null 2>&1 & echo $$! > .watch.pid
@echo "Starting preview server (Ctrl+C to stop both)..."
@trap 'kill $$(cat .watch.pid 2>/dev/null) 2>/dev/null; rm -f .watch.pid' EXIT; \
pnpm run serve
# ── Validation ──────────────────────────────────────────────────────
.PHONY: lint
lint:
@echo "Linting AsciiDoc files..."
@if command -v asciidoctor > /dev/null 2>&1; then \
find modules -name "*.adoc" -exec asciidoctor -o /dev/null -a attribute-missing=warn {} \; 2>&1 | \
grep -E "(WARN|ERROR)" || echo "[OK] No AsciiDoc errors found"; \
else \
echo "⚠ asciidoctor not installed. Install with: gem install asciidoctor"; \
exit 1; \
fi
.PHONY: check-links
check-links:
@if [ ! -d "$(BUILD_DIR)" ]; then \
echo "Build directory not found. Run 'make build' first."; \
exit 1; \
fi
@echo "Checking links in built HTML..."
@if command -v htmltest > /dev/null 2>&1; then \
htmltest $(BUILD_DIR); \
else \
echo "⚠ htmltest not installed. Skipping link validation."; \
echo "Install from: https://github.com/wjdp/htmltest"; \
fi
.PHONY: check-xrefs
check-xrefs: build
@echo "Checking xref links..."
@echo "[OK] No xref warnings found (checked during build)"
.PHONY: validate
validate: lint build check-xrefs review-all
@echo ""
@echo "[OK] All validation checks passed!"
.PHONY: test-manifests
test-manifests: setup
@echo "Validating YAML manifests..."
@find modules -type f \( -name "*.yaml" -o -name "*.yml" \) -exec $(VENV)/bin/yamllint {} + || \
{ echo "YAML validation failed. Fix errors above."; exit 1; }
@echo "[OK] All YAML manifests valid"
.PHONY: test-manifests-dry
test-manifests-dry: check-auth
@echo "Testing manifests with oc dry-run..."
@tmpdir=$$(mktemp -d); \
for file in $$(find modules -type f \( -name "*.yaml" -o -name "*.yml" \) | sort); do \
result=$$(oc apply --dry-run=client -f "$$file" 2>&1); \
rc=$$?; \
if [ $$rc -eq 0 ]; then \
echo pass >> "$$tmpdir/results"; \
elif echo "$$result" | grep -q "no matches for kind\|cannot use generate name"; then \
echo "[skip] $$file (CRD not installed or generateName)"; \
echo skip >> "$$tmpdir/results"; \
else \
echo "[FAIL] $$file"; \
echo " $$result" | head -2; \
echo fail >> "$$tmpdir/results"; \
fi; \
done; \
PASS=$$(grep -cx pass "$$tmpdir/results" || true); \
FAIL=$$(grep -cx fail "$$tmpdir/results" || true); \
SKIP=$$(grep -cx skip "$$tmpdir/results" || true); \
PASS=$${PASS:-0}; FAIL=$${FAIL:-0}; SKIP=$${SKIP:-0}; \
rm -rf "$$tmpdir"; \
echo ""; \
if [ "$$FAIL" -gt 0 ]; then \
echo "FAIL: $$FAIL manifest(s) failed dry-run ($$PASS passed, $$SKIP skipped)"; \
exit 1; \
else \
echo "[OK] All manifests passed dry-run ($$PASS passed, $$SKIP skipped — missing CRDs)"; \
fi
# ── Auth check ──────────────────────────────────────────────────────
.PHONY: check-auth
check-auth:
@oc whoami > /dev/null 2>&1 || \
{ echo ""; \
echo "Error: Not logged into an OpenShift cluster."; \
echo "Run 'oc login <cluster-url>' first."; \
echo ""; \
exit 1; }
@echo "Logged in as $$(oc whoami) on $$(oc whoami --show-server)"
# ── Test ────────────────────────────────────────────────────────────
.PHONY: test
test: generate-all test-manifests test-manifests-dry
@echo ""
@echo "[OK] All tests passed (attachments generated, YAML valid, dry-run OK)"
# ── Review ──────────────────────────────────────────────────────────
.PHONY: review-file
review-file:
ifndef FILE
$(error FILE is required. Example: make review-file FILE=modules/networking/pages/some-tutorial.adoc)
endif
@bash scripts/review-docs.sh $(FILE)
.PHONY: review
review:
@CHANGED=$$(git diff --name-only origin/main -- '*.adoc'); \
if [ -z "$$CHANGED" ]; then \
echo "No changed .adoc files found."; \
else \
bash scripts/review-docs.sh $$CHANGED; \
fi
.PHONY: review-all
review-all:
@bash scripts/review-docs.sh --all
# ── Clean ───────────────────────────────────────────────────────────
.PHONY: clean
clean:
rm -rf $(VENV)
@echo "Virtual environment removed."
.PHONY: clean-all
clean-all:
rm -rf $(VENV) $(BUILD_DIR) $(NODE_MODULES)
rm -f .watch.pid
@echo "Removed: venv, build, node_modules"
# ── Git Helpers ─────────────────────────────────────────────────────
.PHONY: branch
branch:
ifndef NAME
$(error NAME is required. Example: make branch NAME=add-tutorial-xyz)
endif
@git fetch upstream 2>/dev/null || git fetch origin
@git checkout main
@git pull upstream main 2>/dev/null || git pull origin main
@git checkout -b $(NAME)
@echo "Created branch: $(NAME)"
.PHONY: pr
pr:
@BRANCH=$$(git branch --show-current); \
git push -u origin $$BRANCH; \
echo ""; \
echo "Create PR at:"; \
echo "https://github.com/RedHatQuickCourses/ocp-virt-cookbook/compare/$$BRANCH"
.PHONY: sync
sync:
@BRANCH=$$(git branch --show-current); \
git fetch upstream 2>/dev/null || git fetch origin; \
git rebase upstream/main 2>/dev/null || git rebase origin/main; \
echo "Rebased $$BRANCH on upstream/main"