|
| 1 | +name: Generate Architecture Diagrams |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + pull_request: |
| 6 | + paths: |
| 7 | + - "src/**" |
| 8 | + - "modules/**" |
| 9 | + - "assets/**" |
| 10 | + - "docs/scripts/generate_example_architecture.py" |
| 11 | + - "docs/diagram-generation.md" |
| 12 | + push: |
| 13 | + branches: |
| 14 | + - main |
| 15 | + paths: |
| 16 | + - "src/**" |
| 17 | + - "modules/**" |
| 18 | + - "assets/**" |
| 19 | + - "docs/scripts/generate_example_architecture.py" |
| 20 | + - "docs/diagram-generation.md" |
| 21 | + |
| 22 | +permissions: |
| 23 | + contents: write |
| 24 | + |
| 25 | +jobs: |
| 26 | + generate-diagrams: |
| 27 | + runs-on: ubuntu-latest |
| 28 | + |
| 29 | + steps: |
| 30 | + - name: Checkout |
| 31 | + uses: actions/checkout@v4 |
| 32 | + |
| 33 | + - name: Setup Python |
| 34 | + uses: actions/setup-python@v5 |
| 35 | + with: |
| 36 | + python-version: "3.13" |
| 37 | + |
| 38 | + - name: Setup Node.js |
| 39 | + uses: actions/setup-node@v4 |
| 40 | + with: |
| 41 | + node-version: "20" |
| 42 | + |
| 43 | + - name: Install Mermaid CLI |
| 44 | + run: npm install -g @mermaid-js/mermaid-cli |
| 45 | + |
| 46 | + - name: Generate architecture diagrams |
| 47 | + run: python3 docs/scripts/generate_example_architecture.py --out-dir docs/diagrams |
| 48 | + |
| 49 | + - name: Render Mermaid SVG diagrams |
| 50 | + run: | |
| 51 | + for diagram in docs/diagrams/*.mmd; do |
| 52 | + output="${diagram%.mmd}.svg" |
| 53 | + mmdc -i "$diagram" -o "$output" -c .github/mermaid-config.json -p .github/mermaid-puppeteer-config.json |
| 54 | + done |
| 55 | +
|
| 56 | + - name: Verify generated diagrams are committed (PR) |
| 57 | + if: github.event_name == 'pull_request' |
| 58 | + run: | |
| 59 | + if [[ -n "$(git status --porcelain -- docs/diagrams)" ]]; then |
| 60 | + echo "::error::Generated diagrams are out of date. Run the generator locally and commit the changes." |
| 61 | + git status --short -- docs/diagrams |
| 62 | + exit 1 |
| 63 | + fi |
| 64 | +
|
| 65 | + - name: Commit updated diagrams (main) |
| 66 | + if: github.event_name == 'push' && github.ref == 'refs/heads/main' && github.actor != 'github-actions[bot]' |
| 67 | + uses: stefanzweifel/git-auto-commit-action@v5 |
| 68 | + with: |
| 69 | + commit_message: "chore(diagrams): regenerate architecture diagrams" |
| 70 | + file_pattern: docs/diagrams/*.mmd docs/diagrams/*.mmd.md docs/diagrams/*.svg |
0 commit comments