name: KLYPIX Project Map

on:
  workflow_dispatch:
  pull_request:
  push:
    branches: [main]

permissions:
  contents: read

concurrency:
  group: klypix-project-map-${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

env:
  GRAPHIFY_VERSION: "0.9.33"

jobs:
  project-map:
    name: Generate bounded map artifact
    runs-on: ubuntu-latest
    timeout-minutes: 20
    steps:
      - name: Check out repository
        uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

      - name: Set up uv
        uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
        with:
          enable-cache: true

      - name: Generate code-only graph
        run: uvx --from "graphifyy==${GRAPHIFY_VERSION}" graphify extract . --code-only

      - name: Validate the generated contract
        run: node -e "const fs=require('fs'); const p='graphify-out/graph.json'; const g=JSON.parse(fs.readFileSync(p,'utf8')); if(!Array.isArray(g.nodes)||!(Array.isArray(g.edges)||Array.isArray(g.links))) throw Error('unsupported graph contract'); console.log('Project Map:',g.nodes.length,'nodes');"

      - name: Upload Project Map artifact
        uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
        with:
          name: klypix-project-map-${{ github.sha }}
          path: graphify-out/
          if-no-files-found: error
          retention-days: 14
