-
Notifications
You must be signed in to change notification settings - Fork 266
237 lines (185 loc) · 8.25 KB
/
markdown-validation.yml
File metadata and controls
237 lines (185 loc) · 8.25 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
name: Markdown Content Validation
on:
pull_request:
branches: [ main, master ]
paths:
- 'categories/**/*.md'
- 'pages/**/*.md'
- 'scripts/**'
- '.github/workflows/markdown-validation.yml'
jobs:
validate-markdown:
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 metadata completeness
id: check-metadata
run: |
echo "🔍 Checking metadata completeness..."
# Run metadata check and capture output
if node scripts/check-metadata.js > metadata-report.txt 2>&1; then
echo "metadata_status=success" >> $GITHUB_OUTPUT
echo "✅ Metadata validation succeeded"
else
echo "metadata_status=failed" >> $GITHUB_OUTPUT
echo "❌ Metadata validation failed"
fi
# Extract summary statistics
editlink_coverage=$(grep "editlink:" metadata-report.txt | grep -o '[0-9.]*% coverage' | head -1 || echo "0% coverage")
title_coverage=$(grep "title:" metadata-report.txt | grep -o '[0-9.]*% coverage' | head -1 || echo "0% coverage")
echo "editlink_coverage=$editlink_coverage" >> $GITHUB_OUTPUT
echo "title_coverage=$title_coverage" >> $GITHUB_OUTPUT
echo "Metadata check completed"
- name: Validate tags
id: validate-tags
run: |
echo "🏷️ Validating tags against approved list..."
# Run tag validation and capture exit code
if node scripts/validate-tags.js > tag-validation-report.txt 2>&1; then
echo "validation_status=success" >> $GITHUB_OUTPUT
echo "✅ All tags are valid"
else
echo "validation_status=failed" >> $GITHUB_OUTPUT
echo "❌ Tag validation failed"
# Extract invalid tags for summary
invalid_tags=$(grep -A 1000 "INVALID TAGS SUMMARY" tag-validation-report.txt | grep "❌" | head -5 | sed 's/❌ //' || echo "See detailed report for invalid tags")
# Save invalid tags to output (escape for GitHub Actions)
{
echo 'invalid_tags<<EOF'
echo "$invalid_tags"
echo 'EOF'
} >> $GITHUB_OUTPUT
fi
- name: Generate detailed reports
run: |
echo "📋 Generating detailed reports..."
# Create a comprehensive report
cat > validation-summary.md << 'EOF'
# 📊 Markdown Content Validation Report
## Metadata Completeness
**Status**: ${{ steps.check-metadata.outputs.metadata_status == 'success' && '✅ Metadata validation succeeded' || '❌ Metadata validation failed' }}
## Tag Validation
**Status**: ${{ steps.validate-tags.outputs.validation_status == 'success' && '✅ All tags valid' || '❌ Invalid tags found' }}
## Detailed Reports
<details>
<summary>📋 Metadata Analysis Report</summary>
```
EOF
cat metadata-report.txt >> validation-summary.md
cat >> validation-summary.md << 'EOF'
```
</details>
<details>
<summary>🏷️ Tag Validation Report</summary>
```
EOF
cat tag-validation-report.txt >> validation-summary.md
cat >> validation-summary.md << 'EOF'
```
</details>
---
*This report was automatically generated by the Markdown Content Validation workflow.*
EOF
- name: Upload validation reports
uses: actions/upload-artifact@v4
with:
name: markdown-validation-reports
path: |
validation-summary.md
metadata-report.txt
tag-validation-report.txt
- name: Comment on PR
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
// Read the validation summary
const summary = fs.readFileSync('validation-summary.md', 'utf8');
// Determine overall status
const metadataStatus = '${{ steps.check-metadata.outputs.metadata_status }}';
const tagStatus = '${{ steps.validate-tags.outputs.validation_status }}';
let overallStatus = '✅ PASSED';
let statusEmoji = '✅';
if (tagStatus === 'failed') {
overallStatus = '❌ FAILED';
statusEmoji = '❌';
} else if (metadataStatus === 'failed') {
overallStatus = '⚠️ WARNINGS';
statusEmoji = '⚠️';
}
let comment = `
${summary}
## Result
${tagStatus === 'failed' ? '- ❌ **Fix invalid tags** before merging' : '- ✅ All tags are valid'}
`;
// Add specific invalid tags if validation failed
if (tagStatus === 'failed') {
const invalidTags = `${{ steps.validate-tags.outputs.invalid_tags }}`;
if (invalidTags && invalidTags.trim() !== '' && !invalidTags.includes('See detailed report')) {
comment += `
## ❌ Invalid Tags Found
The following tags are not in the approved list:
${invalidTags}
**Fix Required**: Please remove these invalid tags or add them to the approved tags list before merging.
`;
}
}
// Find existing comment
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const existingComment = comments.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('Markdown Content Validation')
);
if (existingComment) {
// Update existing comment
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existingComment.id,
body: comment
});
} else {
// Create new comment
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: comment
});
}
- name: Check validation results
run: |
echo "🔍 Final validation check..."
if [ "${{ steps.validate-tags.outputs.validation_status }}" = "failed" ]; then
echo "❌ Tag validation failed - blocking merge"
echo "Please fix invalid tags before merging this PR"
exit 1
fi
echo "✅ All critical validations passed"
echo "Note: Metadata warnings don't block the merge but should be addressed"
- name: Generate status summary
run: |
echo "## 📊 Validation Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Check | Status | Coverage |" >> $GITHUB_STEP_SUMMARY
echo "|-------|---------|----------|" >> $GITHUB_STEP_SUMMARY
echo "| Tag Validation | ${{ steps.validate-tags.outputs.validation_status == 'success' && '✅ Passed' || '❌ Failed' }} | - |" >> $GITHUB_STEP_SUMMARY
echo "| editlink Field | ⚠️ Warnings | ${{ steps.check-metadata.outputs.editlink_coverage }} |" >> $GITHUB_STEP_SUMMARY
echo "| title Field | ⚠️ Warnings | ${{ steps.check-metadata.outputs.title_coverage }} |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### 🎯 Action Items" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ "${{ steps.validate-tags.outputs.validation_status }}" = "failed" ]; then
echo "- ❌ **CRITICAL**: Fix invalid tags (blocks merge)" >> $GITHUB_STEP_SUMMARY
fi
echo "- 📈 Consider adding missing metadata fields" >> $GITHUB_STEP_SUMMARY
echo "- 📥 Download detailed reports from workflow artifacts" >> $GITHUB_STEP_SUMMARY