|
| 1 | +name: Lint Markdown and Mermaid |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main, develop ] |
| 6 | + paths: |
| 7 | + - '**/*.md' |
| 8 | + - '**/*.mermaid' |
| 9 | + - '**/*.mmd' |
| 10 | + - '.github/workflows/lint-markdown-mermaid.yml' |
| 11 | + pull_request: |
| 12 | + branches: [ main, develop ] |
| 13 | + paths: |
| 14 | + - '**/*.md' |
| 15 | + - '**/*.mermaid' |
| 16 | + - '**/*.mmd' |
| 17 | + - '.github/workflows/lint-markdown-mermaid.yml' |
| 18 | + |
| 19 | +jobs: |
| 20 | + lint-markdown: |
| 21 | + runs-on: ubuntu-latest |
| 22 | + |
| 23 | + steps: |
| 24 | + - uses: actions/checkout@v4 |
| 25 | + |
| 26 | + - name: Set up Node.js |
| 27 | + uses: actions/setup-node@v4 |
| 28 | + with: |
| 29 | + node-version: '20' |
| 30 | + |
| 31 | + - name: Install markdownlint-cli |
| 32 | + run: npm install -g markdownlint-cli |
| 33 | + |
| 34 | + - name: Create markdownlint config |
| 35 | + run: | |
| 36 | + cat > .markdownlint.json << 'EOF' |
| 37 | + { |
| 38 | + "default": true, |
| 39 | + "MD013": false, |
| 40 | + "MD033": false, |
| 41 | + "MD041": false |
| 42 | + } |
| 43 | + EOF |
| 44 | + |
| 45 | + - name: Lint Markdown files |
| 46 | + run: | |
| 47 | + markdownlint '**/*.md' --ignore node_modules || exit 0 |
| 48 | + echo "✓ Markdown linting complete (warnings only)" |
| 49 | + |
| 50 | + validate-mermaid: |
| 51 | + runs-on: ubuntu-latest |
| 52 | + |
| 53 | + steps: |
| 54 | + - uses: actions/checkout@v4 |
| 55 | + |
| 56 | + - name: Set up Python |
| 57 | + uses: actions/setup-python@v5 |
| 58 | + with: |
| 59 | + python-version: '3.9' |
| 60 | + |
| 61 | + - name: Validate Mermaid syntax |
| 62 | + run: | |
| 63 | + python3 << 'EOF' |
| 64 | + import os |
| 65 | + import re |
| 66 | + import sys |
| 67 | + |
| 68 | + def validate_mermaid_file(filepath): |
| 69 | + """Basic Mermaid syntax validation""" |
| 70 | + with open(filepath, 'r') as f: |
| 71 | + content = f.read().strip() |
| 72 | + |
| 73 | + if not content: |
| 74 | + print(f" ✗ File is empty") |
| 75 | + return False |
| 76 | + |
| 77 | + # Check for basic Mermaid diagram types |
| 78 | + diagram_types = [ |
| 79 | + 'graph', 'flowchart', 'sequenceDiagram', 'classDiagram', |
| 80 | + 'stateDiagram', 'erDiagram', 'gantt', 'pie', 'journey', |
| 81 | + 'gitGraph', 'mindmap', 'timeline', 'quadrantChart' |
| 82 | + ] |
| 83 | + |
| 84 | + has_diagram_type = any(dtype in content for dtype in diagram_types) |
| 85 | + |
| 86 | + if not has_diagram_type: |
| 87 | + print(f" ⚠ Warning: No recognized diagram type found") |
| 88 | + return True # Warning only |
| 89 | + |
| 90 | + print(f" ✓ Valid basic syntax") |
| 91 | + return True |
| 92 | + |
| 93 | + print("Checking Mermaid diagram syntax...") |
| 94 | + all_valid = True |
| 95 | + |
| 96 | + # Find all .mermaid and .mmd files |
| 97 | + for root, dirs, files in os.walk('.'): |
| 98 | + for file in files: |
| 99 | + if file.endswith('.mermaid') or file.endswith('.mmd'): |
| 100 | + filepath = os.path.join(root, file) |
| 101 | + print(f"Validating: {filepath}") |
| 102 | + if not validate_mermaid_file(filepath): |
| 103 | + all_valid = False |
| 104 | + |
| 105 | + if all_valid: |
| 106 | + print("\n✓ All Mermaid diagrams have valid basic syntax") |
| 107 | + sys.exit(0) |
| 108 | + else: |
| 109 | + print("\n✗ Some Mermaid diagrams have syntax issues") |
| 110 | + sys.exit(1) |
| 111 | + EOF |
0 commit comments