-
Notifications
You must be signed in to change notification settings - Fork 2
160 lines (138 loc) · 5.55 KB
/
Copy pathmarkdown-naming-check.yml
File metadata and controls
160 lines (138 loc) · 5.55 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
name: Markdown Naming Convention Check
on:
push:
branches:
- main
- develop
paths:
- 'markdownpages/**/*.md'
- 'markdownpages/*.md'
pull_request:
branches:
- main
- develop
paths:
- 'markdownpages/**/*.md'
- 'markdownpages/*.md'
# Allow manual triggering
workflow_dispatch:
# Define workflow permissions
permissions:
contents: read
pull-requests: read
jobs:
validate-markdown-naming:
name: Validate Markdown File Naming
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v5
# Set up Python environment
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip'
# Install dependencies
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install python-frontmatter PyYAML
# Make the validation script executable
- name: Make script executable
run: chmod +x scripts/markdown-naming-check.py
shell: bash
# Run the markdown naming validation
- name: Run markdown naming validation
id: validate
run: |
echo "Starting markdown file naming validation..."
python scripts/markdown-naming-check.py --root-path markdownpages
continue-on-error: true
# Generate detailed report for PR comments (if needed)
- name: Generate validation report
if: always()
id: report
run: |
echo "Generating detailed validation report..."
# Run the validation and capture both exit code and output
set +e # Temporarily disable exit on error
# Check which directory exists and run validation accordingly
if [ -d "markdownpages" ]; then
python scripts/markdown-naming-check.py --root-path markdownpages --json > validation-report.json
validation_exit_code=$?
else
echo '{"error": "No markdownpages directory found", "success": false, "total_files_checked": 0, "violations_found": 0, "violations": []}' > validation-report.json
validation_exit_code=1
fi
set -e # Re-enable exit on error
# Check if there are violations based on exit code
if [ $validation_exit_code -eq 0 ]; then
echo "validation_status=success" >> $GITHUB_OUTPUT
echo "All markdown files follow naming conventions! ✅" >> $GITHUB_STEP_SUMMARY
else
echo "validation_status=failure" >> $GITHUB_OUTPUT
echo "Markdown naming violations detected! ❌" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "## Validation Report" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`json" >> $GITHUB_STEP_SUMMARY
cat validation-report.json >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
fi
shell: bash
# Upload validation report as artifact
- name: Upload validation report
if: always()
uses: actions/upload-artifact@v5
with:
name: markdown-naming-validation-report
path: validation-report.json
retention-days: 30
if-no-files-found: warn
# Fail the job if validation failed
- name: Check validation result
if: steps.report.outputs.validation_status == 'failure'
run: |
echo "❌ Markdown naming validation failed!"
echo "Please check the validation report and rename files to follow kebab-case convention."
exit 1
shell: bash
# Success message
- name: Validation success
if: steps.report.outputs.validation_status == 'success'
run: |
echo "✅ All markdown files follow the naming convention!"
echo "Validation completed successfully."
shell: bash
# Summary job that runs after validation
summary:
name: Validation Summary
runs-on: ubuntu-latest
needs: validate-markdown-naming
if: always()
steps:
- name: Download validation report
uses: actions/download-artifact@v5
with:
name: markdown-naming-validation-report
- name: Display summary
run: |
echo "## Markdown Naming Validation Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ -f validation-report.json ]; then
# Extract key metrics from the JSON report
total_files=$(jq -r '.total_files_checked // 0' validation-report.json)
violations=$(jq -r '.violations_found // 0' validation-report.json)
success=$(jq -r '.success // false' validation-report.json)
echo "- **Total markdown files checked:** $total_files" >> $GITHUB_STEP_SUMMARY
echo "- **Violations found:** $violations" >> $GITHUB_STEP_SUMMARY
echo "- **Status:** $([ "$success" = "true" ] && echo "✅ PASSED" || echo "❌ FAILED")" >> $GITHUB_STEP_SUMMARY
if [ "$violations" -gt "0" ]; then
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Action Required" >> $GITHUB_STEP_SUMMARY
echo "Please rename the files listed in the validation report to follow kebab-case convention." >> $GITHUB_STEP_SUMMARY
fi
else
echo "- **Status:** ❌ Validation report not found" >> $GITHUB_STEP_SUMMARY
fi
shell: bash