-
Notifications
You must be signed in to change notification settings - Fork 4
142 lines (123 loc) Β· 5.71 KB
/
validate-docs.yml
File metadata and controls
142 lines (123 loc) Β· 5.71 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
name: Validate Documentation
on:
pull_request:
types: [opened, synchronize, reopened] # Run on PR open AND every commit
branches:
- main
paths:
- '**.mdx'
- '**.md'
- 'images/**'
- 'scripts/**'
- '.github/workflows/validate-docs.yml'
jobs:
validate:
name: Check Links and Images
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
- name: Check for broken links
id: check-links
run: |
echo "::group::Checking for broken links"
node scripts/check-links.js > /tmp/check-links-output.txt 2>&1 || echo "issues_found=true" >> $GITHUB_OUTPUT
cat /tmp/check-links-output.txt
echo "::endgroup::"
continue-on-error: true
- name: Check image locations
id: check-images
run: |
echo "::group::Checking image locations"
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
echo "::endgroup::"
continue-on-error: true
- name: Post or update PR comment
if: always() # Always run to update comment even if issues are fixed
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
// Build comment body
let comment = '## π Documentation Validation Report\n\n';
const hasIssues = '${{ steps.check-links.outputs.issues_found }}' === 'true' ||
'${{ steps.check-images.outputs.issues_found }}' === 'true';
if (hasIssues) {
comment += 'β οΈ Some issues were found in this PR. These are **informational warnings** and will not block merging.\n\n';
} else {
comment += 'β
All validation checks passed!\n\n';
}
if ('${{ steps.check-links.outputs.issues_found }}' === 'true') {
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 += '### π Links\n';
if (brokenLinks.length > 0) {
comment += '<details><summary>β Found broken links (click to expand)</summary>\n\n';
comment += '```\n' + brokenLinks.join('\n') + '\n```\n';
comment += '</details>\n\n';
}
} else {
comment += '### π Links\nβ
All links valid\n\n';
}
if ('${{ steps.check-images.outputs.issues_found }}' === 'true') {
const imagesOutput = fs.readFileSync('/tmp/check-images-output.txt', 'utf8');
const lines = imagesOutput.split('\n');
const imageIssues = lines.filter(line => line.includes('π') || line.includes('Expected in:')).slice(0, 10);
comment += '### πΌοΈ Images\n';
if (imageIssues.length > 0) {
comment += '<details><summary>β Found image location issues (click to expand)</summary>\n\n';
comment += '```\n' + imageIssues.join('\n') + '\n```\n';
comment += '</details>\n\n';
}
} else {
comment += '### πΌοΈ Images\nβ
All images in correct locations\n\n';
}
comment += '---\n';
comment += 'π‘ **Quick Reference:**\n';
comment += '- A page at `guides/dashboard.mdx` should use images from `images/guides/dashboard/`\n';
comment += '- Shared images can be placed in parent directories\n';
comment += '- All internal links must point to existing files\n\n';
comment += 'π Run `node scripts/check-links.js` and `node scripts/check-image-locations.js` locally for full details.\n';
// Find existing comment from this bot
const { data: comments } = await github.rest.issues.listComments({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
});
const botComment = comments.find(c =>
c.user.type === 'Bot' && c.body.includes('π Documentation Validation Report')
);
// Update existing or create new
if (botComment) {
await github.rest.issues.updateComment({
comment_id: botComment.id,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});
} else {
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});
}
- name: Report results
if: always()
run: |
if [ "${{ steps.check-links.outputs.issues_found }}" == "true" ] || [ "${{ steps.check-images.outputs.issues_found }}" == "true" ]; then
echo "## Documentation Validation Warnings β οΈ" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Issues found - see PR comment for details" >> $GITHUB_STEP_SUMMARY
else
echo "## Documentation Validation Passed β
" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "All links are valid and images are in the correct locations!" >> $GITHUB_STEP_SUMMARY
fi