-
-
Notifications
You must be signed in to change notification settings - Fork 191
265 lines (233 loc) · 11.4 KB
/
doc-quality-checks.yml
File metadata and controls
265 lines (233 loc) · 11.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
name: Documentation Quality Checks
# This workflow validates documentation quality for any markdown changes.
# It runs linting, link checking, spell checking, and grammar checking.
# Auto-fixes are applied where possible, warnings are posted as comments,
# and critical issues block the merge.
# COMMENTED OUT - Will be enabled later
# on:
# pull_request:
# branches:
# - main
# - develop
# paths:
# - "**.md"
# - "docs/**"
# workflow_dispatch:
on:
workflow_dispatch:
permissions:
contents: read
pull-requests: write # For posting comments
jobs:
doc-quality:
name: 📚 Documentation Quality
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Get changed markdown files
id: changed-files
run: |
if [ "${{ github.event_name }}" = "pull_request" ]; then
CHANGED_MD=$(git diff --name-only --diff-filter=ACMRT origin/${{ github.base_ref }}...HEAD | grep -E '\.md$' || true)
else
CHANGED_MD=$(find . -name '*.md' -not -path './node_modules/*' -not -path './.git/*')
fi
if [ -z "$CHANGED_MD" ]; then
echo "No markdown files changed"
echo "has_changes=false" >> $GITHUB_OUTPUT
else
echo "Changed markdown files:"
echo "$CHANGED_MD"
echo "$CHANGED_MD" > changed_files.txt
echo "has_changes=true" >> $GITHUB_OUTPUT
fi
- name: Setup Node.js
if: steps.changed-files.outputs.has_changes == 'true'
uses: actions/setup-node@v6
with:
node-version: "20"
# Markdown Linting with auto-fix
- name: Install markdownlint-cli2
if: steps.changed-files.outputs.has_changes == 'true'
run: npm install -g markdownlint-cli2
- name: Run markdownlint with auto-fix
if: steps.changed-files.outputs.has_changes == 'true'
id: markdown-lint
continue-on-error: true
run: |
# Run with auto-fix
cat changed_files.txt | xargs markdownlint-cli2 --fix || true
# Check if there are still issues
if cat changed_files.txt | xargs markdownlint-cli2 2>&1 | tee markdownlint-output.txt; then
echo "status=success" >> $GITHUB_OUTPUT
else
echo "status=warning" >> $GITHUB_OUTPUT
fi
- name: Commit auto-fixes
if: steps.changed-files.outputs.has_changes == 'true' && steps.markdown-lint.outputs.status == 'warning'
continue-on-error: true
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add -A
git diff --staged --quiet || git commit -m "docs: auto-fix markdown linting issues"
# Link Checking (Critical - blocks merge)
- name: Install markdown-link-check
if: steps.changed-files.outputs.has_changes == 'true'
run: npm install -g markdown-link-check
- name: Check markdown links
if: steps.changed-files.outputs.has_changes == 'true'
id: link-check
continue-on-error: true
run: |
EXIT_CODE=0
while IFS= read -r file; do
echo "Checking links in: $file"
if ! markdown-link-check "$file" --config .markdown-link-check.json 2>&1 | tee -a link-check-output.txt; then
EXIT_CODE=1
fi
done < changed_files.txt
if [ $EXIT_CODE -eq 0 ]; then
echo "status=success" >> $GITHUB_OUTPUT
else
echo "status=critical" >> $GITHUB_OUTPUT
fi
# Spell Checking (Warning only)
- name: Install cspell
if: steps.changed-files.outputs.has_changes == 'true'
run: npm install -g cspell
- name: Run spell check
if: steps.changed-files.outputs.has_changes == 'true'
id: spell-check
continue-on-error: true
run: |
if cat changed_files.txt | xargs cspell --config .cspell.json 2>&1 | tee spell-check-output.txt; then
echo "status=success" >> $GITHUB_OUTPUT
else
echo "status=warning" >> $GITHUB_OUTPUT
fi
# Grammar Checking (Warning only)
- name: Install Vale
if: steps.changed-files.outputs.has_changes == 'true'
run: |
wget https://github.com/errata-ai/vale/releases/latest/download/vale_Linux_64-bit.tar.gz
mkdir -p bin
tar -xvzf vale_Linux_64-bit.tar.gz -C bin
echo "${{ github.workspace }}/bin" >> $GITHUB_PATH
- name: Run grammar check
if: steps.changed-files.outputs.has_changes == 'true'
id: grammar-check
continue-on-error: true
run: |
if cat changed_files.txt | xargs ./bin/vale --config .vale.ini 2>&1 | tee grammar-check-output.txt; then
echo "status=success" >> $GITHUB_OUTPUT
else
echo "status=warning" >> $GITHUB_OUTPUT
fi
# Aggregate results and post comment
- name: Prepare results summary
if: steps.changed-files.outputs.has_changes == 'true'
id: summary
run: |
SUMMARY="## 📚 Documentation Quality Check Results\n\n"
HAS_CRITICAL=false
HAS_WARNING=false
# Markdown lint results
if [ "${{ steps.markdown-lint.outputs.status }}" = "success" ]; then
SUMMARY="${SUMMARY}✅ **Markdown Linting**: Passed\n"
else
SUMMARY="${SUMMARY}⚠️ **Markdown Linting**: Warnings found\n"
HAS_WARNING=true
if [ -f markdownlint-output.txt ]; then
SUMMARY="${SUMMARY}\`\`\`\n$(cat markdownlint-output.txt | head -20)\n\`\`\`\n"
fi
fi
# Link check results
if [ "${{ steps.link-check.outputs.status }}" = "success" ]; then
SUMMARY="${SUMMARY}✅ **Link Checking**: All links valid\n"
elif [ "${{ steps.link-check.outputs.status }}" = "critical" ]; then
SUMMARY="${SUMMARY}❌ **Link Checking**: Broken links found (BLOCKING)\n"
HAS_CRITICAL=true
if [ -f link-check-output.txt ]; then
SUMMARY="${SUMMARY}\`\`\`\n$(cat link-check-output.txt | grep -E 'ERROR|✖' | head -10)\n\`\`\`\n"
fi
fi
# Spell check results
if [ "${{ steps.spell-check.outputs.status }}" = "success" ]; then
SUMMARY="${SUMMARY}✅ **Spell Checking**: No typos found\n"
else
SUMMARY="${SUMMARY}⚠️ **Spell Checking**: Potential typos found\n"
HAS_WARNING=true
if [ -f spell-check-output.txt ]; then
SUMMARY="${SUMMARY}\`\`\`\n$(cat spell-check-output.txt | head -15)\n\`\`\`\n"
fi
fi
# Grammar check results
if [ "${{ steps.grammar-check.outputs.status }}" = "success" ]; then
SUMMARY="${SUMMARY}✅ **Grammar Checking**: Looks good\n"
else
SUMMARY="${SUMMARY}⚠️ **Grammar Checking**: Suggestions found\n"
HAS_WARNING=true
if [ -f grammar-check-output.txt ]; then
SUMMARY="${SUMMARY}\`\`\`\n$(cat grammar-check-output.txt | head -15)\n\`\`\`\n"
fi
fi
# Final status
if [ "$HAS_CRITICAL" = "true" ]; then
SUMMARY="${SUMMARY}\n---\n❌ **Status**: BLOCKING - Please fix critical issues before merging.\n"
echo "final_status=critical" >> $GITHUB_OUTPUT
elif [ "$HAS_WARNING" = "true" ]; then
SUMMARY="${SUMMARY}\n---\n⚠️ **Status**: Warnings found - Review recommended but not blocking.\n"
echo "final_status=warning" >> $GITHUB_OUTPUT
else
SUMMARY="${SUMMARY}\n---\n✅ **Status**: All checks passed!\n"
echo "final_status=success" >> $GITHUB_OUTPUT
fi
echo "$SUMMARY" > summary.txt
echo "summary<<EOF" >> $GITHUB_OUTPUT
cat summary.txt >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Post results as PR comment
if: steps.changed-files.outputs.has_changes == 'true' && github.event_name == 'pull_request'
uses: actions/github-script@v8
env:
SUMMARY: ${{ steps.summary.outputs.summary }}
with:
script: |
const summary = process.env.SUMMARY;
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const botComment = comments.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('Documentation Quality Check Results')
);
const commentBody = summary;
if (botComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: commentBody
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: commentBody
});
}
- name: Fail if critical issues found
if: steps.changed-files.outputs.has_changes == 'true' && steps.summary.outputs.final_status == 'critical'
run: |
echo "❌ Critical documentation issues found. Please fix before merging."
exit 1
- name: Success
if: steps.changed-files.outputs.has_changes == 'true'
run: echo "✅ Documentation quality checks completed"