name: check-generated-pyi

concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.id }}
  cancel-in-progress: true

on:
  push:
    branches: ['main']
    # We don't just trigger on make_pyi.py and the components dir, because
    # there are other things that can change the generator output
    # e.g. black version, reflex.Component, reflex.Var.
    paths-ignore:
      - '**/*.md'
  pull_request:
    branches: ['main']
    paths-ignore:
      - '**/*.md'

jobs:
  check-generated-pyi-components:
    timeout-minutes: 30
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: ./.github/actions/setup_build_env
        with:
          python-version: '3.11.5'
          run-poetry-install: true
          create-venv-at-path: .venv
      - run: |
          poetry run python scripts/make_pyi.py
          if [[ $(git status --porcelain) ]]; then
            git status
            git diff
            echo "ERROR: make_pyi.py output is out of date. Please run scripts/make_pyi.py and commit the changes."
            exit 1
          else
            echo "No diffs - AOK!"
          fi