# check spelling, codestyle
name: Style and Docstring Check

on: [pull_request, workflow_dispatch]

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

env:
  PYTEST_ADDOPTS: "--color=yes"

permissions:
  id-token: none

jobs:
  docstringcheck:
    runs-on: ubuntu-22.04
    steps:
      - uses: actions/checkout@v4
        with:
          persist-credentials: false

      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: 3.13
          cache: "pip"

      - uses: actions/cache@v4
        with:
          path: ~/.local/share/pyvista/examples
          key: Examples-Data-${{ hashFiles('*') }}
          restore-keys: |
            Examples-Data-

      - name: Install pyvista and doctest requirements
        run: |
          pip install --upgrade pip
          pip install -e . --group test

      - name: Setup headless display
        uses: pyvista/setup-headless-display-action@7d84ae825e6d9297a8e99bdbbae20d1b919a0b19

      - name: Software Report
        run: |
          python -c "import pyvista; print(pyvista.Report()); from pyvista import examples; print('Examples path:', examples.USER_DATA_PATH)"
          which python
          pip list

      - name: Test Package Docstrings
        run: make doctest-modules

      - name: Test Package Docstrings with Local Namespace
        run: make doctest-modules-local-namespace

  vale:
    name: Vale
    runs-on: ubuntu-22.04
    steps:
      - uses: actions/checkout@v4
        with:
          persist-credentials: false

      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: 3.13

      - name: Install test dependencies
        run: |
          pip install --upgrade pip
          pip install . --group docs

      # this is equivalent to
      # vale --config doc/.vale.ini doc pyvista examples
      # GHA SHA is pinned to a reviewdog branch commit
      - name: "Run Vale"
        uses: errata-ai/vale-action@dcded780f1ff68e2558e802a165a484a4a3e2fb8
        with:
          files: '["doc", "pyvista", "examples"]'
          vale_flags: "--config=doc/.vale.ini"
          reporter: github-pr-check
          level: error
          filter_mode: nofilter
          fail_on_error: true
          version: 2.29.5
          reviewdog_url: https://github.com/reviewdog/reviewdog/releases/download/v0.17.5/reviewdog_0.17.5_Linux_x86_64.tar.gz
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
