name: Jarvis Readiness

on:
  push:
    branches:
      - main
    paths:
      - "src/**"
      - "tests/**"
      - "scripts/**"
      - "config/release-channels.json"
      - "config/quality-trend-baselines.json"
      - "docs/evals/**"
      - "Makefile"
      - "README.md"
      - ".github/workflows/jarvis-readiness.yml"
  pull_request:
    paths:
      - "src/**"
      - "tests/**"
      - "scripts/**"
      - "config/release-channels.json"
      - "config/quality-trend-baselines.json"
      - "docs/evals/**"
      - "Makefile"
      - "README.md"
      - ".github/workflows/jarvis-readiness.yml"
  workflow_dispatch:
    inputs:
      profile:
        description: "Readiness profile"
        type: choice
        default: fast
        options:
          - fast
          - full

concurrency:
  group: jarvis-readiness-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
  cancel-in-progress: true

jobs:
  readiness:
    runs-on: ubuntu-latest
    timeout-minutes: 45
    steps:
      - name: Checkout
        uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

      - name: Set up Python
        uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
        with:
          python-version: "3.12"

      - name: Install uv
        uses: astral-sh/setup-uv@5a095e7a2014a4212f075830d4f7277575a9d098 # v7.3.1

      - name: Sync dependencies
        run: uv sync --extra dev

      - name: Run readiness suite
        run: |
          profile="${{ github.event.inputs.profile }}"
          if [[ -z "$profile" ]]; then
            profile="fast"
          fi
          ./scripts/jarvis_readiness.sh "$profile"

      - name: Upload readiness artifacts
        if: always()
        uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
        with:
          name: jarvis-readiness-${{ github.run_id }}
          path: .artifacts/quality
          if-no-files-found: warn
