feat: Add GitHub Action to generate C4 diagrams #3
Workflow file for this run
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: Generate C4 Diagrams | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - develop | |
| paths: | |
| - 'docs/c4-diagram.structurizr' | |
| - '.github/workflows/generate-c4-diagrams.yml' | |
| pull_request: | |
| paths: | |
| - 'docs/c4-diagram.structurizr' | |
| - '.github/workflows/generate-c4-diagrams.yml' | |
| workflow_dispatch: | |
| jobs: | |
| generate-diagrams: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| # For PRs from same repo, checkout the head branch to allow commits | |
| # For PRs from forks, checkout base branch (no write access anyway) | |
| ref: ${{ github.event.pull_request && github.event.pull_request.head.repo.full_name == github.repository && github.event.pull_request.head.ref || github.ref }} | |
| - name: Generate C4 diagrams | |
| run: | | |
| docker run --rm -v ${{ github.workspace }}/docs:/docs extenda/structurizr-to-png \ | |
| --path c4-diagram.structurizr \ | |
| --output images | |
| - name: Commit and push changes | |
| # Only attempt to commit if it's a push event or a PR from the same repository | |
| if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) | |
| run: | | |
| git config --local user.email "github-actions[bot]@users.noreply.github.com" | |
| git config --local user.name "github-actions[bot]" | |
| git add docs/images/ | |
| if ! git diff --staged --quiet; then | |
| git commit -m "chore: update C4 diagrams [skip ci]" | |
| git push | |
| else | |
| echo "No changes in generated diagrams" | |
| fi | |
| - name: Upload diagrams as artifacts | |
| # Upload artifacts for PRs from forks (they can't push commits) | |
| if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: c4-diagrams | |
| path: docs/images/ | |
| retention-days: 7 |