Skip to content

Commit c2f6067

Browse files
authored
Try to fix file path validation documentation-review.yml
1 parent 325f9e6 commit c2f6067

File tree

1 file changed

+171
-0
lines changed

1 file changed

+171
-0
lines changed

.github/workflows/documentation-review.yml

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,177 @@ jobs:
4444
if [ -n "${{ github.event.inputs.target_files }}" ]; then
4545
echo "Validating specific files: ${{ github.event.inputs.target_files }}"
4646
node scripts/style-validation/validate-content-style.js --verbose ${{ github.event.inputs.target_files }}
47+
elif [ "${{ github.event_name }}" = "pull_request" ]; then
48+
echo "Validating changed files in PR"
49+
# Get changed files from the PR and filter for .md/.mdx
50+
git diff --name-only ${{ github.event.pull_request.base.sha }} | grep -E '\.(md|mdx)
51+
52+
- name: Comment PR with results
53+
uses: actions/github-script@v7
54+
with:
55+
script: |
56+
const fs = require('fs');
57+
const path = require('path');
58+
59+
try {
60+
// Read validation results
61+
const resultsPath = 'docusaurus/style-check-results.json';
62+
63+
if (!fs.existsSync(resultsPath)) {
64+
console.log('No results file found, validation may have failed');
65+
66+
// Only try to comment if we're in a PR context or manual run with PR number
67+
if (context.eventName === 'pull_request') {
68+
await github.rest.issues.createComment({
69+
issue_number: context.issue.number,
70+
owner: context.repo.owner,
71+
repo: context.repo.repo,
72+
body: '## ❌ Documentation Style Review\n\n' +
73+
'Validation script failed to run. Please check the GitHub Action logs.\n\n' +
74+
'This might be due to missing files or configuration issues.'
75+
});
76+
} else if (github.event.inputs && github.event.inputs.pr_number) {
77+
await github.rest.issues.createComment({
78+
issue_number: parseInt(github.event.inputs.pr_number),
79+
owner: context.repo.owner,
80+
repo: context.repo.repo,
81+
body: '## ❌ Documentation Style Review\n\n' +
82+
'Validation script failed to run. Please check the GitHub Action logs.\n\n' +
83+
'This might be due to missing files or configuration issues.'
84+
});
85+
} else {
86+
console.log('No results file found and no PR to comment on. Manual run completed.');
87+
}
88+
return;
89+
}
90+
91+
const results = JSON.parse(fs.readFileSync(resultsPath, 'utf8'));
92+
93+
// Generate comment
94+
let comment = '## 🎯 Strapi Documentation Style Review\n\n';
95+
comment += `*Based on Strapi's 12 Rules of Technical Writing*\n\n`;
96+
97+
// Summary
98+
comment += '### 📊 Summary\n';
99+
comment += `- **Files checked:** ${results.summary.filesProcessed}\n`;
100+
comment += `- **Total issues:** ${results.summary.totalIssues}\n`;
101+
comment += `- **Critical errors:** ${results.issues.errors.length} 🚨\n`;
102+
comment += `- **Warnings:** ${results.issues.warnings.length} ⚠️\n`;
103+
comment += `- **Suggestions:** ${results.issues.suggestions.length} 💡\n\n`;
104+
105+
if (results.summary.totalIssues === 0) {
106+
comment += '🎉 **Perfect!** Your documentation follows all 12 rules of technical writing.\n\n';
107+
} else {
108+
// Show critical errors
109+
if (results.issues.errors.length > 0) {
110+
comment += '### 🚨 Critical Issues (must fix)\n\n';
111+
results.issues.errors.slice(0, 5).forEach(error => {
112+
const fileName = error.file.replace(/^.*\/docs\//, 'docs/');
113+
comment += `**${fileName}:${error.line}**\n`;
114+
comment += `- ${error.message}\n`;
115+
if (error.suggestion) {
116+
comment += `- 💡 *${error.suggestion}*\n`;
117+
}
118+
comment += '\n';
119+
});
120+
121+
if (results.issues.errors.length > 5) {
122+
comment += `*... and ${results.issues.errors.length - 5} more critical issues*\n\n`;
123+
}
124+
}
125+
126+
// Show some warnings
127+
if (results.issues.warnings.length > 0) {
128+
comment += '### ⚠️ Warnings (should address)\n\n';
129+
results.issues.warnings.slice(0, 3).forEach(warning => {
130+
const fileName = warning.file.replace(/^.*\/docs\//, 'docs/');
131+
comment += `**${fileName}:${warning.line}** - ${warning.message}\n`;
132+
});
133+
134+
if (results.issues.warnings.length > 3) {
135+
comment += `\n*... and ${results.issues.warnings.length - 3} more warnings*\n`;
136+
}
137+
comment += '\n';
138+
}
139+
140+
// Show some suggestions
141+
if (results.issues.suggestions.length > 0) {
142+
comment += '### 💡 Suggestions (improvements)\n\n';
143+
results.issues.suggestions.slice(0, 2).forEach(suggestion => {
144+
const fileName = suggestion.file.replace(/^.*\/docs\//, 'docs/');
145+
comment += `**${fileName}:${suggestion.line}** - ${suggestion.message}\n`;
146+
});
147+
148+
if (results.issues.suggestions.length > 2) {
149+
comment += `\n*... and ${results.issues.suggestions.length - 2} more suggestions*\n`;
150+
}
151+
comment += '\n';
152+
}
153+
}
154+
155+
// Add footer
156+
comment += '---\n';
157+
comment += '*🤖 Automated review based on [Strapi\'s 12 Rules of Technical Writing](https://strapi.notion.site/12-Rules-of-Technical-Writing)*\n';
158+
159+
// Add trigger info for manual runs
160+
if (context.eventName === 'workflow_dispatch') {
161+
comment += `*🔧 Manually triggered${github.event.inputs && github.event.inputs.pr_number ? ` for PR #${github.event.inputs.pr_number}` : ''}*\n\n`;
162+
}
163+
164+
// Post comment
165+
if (context.eventName === 'pull_request') {
166+
// Normal PR comment
167+
await github.rest.issues.createComment({
168+
issue_number: context.issue.number,
169+
owner: context.repo.owner,
170+
repo: context.repo.repo,
171+
body: comment
172+
});
173+
} else if (github.event.inputs && github.event.inputs.pr_number) {
174+
// Manual run with PR number
175+
await github.rest.issues.createComment({
176+
issue_number: parseInt(github.event.inputs.pr_number),
177+
owner: context.repo.owner,
178+
repo: context.repo.repo,
179+
body: comment
180+
});
181+
} else {
182+
// Manual run without PR - just log
183+
console.log('Manual validation completed');
184+
console.log(comment);
185+
}
186+
187+
// Set step output for potential failure
188+
if (results.issues.errors.length > 0) {
189+
core.setFailed(`Found ${results.issues.errors.length} critical errors that must be fixed.`);
190+
}
191+
192+
} catch (error) {
193+
console.error('Error processing results:', error);
194+
195+
// Only try to comment if we're in a PR context or manual run with PR number
196+
if (context.eventName === 'pull_request') {
197+
await github.rest.issues.createComment({
198+
issue_number: context.issue.number,
199+
owner: context.repo.owner,
200+
repo: context.repo.repo,
201+
body: '## ❌ Documentation Style Review Failed\n\n' +
202+
'There was an error running the style validation. Please check the GitHub Action logs.\n\n' +
203+
`Error: ${error.message}`
204+
});
205+
} else if (github.event.inputs && github.event.inputs.pr_number) {
206+
await github.rest.issues.createComment({
207+
issue_number: parseInt(github.event.inputs.pr_number),
208+
owner: context.repo.owner,
209+
repo: context.repo.repo,
210+
body: '## ❌ Documentation Style Review Failed\n\n' +
211+
'There was an error running the style validation. Please check the GitHub Action logs.\n\n' +
212+
`Error: ${error.message}`
213+
});
214+
} else {
215+
console.log(`Manual validation failed: ${error.message}`);
216+
}
217+
} | head -10 | xargs -r node scripts/style-validation/validate-content-style.js --verbose
47218
else
48219
echo "Validating all documentation files"
49220
node scripts/style-validation/validate-content-style.js --verbose

0 commit comments

Comments
 (0)