-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate-template.sh
More file actions
executable file
·336 lines (286 loc) · 11.2 KB
/
validate-template.sh
File metadata and controls
executable file
·336 lines (286 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
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
#!/bin/bash
# SPDX-License-Identifier: PMPL-1.0-or-later
# Copyright (c) 2026 Jonathan D.A. Jewell (hyperpolymath) <[email protected]>
#
# RSR Template Validation Script
# Verifies that a repository follows the RSR template structure and contains all required files
#
# Exit codes:
# 0 = validation passed
# 1 = validation failed with errors
# 2 = validation failed with warnings (but can proceed)
set -euo pipefail
REPO_ROOT="${1:-.}"
VERBOSE="${2:-0}"
ERRORS=0
WARNINGS=0
# ANSI colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Helper functions
log_error() {
echo -e "${RED}ERROR${NC}: $*" >&2
ERRORS=$((ERRORS + 1))
}
log_warning() {
echo -e "${YELLOW}WARN${NC}: $*" >&2
WARNINGS=$((WARNINGS + 1))
}
log_info() {
echo -e "${BLUE}INFO${NC}: $*" >&2
}
log_pass() {
echo -e "${GREEN}PASS${NC}: $*" >&2
}
check_file_exists() {
local file="$1"
local description="${2:-}"
if [ -f "$REPO_ROOT/$file" ]; then
[ "$VERBOSE" = "1" ] && log_pass "File exists: $file"
return 0
else
log_error "Required file missing: $file ${description:+(${description})}"
return 1
fi
}
check_dir_exists() {
local dir="$1"
local description="${2:-}"
if [ -d "$REPO_ROOT/$dir" ]; then
[ "$VERBOSE" = "1" ] && log_pass "Directory exists: $dir"
return 0
else
log_error "Required directory missing: $dir ${description:+(${description})}"
return 1
fi
}
has_spdx_header() {
local file="$1"
if head -10 "$file" | grep -q "SPDX-License-Identifier"; then
return 0
fi
return 1
}
has_placeholder() {
local file="$1"
if grep -q "{{REPO\|{{OWNER\|{{FORGE\|{{PROJECT\|{{project\|{{AUTHOR" "$file" 2>/dev/null; then
return 0
fi
return 1
}
#==============================================================================
# VALIDATION PHASE 1: CORE STRUCTURE
#==============================================================================
echo ""
log_info "Phase 1: Core repository structure"
echo ""
# Root files
check_file_exists "0-AI-MANIFEST.a2ml" "AI manifest (universal entry point)"
check_file_exists "README.adoc" "High-level pitch"
check_file_exists "EXPLAINME.adoc" "Developer deep-dive"
check_file_exists "LICENSE" "License file"
check_file_exists "Justfile" "Task runner"
check_file_exists "AUDIT.adoc" "Release audit gate"
# Directories
check_dir_exists ".machine_readable" "Machine-readable metadata"
check_dir_exists ".github" "GitHub community metadata"
check_dir_exists "src/interface/abi" "Idris2 ABI definitions"
check_dir_exists "src/interface/ffi" "Zig FFI implementation"
check_dir_exists "src/interface/generated/abi" "Generated C headers"
check_dir_exists "docs" "Documentation"
#==============================================================================
# VALIDATION PHASE 2: MACHINE-READABLE METADATA
#==============================================================================
echo ""
log_info "Phase 2: Machine-readable metadata (.machine_readable/)"
echo ""
check_file_exists ".machine_readable/STATE.a2ml" "Project state"
check_file_exists ".machine_readable/META.a2ml" "Architecture decisions"
check_file_exists ".machine_readable/ECOSYSTEM.a2ml" "Ecosystem position"
check_file_exists ".machine_readable/anchors/ANCHOR.a2ml" "Semantic boundary anchor"
check_file_exists ".machine_readable/policies/MAINTENANCE-AXES.a2ml" "Maintenance axes"
#==============================================================================
# VALIDATION PHASE 3: REQUIRED WORKFLOWS (17 minimum)
#==============================================================================
echo ""
log_info "Phase 3: GitHub Actions workflows"
echo ""
REQUIRED_WORKFLOWS=(
"hypatia-scan.yml"
"codeql.yml"
"scorecard.yml"
"quality.yml"
"mirror.yml"
"instant-sync.yml"
"guix-nix-policy.yml"
"rsr-antipattern.yml"
"security-policy.yml"
"wellknown-enforcement.yml"
"workflow-linter.yml"
"npm-bun-blocker.yml"
"ts-blocker.yml"
"scorecard-enforcer.yml"
"secret-scanner.yml"
)
# Check required workflows
for workflow in "${REQUIRED_WORKFLOWS[@]}"; do
if [ -f "$REPO_ROOT/.github/workflows/$workflow" ]; then
[ "$VERBOSE" = "1" ] && log_pass "Workflow found: $workflow"
else
log_error "Required workflow missing: $workflow"
fi
done
# Verify all workflows have SPDX headers and proper structure
WORKFLOW_FILES=$(find "$REPO_ROOT/.github/workflows" -name "*.yml" -type f 2>/dev/null || true)
WORKFLOW_COUNT=$(echo "$WORKFLOW_FILES" | grep -c "." || true)
if [ "$WORKFLOW_COUNT" -ge 15 ]; then
log_pass "Found $WORKFLOW_COUNT workflows (>= 15 expected)"
else
log_warning "Found only $WORKFLOW_COUNT workflows (expected >= 15)"
fi
# Spot-check workflow files for issues
while IFS= read -r workflow_file; do
if [ -z "$workflow_file" ]; then continue; fi
# Check for SPDX header (optional in YAML workflows, but best practice)
if ! head -5 "$workflow_file" | grep -q "SPDX-License-Identifier"; then
log_warning "Workflow missing SPDX header: $(basename "$workflow_file")"
fi
# Check for proper YAML structure
if ! grep -q "^name:" "$workflow_file"; then
log_error "Workflow missing 'name' field: $(basename "$workflow_file")"
fi
done <<< "$WORKFLOW_FILES"
#==============================================================================
# VALIDATION PHASE 4: ABI/FFI SOURCE FILES
#==============================================================================
echo ""
log_info "Phase 4: Idris2 ABI and Zig FFI source files"
echo ""
# Idris2 ABI files
check_file_exists "src/interface/abi/Types.idr" "Core type definitions"
check_file_exists "src/interface/abi/Layout.idr" "Memory layout specifications"
check_file_exists "src/interface/abi/Foreign.idr" "FFI foreign declarations"
# Zig FFI files
check_file_exists "src/interface/ffi/build.zig" "Zig build configuration"
check_file_exists "src/interface/ffi/src/main.zig" "Zig implementation"
check_file_exists "src/interface/ffi/test/integration_test.zig" "Integration tests"
#==============================================================================
# VALIDATION PHASE 5: PLACEHOLDER TOKENS
#==============================================================================
echo ""
log_info "Phase 5: Placeholder token replacement (skipped in template repo)"
echo ""
# Note: Template repo is allowed to have placeholders
# For derived repos, we'd check that placeholders are replaced
if [ "$(basename "$REPO_ROOT")" = "rsr-template-repo" ]; then
log_pass "Skipping placeholder check for template repo"
else
# Check that key files don't have unresolved placeholders
for file in "$REPO_ROOT/README.adoc" "$REPO_ROOT/Justfile" "$REPO_ROOT/.machine_readable/STATE.a2ml"; do
if [ -f "$file" ]; then
if has_placeholder "$file"; then
log_warning "File contains unresolved placeholders: $(basename "$file")"
fi
fi
done
fi
#==============================================================================
# VALIDATION PHASE 6: SPDX LICENSE HEADERS
#==============================================================================
echo ""
log_info "Phase 6: SPDX License Headers"
echo ""
# Check source files for SPDX headers (excluding build artifacts)
SOURCE_FILES=$(find "$REPO_ROOT/src" -type f \( -name "*.idr" -o -name "*.zig" \) \
! -path "*/.zig-cache/*" ! -path "*/zig-cache/*" 2>/dev/null || true)
SOURCE_COUNT=$(echo "$SOURCE_FILES" | grep -c "." || true)
SPDX_COUNT=0
while IFS= read -r src_file; do
if [ -z "$src_file" ]; then continue; fi
if has_spdx_header "$src_file"; then
SPDX_COUNT=$((SPDX_COUNT + 1))
else
log_warning "Source file missing SPDX header: $(basename "$src_file")"
fi
done <<< "$SOURCE_FILES"
if [ "$SOURCE_COUNT" -gt 0 ]; then
PERCENT=$((SPDX_COUNT * 100 / SOURCE_COUNT))
log_pass "SPDX headers: $SPDX_COUNT/$SOURCE_COUNT ($PERCENT%)"
if [ "$PERCENT" -lt 100 ]; then
log_warning "Not all source files have SPDX headers"
fi
fi
#==============================================================================
# VALIDATION PHASE 7: BUILD VERIFICATION
#==============================================================================
echo ""
log_info "Phase 7: Build system verification"
echo ""
# Check Zig build
if [ -f "$REPO_ROOT/src/interface/ffi/build.zig" ]; then
if command -v zig &> /dev/null; then
cd "$REPO_ROOT/src/interface/ffi"
if zig build 2>&1 | grep -q "error"; then
log_error "Zig build failed"
else
log_pass "Zig build successful"
fi
cd - > /dev/null
else
log_warning "Zig compiler not found - skipping Zig build check"
fi
else
log_error "Zig build.zig not found"
fi
# Check Idris2 syntax (if available)
if command -v idris2 &> /dev/null; then
IDS_FILES=$(find "$REPO_ROOT/src/interface/abi" -name "*.idr" -type f 2>/dev/null || true)
while IFS= read -r ids_file; do
if [ -z "$ids_file" ]; then continue; fi
if ! idris2 --check "$ids_file" 2>&1 | grep -q "Error"; then
log_pass "Idris2 syntax OK: $(basename "$ids_file")"
else
log_warning "Idris2 syntax issue: $(basename "$ids_file")"
fi
done <<< "$IDS_FILES"
else
log_warning "Idris2 compiler not found - skipping Idris2 syntax checks"
fi
#==============================================================================
# VALIDATION PHASE 8: DOCUMENTATION
#==============================================================================
echo ""
log_info "Phase 8: Documentation requirements"
echo ""
check_file_exists "docs/developer/ABI-FFI-README.adoc" "ABI/FFI documentation"
check_file_exists "TOPOLOGY.md" "Architecture topology" || check_file_exists "docs/architecture/TOPOLOGY.md" "Architecture topology (in docs)"
check_file_exists "CONTRIBUTING.md" "Contribution guide"
# Governance can be at root or in docs/governance/
if [ -f "$REPO_ROOT/GOVERNANCE.adoc" ] || [ -f "$REPO_ROOT/GOVERNANCE.md" ] || [ -d "$REPO_ROOT/docs/governance" ]; then
[ "$VERBOSE" = "1" ] && log_pass "Governance files found"
else
log_warning "Governance documentation not found"
fi
#==============================================================================
# VALIDATION SUMMARY
#==============================================================================
echo ""
echo "═══════════════════════════════════════════════════════════════════════════════"
echo "VALIDATION SUMMARY"
echo "═══════════════════════════════════════════════════════════════════════════════"
echo ""
echo -e "Errors: ${RED}${ERRORS}${NC}"
echo -e "Warnings: ${YELLOW}${WARNINGS}${NC}"
echo ""
if [ "$ERRORS" -eq 0 ]; then
echo -e "${GREEN}✓ Validation PASSED${NC}"
[ "$WARNINGS" -gt 0 ] && echo -e " (with $WARNINGS warnings)"
exit 0
else
echo -e "${RED}✗ Validation FAILED${NC}"
echo " Please fix the errors above."
exit 1
fi