-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJustfile
More file actions
487 lines (408 loc) · 21.4 KB
/
Justfile
File metadata and controls
487 lines (408 loc) · 21.4 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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
# SPDX-License-Identifier: Palimpsest-MPL 1.0 or later
# RSR-template-repo - RSR Standard Justfile Template
# https://just.systems/man/en/
#
# This is the CANONICAL template for all RSR projects.
# Copy this file to new projects and customize the {{PLACEHOLDER}} values.
#
# IMPORTANT: This file MUST be named "Justfile" (capital J) for RSR compliance.
#
# Run `just` to see all available recipes
# Run `just cookbook` to generate docs/just-cookbook.adoc
# Run `just combinations` to see matrix recipe options
set shell := ["bash", "-uc"]
set dotenv-load := true
set positional-arguments := true
# Project metadata
import? "contractile.just"
project := "http-capability-gateway"
version := "1.0.0"
tier := "infrastructure" # 1 | 2 | infrastructure
# ═══════════════════════════════════════════════════════════════════════════════
# DEFAULT & HELP
# ═══════════════════════════════════════════════════════════════════════════════
# Show all available recipes with descriptions
default:
@just --list --unsorted
# Show detailed help for a specific recipe
help recipe="":
#!/usr/bin/env bash
if [ -z "{{recipe}}" ]; then
just --list --unsorted
echo ""
echo "Usage: just help <recipe>"
echo " just cookbook # Generate full documentation"
echo " just combinations # Show matrix recipes"
else
just --show "{{recipe}}" 2>/dev/null || echo "Recipe '{{recipe}}' not found"
fi
# Show this project's info
info:
@echo "Project: {{project}}"
@echo "Version: {{version}}"
@echo "RSR Tier: {{tier}}"
@echo "Recipes: $(just --summary | wc -w)"
@[ -f STATE.scm ] && grep -oP '\(phase\s+\.\s+\K[^)]+' STATE.scm | head -1 | xargs -I{} echo "Phase: {}" || true
# ═══════════════════════════════════════════════════════════════════════════════
# BUILD & COMPILE
# ═══════════════════════════════════════════════════════════════════════════════
# Build the project (debug mode)
build *args:
mix compile {{args}}
# Build in release mode with optimizations
build-release *args:
MIX_ENV=prod mix compile {{args}}
# Build and watch for changes
build-watch:
@echo "No dedicated watch recipe configured; use 'iex -S mix' for interactive development."
# Clean build artifacts [reversible: rebuild with `just build`]
clean:
mix clean
rm -rf _build deps doc coverage
# Deep clean including caches [reversible: rebuild]
clean-all: clean
rm -rf .cache .tmp
# ═══════════════════════════════════════════════════════════════════════════════
# TEST & QUALITY
# ═══════════════════════════════════════════════════════════════════════════════
# Run all tests
test *args:
mix test {{args}}
# Run tests with verbose output
test-verbose:
mix test --trace
# Run tests and generate coverage report
test-coverage:
mix test --cover
# ═══════════════════════════════════════════════════════════════════════════════
# LINT & FORMAT
# ═══════════════════════════════════════════════════════════════════════════════
# Format all source files [reversible: git checkout]
fmt:
mix format
# Check formatting without changes
fmt-check:
mix format --check-formatted
# Run linter
lint:
mix compile --warnings-as-errors
# Run all quality checks
quality: fmt-check lint test
@echo "All quality checks passed!"
# Fix all auto-fixable issues [reversible: git checkout]
fix: fmt
@echo "Fixed all auto-fixable issues"
# ═══════════════════════════════════════════════════════════════════════════════
# RUN & EXECUTE
# ═══════════════════════════════════════════════════════════════════════════════
# Run the application
run *args:
mix run --no-halt {{args}}
# Run in development mode with hot reload
dev:
iex -S mix
# Run REPL/interactive mode
repl:
iex -S mix
# ═══════════════════════════════════════════════════════════════════════════════
# DEPENDENCIES
# ═══════════════════════════════════════════════════════════════════════════════
# Install all dependencies
deps:
mix deps.get
# Audit dependencies for vulnerabilities
deps-audit:
mix hex.audit
# ═══════════════════════════════════════════════════════════════════════════════
# DOCUMENTATION
# ═══════════════════════════════════════════════════════════════════════════════
# Generate all documentation
docs:
@mkdir -p docs/generated docs/man
just cookbook
just man
@echo "Documentation generated in docs/"
# Generate justfile cookbook documentation
cookbook:
#!/usr/bin/env bash
mkdir -p docs
OUTPUT="docs/just-cookbook.adoc"
echo "= {{project}} Justfile Cookbook" > "$OUTPUT"
echo ":toc: left" >> "$OUTPUT"
echo ":toclevels: 3" >> "$OUTPUT"
echo "" >> "$OUTPUT"
echo "Generated: $(date -Iseconds)" >> "$OUTPUT"
echo "" >> "$OUTPUT"
echo "== Recipes" >> "$OUTPUT"
echo "" >> "$OUTPUT"
just --list --unsorted | while read -r line; do
if [[ "$line" =~ ^[[:space:]]+([a-z_-]+) ]]; then
recipe="${BASH_REMATCH[1]}"
echo "=== $recipe" >> "$OUTPUT"
echo "" >> "$OUTPUT"
echo "[source,bash]" >> "$OUTPUT"
echo "----" >> "$OUTPUT"
echo "just $recipe" >> "$OUTPUT"
echo "----" >> "$OUTPUT"
echo "" >> "$OUTPUT"
fi
done
echo "Generated: $OUTPUT"
# Generate man page
man:
#!/usr/bin/env bash
mkdir -p docs/man
printf '%s\n' \
'.TH HTTP-CAPABILITY-GATEWAY 1 "$(date +%Y-%m-%d)" "{{version}}" "HTTP Capability Gateway Manual"' \
'.SH NAME' \
'{{project}} \- policy-driven HTTP capability gateway' \
'.SH SYNOPSIS' \
'.B just' \
'[recipe] [args...]' \
'.SH DESCRIPTION' \
'Utility recipes for building, testing, and validating the HTTP capability gateway.' \
'.SH AUTHOR' \
'Hyperpolymath <hyperpolymath@proton.me>' \
> docs/man/{{project}}.1
echo "Generated: docs/man/{{project}}.1"
# ═══════════════════════════════════════════════════════════════════════════════
# CONTAINERS (nerdctl-first, podman-fallback)
# ═══════════════════════════════════════════════════════════════════════════════
# Detect container runtime: nerdctl > podman > docker
[private]
container-cmd:
#!/usr/bin/env bash
if command -v nerdctl >/dev/null 2>&1; then
echo "nerdctl"
elif command -v podman >/dev/null 2>&1; then
echo "podman"
elif command -v docker >/dev/null 2>&1; then
echo "docker"
else
echo "ERROR: No container runtime found (install nerdctl, podman, or docker)" >&2
exit 1
fi
# Build container image
container-build tag="latest":
#!/usr/bin/env bash
CTR=$(just container-cmd)
if [ -f Containerfile ]; then
echo "Building with $CTR..."
$CTR build -t {{project}}:{{tag}} -f Containerfile .
else
echo "No Containerfile found"
fi
# Run container
container-run tag="latest" *args:
#!/usr/bin/env bash
CTR=$(just container-cmd)
$CTR run --rm -it {{project}}:{{tag}} {{args}}
# Push container image
container-push registry="ghcr.io/hyperpolymath" tag="latest":
#!/usr/bin/env bash
CTR=$(just container-cmd)
$CTR tag {{project}}:{{tag}} {{registry}}/{{project}}:{{tag}}
$CTR push {{registry}}/{{project}}:{{tag}}
# ═══════════════════════════════════════════════════════════════════════════════
# CI & AUTOMATION
# ═══════════════════════════════════════════════════════════════════════════════
# Run full CI pipeline locally
ci: deps quality
@echo "CI pipeline complete!"
# Install git hooks
install-hooks:
@mkdir -p .git/hooks
@printf '%s\n' '#!/bin/bash' 'just fmt-check || exit 1' 'just lint || exit 1' > .git/hooks/pre-commit
@chmod +x .git/hooks/pre-commit
@echo "Git hooks installed"
# ═══════════════════════════════════════════════════════════════════════════════
# SECURITY
# ═══════════════════════════════════════════════════════════════════════════════
# Run security audit
security: deps-audit
@echo "=== Security Audit ==="
@command -v gitleaks >/dev/null && gitleaks detect --source . --verbose || true
@command -v trivy >/dev/null && trivy fs --severity HIGH,CRITICAL . || true
@echo "Security audit complete"
# Generate SBOM
sbom:
@mkdir -p docs/security
@command -v syft >/dev/null && syft . -o spdx-json > docs/security/sbom.spdx.json || echo "syft not found"
# ═══════════════════════════════════════════════════════════════════════════════
# VALIDATION & COMPLIANCE
# ═══════════════════════════════════════════════════════════════════════════════
# Validate RSR compliance
validate-rsr:
#!/usr/bin/env bash
echo "=== RSR Compliance Check ==="
MISSING=""
for f in .editorconfig .gitignore Justfile RSR_COMPLIANCE.adoc README.adoc; do
[ -f "$f" ] || MISSING="$MISSING $f"
done
for d in .well-known; do
[ -d "$d" ] || MISSING="$MISSING $d/"
done
for f in .well-known/security.txt .well-known/ai.txt .well-known/humans.txt; do
[ -f "$f" ] || MISSING="$MISSING $f"
done
if [ ! -f "guix.scm" ] && [ ! -f ".guix-channel" ] && [ ! -f "flake.nix" ]; then
MISSING="$MISSING guix.scm/flake.nix"
fi
if [ -n "$MISSING" ]; then
echo "MISSING:$MISSING"
exit 1
fi
echo "RSR compliance: PASS"
# Validate STATE.scm syntax
validate-state:
@if [ -f "STATE.scm" ]; then \
guile -c "(primitive-load \"STATE.scm\")" 2>/dev/null && echo "STATE.scm: valid" || echo "STATE.scm: INVALID"; \
else \
echo "No STATE.scm found"; \
fi
# Full validation suite
validate: fmt-check lint test validate-rsr validate-state
@echo "All validations passed!"
# ═══════════════════════════════════════════════════════════════════════════════
# STATE MANAGEMENT
# ═══════════════════════════════════════════════════════════════════════════════
# Update STATE.scm timestamp
state-touch:
@if [ -f "STATE.scm" ]; then \
sed -i 's/(updated . "[^"]*")/(updated . "'"$(date -Iseconds)"'")/' STATE.scm && \
echo "STATE.scm timestamp updated"; \
fi
# Show current phase from STATE.scm
state-phase:
@grep -oP '\(phase\s+\.\s+\K[^)]+' STATE.scm 2>/dev/null | head -1 || echo "unknown"
# ═══════════════════════════════════════════════════════════════════════════════
# GUIX & NIX
# ═══════════════════════════════════════════════════════════════════════════════
# Enter Guix development shell (primary)
guix-shell:
guix shell -D -f guix.scm
# Build with Guix
guix-build:
guix build -f guix.scm
# Enter Nix development shell (fallback)
nix-shell:
@if [ -f "flake.nix" ]; then nix develop; else echo "No flake.nix"; fi
# ═══════════════════════════════════════════════════════════════════════════════
# HYBRID AUTOMATION
# ═══════════════════════════════════════════════════════════════════════════════
# Run local automation tasks
automate task="all":
#!/usr/bin/env bash
case "{{task}}" in
all) just fmt && just lint && just test && just docs && just state-touch ;;
cleanup) just clean && find . -name "*.orig" -delete && find . -name "*~" -delete ;;
update) just deps && just validate ;;
*) echo "Unknown: {{task}}. Use: all, cleanup, update" && exit 1 ;;
esac
# ═══════════════════════════════════════════════════════════════════════════════
# COMBINATORIC MATRIX RECIPES
# ═══════════════════════════════════════════════════════════════════════════════
# Build matrix: [debug|release] × [target] × [features]
build-matrix mode="debug" target="" features="":
@echo "Build matrix: mode={{mode}} target={{target}} features={{features}}"
# Customize for your build system
# Test matrix: [unit|integration|e2e|all] × [verbosity] × [parallel]
test-matrix suite="unit" verbosity="normal" parallel="true":
@echo "Test matrix: suite={{suite}} verbosity={{verbosity}} parallel={{parallel}}"
# Container matrix: [build|run|push|shell|scan] × [registry] × [tag]
container-matrix action="build" registry="ghcr.io/hyperpolymath" tag="latest":
@echo "Container matrix: action={{action}} registry={{registry}} tag={{tag}}"
# CI matrix: [lint|test|build|security|all] × [quick|full]
ci-matrix stage="all" depth="quick":
@echo "CI matrix: stage={{stage}} depth={{depth}}"
# Show all matrix combinations
combinations:
@echo "=== Combinatoric Matrix Recipes ==="
@echo ""
@echo "Build Matrix: just build-matrix [debug|release] [target] [features]"
@echo "Test Matrix: just test-matrix [unit|integration|e2e|all] [verbosity] [parallel]"
@echo "Container: just container-matrix [build|run|push|shell|scan] [registry] [tag]"
@echo "CI Matrix: just ci-matrix [lint|test|build|security|all] [quick|full]"
@echo ""
@echo "Total combinations: ~10 billion"
# ═══════════════════════════════════════════════════════════════════════════════
# VERSION CONTROL
# ═══════════════════════════════════════════════════════════════════════════════
# Show git status
status:
@git status --short
# Show recent commits
log count="20":
@git log --oneline -{{count}}
# ═══════════════════════════════════════════════════════════════════════════════
# UTILITIES
# ═══════════════════════════════════════════════════════════════════════════════
# Count lines of code
loc:
@find . \( -name "*.rs" -o -name "*.ex" -o -name "*.res" -o -name "*.ncl" -o -name "*.scm" \) 2>/dev/null | xargs wc -l 2>/dev/null | tail -1 || echo "0"
# Show TODO comments
todos:
@grep -rn "TODO\|FIXME" --include="*.rs" --include="*.ex" --include="*.res" . 2>/dev/null || echo "No TODOs"
# Open in editor
edit:
${EDITOR:-code} .
# [AUTO-GENERATED] Multi-arch / RISC-V target
build-riscv:
@echo "Building for RISC-V..."
cross build --target riscv64gc-unknown-linux-gnu
# Self-diagnostic — checks dependencies, permissions, paths
doctor:
@echo "Running diagnostics for http-capability-gateway..."
@echo "Checking required tools..."
@command -v just >/dev/null 2>&1 && echo " [OK] just" || echo " [FAIL] just not found"
@command -v git >/dev/null 2>&1 && echo " [OK] git" || echo " [FAIL] git not found"
@echo "Checking for hardcoded paths..."
@grep -rn '$HOME\|$ECLIPSE_DIR' --include='*.rs' --include='*.ex' --include='*.res' --include='*.gleam' --include='*.sh' . 2>/dev/null | head -5 || echo " [OK] No hardcoded paths"
@echo "Diagnostics complete."
# Auto-repair common issues
heal:
@echo "Attempting auto-repair for http-capability-gateway..."
@echo "Fixing permissions..."
@find . -name "*.sh" -exec chmod +x {} \; 2>/dev/null || true
@echo "Cleaning stale caches..."
@rm -rf .cache/stale 2>/dev/null || true
@echo "Repair complete."
# Guided tour of key features
tour:
@echo "=== http-capability-gateway Tour ==="
@echo ""
@echo "1. Project structure:"
@ls -la
@echo ""
@echo "2. Available commands: just --list"
@echo ""
@echo "3. Read README.adoc for full overview"
@echo "4. Read EXPLAINME.adoc for architecture decisions"
@echo "5. Run 'just doctor' to check your setup"
@echo ""
@echo "Tour complete! Try 'just --list' to see all available commands."
# Open feedback channel with diagnostic context
help-me:
@echo "=== http-capability-gateway Help ==="
@echo "Platform: $(uname -s) $(uname -m)"
@echo "Shell: $SHELL"
@echo ""
@echo "To report an issue:"
@echo " https://github.com/hyperpolymath/http-capability-gateway/issues/new"
@echo ""
@echo "Include the output of 'just doctor' in your report."
# Print the current CRG grade (reads from READINESS.md '**Current Grade:** X' line)
crg-grade:
@grade=$$(grep -oP '(?<=\*\*Current Grade:\*\* )[A-FX]' READINESS.md 2>/dev/null | head -1); \
[ -z "$$grade" ] && grade="X"; \
echo "$$grade"
# Generate a shields.io badge markdown for the current CRG grade
# Looks for '**Current Grade:** X' in READINESS.md; falls back to X
crg-badge:
@grade=$$(grep -oP '(?<=\*\*Current Grade:\*\* )[A-FX]' READINESS.md 2>/dev/null | head -1); \
[ -z "$$grade" ] && grade="X"; \
case "$$grade" in \
A) color="brightgreen" ;; B) color="green" ;; C) color="yellow" ;; \
D) color="orange" ;; E) color="red" ;; F) color="critical" ;; \
*) color="lightgrey" ;; esac; \
echo "[](https://github.com/hyperpolymath/standards/tree/main/component-readiness-grades)"