Skip to content

Merge pull request #1 from AFASSoftware/rename-files-script #6

Merge pull request #1 from AFASSoftware/rename-files-script

Merge pull request #1 from AFASSoftware/rename-files-script #6

name: Markdown Naming Convention Check
# Trigger the workflow on push and pull request events
on:
push:
branches:
- main
- develop
paths:
- 'MarkdownPages/**.md'
pull_request:
branches:
- main
- develop
paths:
- '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:
# Checkout the repository code
- name: Checkout repository
uses: actions/checkout@v4
with:
# Fetch full history for better file analysis
fetch-depth: 0
# Set up Python environment
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
cache: 'pip'
# Install dependencies (if any are added in the future)
- name: Install dependencies
run: |
python -m pip install --upgrade pip
# Add any future dependencies here
# pip install -r requirements.txt
shell: bash
# 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: validation
run: |
echo "Starting markdown file naming validation..."
python scripts/markdown-naming-check.py --root-path MarkdownPages
shell: bash
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
python scripts/markdown-naming-check.py --root-path MarkdownPages --json > validation-report.json
validation_exit_code=$?
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@v4
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 start with a capital letter."
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@v4
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 start with a capital letter." >> $GITHUB_STEP_SUMMARY
fi
else
echo "- **Status:** ❌ Validation report not found" >> $GITHUB_STEP_SUMMARY
fi
shell: bash