Repository navigation
183 lines (160 loc) · 6.63 KB
/
Copy pathvalidate-specifications.yml
File metadata and controls
183 lines (160 loc) · 6.63 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
name: Validate Specifications
on:
pull_request:
paths:
- '.github/specs/**'
- '.github/workflows/validate-specifications.yml'
- '.specify/scripts/bash/audit-specs.sh'
- '.specify/scripts/bash/validate-catalog.sh'
- 'tests/bash/**'
push:
branches:
- develop
paths:
- '.github/specs/**'
- '.github/workflows/validate-specifications.yml'
- '.specify/scripts/bash/audit-specs.sh'
- '.specify/scripts/bash/validate-catalog.sh'
- 'tests/bash/**'
permissions:
contents: read
concurrency:
group: validate-specifications-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
validate:
name: Specification Validation
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
# Full history is required to diff PR changes against develop.
fetch-depth: 0
# Only the markdown lint step needs npm packages; it installs them
# itself, and only when markdown files changed.
- name: Set up Node.js
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version-file: '.nvmrc'
cache: 'npm'
- name: Run specification audit
id: audit
run: |
set -o pipefail
bash .specify/scripts/bash/audit-specs.sh 2>&1 | tee audit-output.txt
audit_exit=${PIPESTATUS[0]}
if [ "$audit_exit" -ne 0 ]; then
echo "Specification audit failed with exit code $audit_exit" >&2
exit "$audit_exit"
fi
- name: Validate catalog structure
id: catalog
run: |
set +e
bash .specify/scripts/bash/validate-catalog.sh
exit_code=$?
set -e
if [ $exit_code -eq 0 ]; then
{
echo "status=found"
echo "schema_valid=true"
echo "links_valid=true"
echo "maintenance_ok=true"
} >> "$GITHUB_OUTPUT"
else
echo "Validation failed with exit code $exit_code" >&2
exit 1
fi
- name: Install Bats test framework
if: always()
uses: bats-core/bats-action@3566550e0f594451ac0f58fcbfdeca93aa29a45e # 4.1.0
with:
# Repository tests use plain bats only; skipping the unused
# libraries avoids their failing cache restores.
support-install: false
assert-install: false
detik-install: false
file-install: false
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Run audit script test suite
if: always()
id: tests
run: |
bats tests/bash
echo "tests_ok=true" >> "$GITHUB_OUTPUT"
echo "✓ Audit script tests passed"
- name: Lint specification files
if: always()
run: |
# Lint only markdown files changed in this PR. A repo-wide run
# fails on pre-existing debt in unrelated skill and plugin docs,
# which this check must not gate on.
mapfile -t CHANGED_MD < <(git diff --name-only --diff-filter=ACMR \
"$(git merge-base HEAD origin/develop)" HEAD -- '*.md' '*.mdx' \
| while IFS= read -r file; do
[ -f "$file" ] && printf '%s\n' "$file"
done)
if [ "${#CHANGED_MD[@]}" -eq 0 ]; then
echo "✓ No changed markdown files to lint"
exit 0
fi
printf 'Linting %d changed file(s):\n' "${#CHANGED_MD[@]}"
printf ' %s\n' "${CHANGED_MD[@]}"
npm ci --ignore-scripts --prefer-offline --no-audit --no-fund
./node_modules/.bin/markdownlint-cli2 "${CHANGED_MD[@]}"
echo "✓ Markdown linting passed"
- name: Run security scan
if: always()
run: |
set +e
# Scan specification files for common security issues
SECURITY_ISSUES=0
# Check for hardcoded secrets (literal password=, api_key=, token= patterns)
if grep -rE '(password|api_key|token)\s*[=:]\s*['"'"'"]?[^'"'"'" \n]' .github/specs/ --include="*.md" 2>/dev/null; then
echo "⚠️ Potential hardcoded secrets detected in specifications"
((SECURITY_ISSUES++))
fi
# No dangerous script pattern checks - eval is used legitimately for config loading
if [ $SECURITY_ISSUES -eq 0 ]; then
echo "🔒 Security scan completed"
echo "✓ No security issues detected in changes"
exit 0
else
echo "✗ Security scan found $SECURITY_ISSUES issue(s)"
exit 1
fi
- name: Generate compliance report
if: always()
id: report
run: |
cat > /tmp/compliance-report.md << 'EOF'
## 📋 Specification Compliance Report
### Directory Structure
- Catalog file: ${{ steps.catalog.outputs.status }}
- Schema compliance: ${{ steps.catalog.outputs.schema_valid }}
### Schema Compliance
- Canonical schema validation: ${{ steps.catalog.outputs.schema_valid }}
- Catalog link validation: ${{ steps.catalog.outputs.links_valid }}
- MAINTENANCE.md compliant: ${{ steps.catalog.outputs.maintenance_ok }}
### Metrics
| Metric | Status |
|--------|--------|
| Catalog exists | ${{ steps.catalog.outputs.status == 'found' && '✅' || '❌' }} |
| Schema valid | ${{ steps.catalog.outputs.schema_valid == 'true' && '✅' || '❌' }} |
| Links valid | ${{ steps.catalog.outputs.links_valid == 'true' && '✅' || '❌' }} |
| MAINTENANCE.md updated | ${{ steps.catalog.outputs.maintenance_ok == 'true' && '✅' || '⚠️' }} |
| Tests passed | ${{ steps.tests.outputs.tests_ok == 'true' && '✅' || '❌' }} |
### Principle X Compliance
This workflow enforces **Principle X: Automated Validation & Metrics-Driven Governance** by:
- ✅ Running automated validation on every PR touching specification files
- ✅ Generating compliance metrics and reporting them
- ✅ Failing the check if critical validation rules are violated
- ✅ Tracking specification structure, numbering, and schema compliance
- ✅ Running required quality checks (linting, security, tests)
---
_Generated by specification validation workflow_
EOF
cat /tmp/compliance-report.md >> "$GITHUB_STEP_SUMMARY"