Repository navigation
Netbox → Network Diagram #11
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: Netbox → Network Diagram | |
| on: | |
| schedule: | |
| - cron: '0 18 * * 1' # Every Monday 18:00 UTC | |
| workflow_dispatch: # Manual trigger from Actions UI | |
| permissions: | |
| contents: write # Required to commit diagram back to repo | |
| jobs: | |
| generate-diagram: | |
| name: Generate network diagram from Netbox | |
| runs-on: ubuntu-latest | |
| steps: | |
| # ── 1. Checkout ────────────────────────────────────────────────────────── | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 1 | |
| # ── 2. Python setup ─────────────────────────────────────────────────────── | |
| - name: Set up Python 3.13 | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: '3.13' | |
| # ── 3. Install dependencies ─────────────────────────────────────────────── | |
| - name: Install Python dependencies | |
| run: | | |
| pip install --upgrade pip | |
| sudo apt-get install -y libcairo2-dev pkg-config python3-dev 2>/dev/null || true | |
| pip install cairosvg || echo "cairosvg install failed – PNG export skipped" | |
| # ── 4. Create assets directory ──────────────────────────────────────────── | |
| - name: Ensure assets directory exists | |
| run: mkdir -p assets | |
| # ── 5. Generate diagram ─────────────────────────────────────────────────── | |
| - name: Generate SVG/PNG from Netbox API | |
| env: | |
| NETBOX_URL: ${{ secrets.NETBOX_URL }} | |
| NETBOX_TOKEN: ${{ secrets.NETBOX_TOKEN }} | |
| run: python scripts/generate_diagram.py | |
| # ── 6. Check for changes ────────────────────────────────────────────────── | |
| - name: Check for diagram changes | |
| id: diff | |
| run: | | |
| git add assets/ | |
| git diff --cached --quiet \ | |
| && echo "changed=false" >> "$GITHUB_OUTPUT" \ | |
| || echo "changed=true" >> "$GITHUB_OUTPUT" | |
| # ── 7. Commit & push ────────────────────────────────────────────────────── | |
| - name: Commit and push updated diagram | |
| if: steps.diff.outputs.changed == 'true' | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git commit -m "chore: update network diagram [skip ci] | |
| Auto-generated by Netbox API · $(date -u +'%Y-%m-%d %H:%M UTC')" | |
| git push | |
| # ── 8. No-op notice ─────────────────────────────────────────────────────── | |
| - name: No changes detected | |
| if: steps.diff.outputs.changed == 'false' | |
| run: echo "Diagram unchanged – nothing to commit." |