name: Sphinx

on:
  pull_request:
    paths:
      - "**/*.rst"
  push:
    paths:
      - "**/*.rst"

permissions:
  contents: "read"

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

jobs:
  sphinx:
    name: Sphinx reStructuredText validity
    runs-on: ubuntu-latest
    timeout-minutes: 1
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
      - name: Cache pip
        uses: actions/cache@v4
        with:
          path: ~/.cache/pip
          key: ${{ runner.os }}-pip-sphinx-lint
      - name: Install sphinx-lint
        run: |
          pip install --user sphinx-lint
      - name: Check Sphinx document sources
        run: |
          git ls-files --cached -z -- '*.rst' \
            | xargs --null -- python -m sphinxlint --enable all --disable trailing-whitespace --max-line-length 2000
