name: Validate

on:
  push:
    branches:
      - main
  pull_request:

jobs:
  validate:
    name: Validate and build
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v6

      - name: Set up Node.js
        uses: actions/setup-node@v6
        with:
          node-version: "22"
          cache: "npm"

      - name: Install dependencies
        run: npm install

      - name: Configure git identity (required by tests)
        run: |
          git config --global user.name "CI"
          git config --global user.email "ci@agentboot.dev"

      - name: Validate personas and traits
        run: npm run validate

      - name: Build
        run: npm run build

      - name: Run tests
        run: npm test

      - name: Check PERSONAS.md is up to date
        run: |
          if ! git diff --exit-code PERSONAS.md; then
            echo ""
            echo "PERSONAS.md is out of date."
            echo "Run 'npm run build' locally and commit the updated PERSONAS.md."
            exit 1
          fi
