[WIP] Add smart workflows for repository management #2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Lint Markdown and Mermaid | |
| on: | |
| push: | |
| branches: [ main, develop ] | |
| paths: | |
| - '**/*.md' | |
| - '**/*.mermaid' | |
| - '**/*.mmd' | |
| - '.github/workflows/lint-markdown-mermaid.yml' | |
| pull_request: | |
| branches: [ main, develop ] | |
| paths: | |
| - '**/*.md' | |
| - '**/*.mermaid' | |
| - '**/*.mmd' | |
| - '.github/workflows/lint-markdown-mermaid.yml' | |
| jobs: | |
| lint-markdown: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| - name: Install markdownlint-cli | |
| run: npm install -g markdownlint-cli | |
| - name: Create markdownlint config | |
| run: | | |
| cat > .markdownlint.json << 'EOF' | |
| { | |
| "default": true, | |
| "MD013": false, | |
| "MD033": false, | |
| "MD041": false | |
| } | |
| EOF | |
| - name: Lint Markdown files | |
| run: | | |
| markdownlint '**/*.md' --ignore node_modules || exit 0 | |
| echo "✓ Markdown linting complete (warnings only)" | |
| validate-mermaid: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.9' | |
| - name: Validate Mermaid syntax | |
| run: | | |
| python3 << 'EOF' | |
| import os | |
| import re | |
| import sys | |
| def validate_mermaid_file(filepath): | |
| """Basic Mermaid syntax validation""" | |
| with open(filepath, 'r') as f: | |
| content = f.read().strip() | |
| if not content: | |
| print(f" ✗ File is empty") | |
| return False | |
| # Check for basic Mermaid diagram types | |
| diagram_types = [ | |
| 'graph', 'flowchart', 'sequenceDiagram', 'classDiagram', | |
| 'stateDiagram', 'erDiagram', 'gantt', 'pie', 'journey', | |
| 'gitGraph', 'mindmap', 'timeline', 'quadrantChart' | |
| ] | |
| has_diagram_type = any(dtype in content for dtype in diagram_types) | |
| if not has_diagram_type: | |
| print(f" ⚠ Warning: No recognized diagram type found") | |
| return True # Warning only | |
| print(f" ✓ Valid basic syntax") | |
| return True | |
| print("Checking Mermaid diagram syntax...") | |
| all_valid = True | |
| # Find all .mermaid and .mmd files | |
| for root, dirs, files in os.walk('.'): | |
| for file in files: | |
| if file.endswith('.mermaid') or file.endswith('.mmd'): | |
| filepath = os.path.join(root, file) | |
| print(f"Validating: {filepath}") | |
| if not validate_mermaid_file(filepath): | |
| all_valid = False | |
| if all_valid: | |
| print("\n✓ All Mermaid diagrams have valid basic syntax") | |
| sys.exit(0) | |
| else: | |
| print("\n✗ Some Mermaid diagrams have syntax issues") | |
| sys.exit(1) | |
| EOF |