-
Notifications
You must be signed in to change notification settings - Fork 3
214 lines (179 loc) Β· 8.01 KB
/
validate-docs.yml
File metadata and controls
214 lines (179 loc) Β· 8.01 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
name: Validate and Auto-fix Documentation
on:
pull_request:
types: [opened, synchronize, reopened]
branches:
- main
paths:
- '**.mdx'
- '**.md'
- 'images/**'
- 'scripts/**'
- '.github/workflows/validate-docs.yml'
permissions:
contents: write
pull-requests: write
jobs:
validate-and-fix:
name: Check and Auto-fix Documentation
runs-on: ubuntu-latest
steps:
- name: Checkout PR branch
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
- name: Post initial status comment
id: initial-comment
uses: actions/github-script@v7
with:
script: |
const { data: comment } = await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '## π§ Documentation Bot\n\nChecking for issues and fixing what I can...'
});
core.setOutput('comment_id', comment.id);
- name: Check for broken links
id: check-links
run: |
node scripts/check-links.js > /tmp/check-links-output.txt 2>&1 || echo "issues_found=true" >> $GITHUB_OUTPUT
cat /tmp/check-links-output.txt
continue-on-error: true
- name: Check image locations
id: check-images
run: |
node scripts/check-image-locations.js > /tmp/check-images-output.txt 2>&1 || echo "issues_found=true" >> $GITHUB_OUTPUT
cat /tmp/check-images-output.txt
continue-on-error: true
- name: Auto-fix image locations
id: fix-images
if: steps.check-images.outputs.issues_found == 'true'
run: |
echo "Running auto-fix for image locations..."
node scripts/fix-image-locations.js > /tmp/fix-output.txt 2>&1
cat /tmp/fix-output.txt
# Check if any files were modified
if git diff --quiet && git diff --cached --quiet; then
echo "fixed_count=0" >> $GITHUB_OUTPUT
echo "No changes made (images might be missing or other unfixable issues)"
else
# Count the number of images that were fixed
FIXED_COUNT=$(grep -c "β Moved image" /tmp/fix-output.txt || echo "0")
echo "fixed_count=$FIXED_COUNT" >> $GITHUB_OUTPUT
echo "Fixed $FIXED_COUNT image(s)"
fi
continue-on-error: true
- name: Commit fixes
if: steps.fix-images.outputs.fixed_count != '0'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add -A
git commit -m "π€ Auto-fix: Move images to correct directories
Automatically fixed image location issues.
Co-Authored-By: GitHub Actions <github-actions[bot]@users.noreply.github.com>"
git push
- name: Re-check after fixes
id: recheck
if: steps.fix-images.outputs.fixed_count != '0'
run: |
echo "Re-checking image locations after fixes..."
if node scripts/check-image-locations.js > /tmp/recheck-output.txt 2>&1; then
echo "remaining_issues=false" >> $GITHUB_OUTPUT
else
echo "remaining_issues=true" >> $GITHUB_OUTPUT
fi
continue-on-error: true
- name: Update final status comment
if: always()
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
let comment = '## π€ Documentation Bot\n\n';
const hasLinkIssues = '${{ steps.check-links.outputs.issues_found }}' === 'true';
const fixedCount = parseInt('${{ steps.fix-images.outputs.fixed_count }}' || '0');
const hasRemainingImageIssues = '${{ steps.recheck.outputs.remaining_issues }}' === 'true';
// Build status summary
const statuses = [];
if (fixedCount > 0) {
statuses.push(`β
Fixed ${fixedCount} misplaced image${fixedCount > 1 ? 's' : ''}`);
}
if (hasRemainingImageIssues) {
statuses.push('β οΈ Some image issues could not be auto-fixed (missing files or invalid types)');
}
if (hasLinkIssues) {
const linksOutput = fs.readFileSync('/tmp/check-links-output.txt', 'utf8');
const lines = linksOutput.split('\n');
const brokenLinkCount = lines.filter(line => line.includes('π')).length;
statuses.push(`β οΈ ${brokenLinkCount} broken link${brokenLinkCount > 1 ? 's' : ''} need${brokenLinkCount === 1 ? 's' : ''} manual attention`);
}
if (statuses.length === 0) {
comment += 'β
**All checks passed!** No issues found.\n';
} else {
comment += '### Status\n\n';
statuses.forEach(status => {
comment += `${status}\n`;
});
comment += '\n';
}
// Add details for broken links if any
if (hasLinkIssues) {
const linksOutput = fs.readFileSync('/tmp/check-links-output.txt', 'utf8');
const lines = linksOutput.split('\n');
const brokenLinks = lines.filter(line => line.includes('Broken link:') || line.includes('π')).slice(0, 10);
comment += '---\n\n';
comment += '### π Broken Links (Manual Fix Required)\n\n';
comment += '<details><summary>Click to view details</summary>\n\n';
comment += '```\n' + brokenLinks.join('\n') + '\n```\n';
comment += '</details>\n';
}
// Add details for unfixable image issues if any
if (hasRemainingImageIssues) {
comment += '\n---\n\n';
comment += '### πΌοΈ Image Issues (Manual Fix Required)\n\n';
comment += 'Some image issues could not be automatically fixed. These typically include:\n';
comment += '- Missing image files\n';
comment += '- Invalid file types\n';
comment += '\nPlease review and fix these manually.\n';
}
// Update the initial comment
await github.rest.issues.updateComment({
comment_id: '${{ steps.initial-comment.outputs.comment_id }}',
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});
- name: Report summary and fail if needed
if: always()
run: |
FIXED_COUNT="${{ steps.fix-images.outputs.fixed_count }}"
HAS_LINK_ISSUES="${{ steps.check-links.outputs.issues_found }}"
HAS_REMAINING_ISSUES="${{ steps.recheck.outputs.remaining_issues }}"
echo "## Documentation Check Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ "$FIXED_COUNT" != "0" ]; then
echo "β
Auto-fixed $FIXED_COUNT image location issue(s)" >> $GITHUB_STEP_SUMMARY
fi
if [ "$HAS_LINK_ISSUES" == "true" ]; then
echo "β Broken links found - fix required before merging" >> $GITHUB_STEP_SUMMARY
fi
if [ "$HAS_REMAINING_ISSUES" == "true" ]; then
echo "β οΈ Some image issues could not be auto-fixed" >> $GITHUB_STEP_SUMMARY
fi
if [ "$FIXED_COUNT" == "0" ] && [ "$HAS_LINK_ISSUES" != "true" ] && [ "$HAS_REMAINING_ISSUES" != "true" ]; then
echo "β
All checks passed!" >> $GITHUB_STEP_SUMMARY
fi
# Fail the workflow if there are broken links
if [ "$HAS_LINK_ISSUES" == "true" ]; then
echo "::error::Broken links found. Please fix them before merging."
exit 1
fi