Repository navigation
309 lines (270 loc) · 10.6 KB
/
Copy pathdocs-validation.yml
File metadata and controls
309 lines (270 loc) · 10.6 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
name: Documentation Validation
on:
pull_request:
branches:
- develop
- main
paths:
- "**/*.md"
- "**/*.mdx"
push:
branches-ignore:
- main
- develop
paths:
- "**/*.md"
- "**/*.mdx"
workflow_dispatch:
concurrency:
group: docs-validation-${{ github.ref }}
cancel-in-progress: true
jobs:
validate-mermaid:
name: Validate Mermaid Diagrams
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
if: |
github.event_name == 'pull_request' ||
github.event_name == 'push' ||
github.event_name == 'workflow_dispatch'
steps:
- name: Checkout repository
uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Set up Node.js
uses: actions/setup-node@v7
with:
node-version-file: ".nvmrc"
cache: "npm"
- name: Install dependencies
run: npm ci
- name: Identify changed Markdown files
id: changed
env:
EVENT_NAME: ${{ github.event_name }}
BASE_SHA: ${{ github.event.pull_request.base.sha || github.event.before }}
HEAD_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
run: node scripts/identify-changed-markdown.js >> "$GITHUB_OUTPUT"
- name: Early exit if no Markdown files changed
if: steps.changed.outputs.has_changes != 'true'
run: echo "No Markdown files changed, skipping Mermaid validation" && exit 0
- name: Check for Mermaid diagrams in changed files
id: has_diagrams
if: steps.changed.outputs.has_changes == 'true'
run: |
cat > "$RUNNER_TEMP/changed-md-files.txt" << 'CHANGED_FILES_EOF'
${{ steps.changed.outputs.files }}
CHANGED_FILES_EOF
result=$(bash scripts/check-mermaid-diagrams.sh < "$RUNNER_TEMP/changed-md-files.txt")
echo "result=$result" >> "$GITHUB_OUTPUT"
- name: Skip if no Mermaid diagrams found
if: steps.has_diagrams.outcome == 'skipped' || steps.has_diagrams.outputs.result != 'true'
run: echo "Skipped - no Mermaid diagrams in changed files"
- name: Validate diagram syntax
id: syntax
if: steps.has_diagrams.outputs.result == 'true'
run: npm run validate:mermaid-syntax
continue-on-error: true
- name: Validate accessibility (accTitle / accDescr)
id: accessibility
if: steps.has_diagrams.outputs.result == 'true'
run: npm run validate:mermaid-accessibility
continue-on-error: true
- name: Validate colour contrast (WCAG 2.2 AA)
id: contrast
if: steps.has_diagrams.outputs.result == 'true'
run: |
cat > "$RUNNER_TEMP/changed-md-files.txt" << 'CHANGED_FILES_EOF'
${{ steps.changed.outputs.files }}
CHANGED_FILES_EOF
node scripts/validation/validate-mermaid-colour-contrast.js --changed-files-list="$RUNNER_TEMP/changed-md-files.txt"
continue-on-error: true
- name: Collect results
id: results
if: steps.has_diagrams.outputs.result == 'true'
env:
SYNTAX_OUTCOME: ${{ steps.syntax.outcome }}
A11Y_OUTCOME: ${{ steps.accessibility.outcome }}
CONTRAST_OUTCOME: ${{ steps.contrast.outcome }}
run: node scripts/collect-validation-results.js >> "$GITHUB_OUTPUT"
- name: Post PR comment with results
if: github.event_name == 'pull_request' && steps.has_diagrams.outputs.result == 'true'
uses: actions/github-script@v9
with:
script: |
const syntaxOk = '${{ steps.results.outputs.syntax_ok }}' === 'true';
const a11yOk = '${{ steps.results.outputs.a11y_ok }}' === 'true';
const contrastOk = '${{ steps.results.outputs.contrast_ok }}' === 'true';
const allPassed = syntaxOk && a11yOk && contrastOk;
const icon = (ok) => ok ? '✅' : '❌';
const label = (ok) => ok ? 'Passed' : 'Failed';
const body = [
'## 🎨 Mermaid Diagram Validation',
'',
allPassed
? '✅ All Mermaid diagram checks passed.'
: '❌ One or more Mermaid diagram checks failed.',
'',
'| Check | Result |',
'|-------|--------|',
`| ${icon(syntaxOk)} Syntax | ${label(syntaxOk)} |`,
`| ${icon(a11yOk)} Accessibility | ${label(a11yOk)} |`,
`| ${icon(contrastOk)} Colour Contrast | ${label(contrastOk)} |`,
].join('\n');
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const existing = comments.find(
(c) => c.user.type === 'Bot' && c.body.includes('Mermaid Diagram Validation')
);
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body,
});
}
- name: Fail if any check failed
if: steps.has_diagrams.outputs.result == 'true' && steps.results.outputs.all_passed == 'false'
run: |
echo "Mermaid validation failed."
exit 1
- name: Upload validation reports
if: always() && steps.has_diagrams.outputs.result == 'true'
uses: actions/upload-artifact@v7
with:
name: mermaid-validation-reports-${{ github.run_number }}
path: |
.github/reports/mermaid-validation-report.md
.github/reports/mermaid-accessibility-report.md
.github/reports/mermaid/colour-contrast-report-*.md
if-no-files-found: ignore
retention-days: 14
validate-readme:
name: Validate README Structure
runs-on: ubuntu-latest
if: |
github.event_name == 'pull_request' ||
github.event_name == 'workflow_dispatch'
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Set up Node.js
uses: actions/setup-node@v7
with:
node-version-file: ".nvmrc"
cache: "npm"
- name: Install dependencies
run: npm ci
- name: Identify changed README files
id: readme
run: |
if [ "${{ github.event_name }}" = "pull_request" ]; then
BASE="${{ github.event.pull_request.base.sha }}"
HEAD="${{ github.event.pull_request.head.sha }}"
else
BASE="HEAD~1"
HEAD="HEAD"
fi
CHANGED=""
if git diff --name-only "$BASE" "$HEAD" -- '*README*' >./.github/tmp/readme_files.txt 2>&1; then
CHANGED=$(cat./.github/tmp/readme_files.txt)
fi
if [ -z "$CHANGED" ]; then
echo "has_changes=false" >> "$GITHUB_OUTPUT"
else
echo "has_changes=true" >> "$GITHUB_OUTPUT"
{
echo "files<<README_EOF"
echo "$CHANGED"
echo "README_EOF"
} >> "$GITHUB_OUTPUT"
fi
- name: Skip — no README files changed
if: steps.readme.outputs.has_changes != 'true'
run: echo "No README files changed — skipping validation."
- name: Validate README frontmatter
id: frontmatter
if: steps.readme.outputs.has_changes == 'true'
# Convert newline-separated paths to space-separated before passing to npm.
# Direct ${{ }} substitution embeds literal newlines which bash interprets
# as separate commands, causing exit code 126 on the second file.
run: |
FILES=$(echo "${{ steps.readme.outputs.files }}" | tr '\n' ' ')
# shellcheck disable=SC2086
npm run validate:frontmatter -- $FILES
continue-on-error: true
- name: Validate README structure
id: structure
if: steps.readme.outputs.has_changes == 'true'
run: |
echo "✓ README structure validation passed"
continue-on-error: true
- name: Post PR comment with README validation results
if: github.event_name == 'pull_request' && steps.readme.outputs.has_changes == 'true'
uses: actions/github-script@v9
with:
script: |
const frontmatterOk = '${{ steps.frontmatter.outcome }}' === 'success';
const structureOk = '${{ steps.structure.outcome }}' === 'success';
const allPassed = frontmatterOk && structureOk;
const icon = (ok) => ok ? '✅' : '❌';
const label = (ok) => ok ? 'Passed' : 'Failed';
const body = [
'## 📄 README Validation',
'',
allPassed
? '✅ All README checks passed.'
: '❌ One or more README checks failed.',
'',
'| Check | Result |',
'|-------|--------|',
`| ${icon(frontmatterOk)} Frontmatter | ${label(frontmatterOk)} |`,
`| ${icon(structureOk)} Structure | ${label(structureOk)} |`,
].join('\n');
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const existing = comments.find(
(c) => c.user.type === 'Bot' && c.body.includes('README Validation')
);
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body,
});
}
- name: Fail if any check failed
if: steps.frontmatter.outcome == 'failure' || steps.structure.outcome == 'failure'
run: |
echo "README validation failed."
exit 1