name: Check Links in Documentation
on:
  schedule:
    # First day of month at 05:46 in every 2nd month
    - cron: '46 5 1 */2 *'
  pull_request:
    paths:
      - .github/workflows/docs-linkcheck.yml

permissions: {}

jobs:
  test-sphinx-build:
    name: test-sphinx-linkcheck
    runs-on: ${{matrix.os}}
    strategy:
      matrix:
        python-version: ['3.12']
        os: [ubuntu-latest]
      fail-fast: False
    steps:
      - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
        with:
          persist-credentials: false
      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0
        with:
          python-version: ${{ matrix.python-version }}
      - name: Install dependencies
        run: |
          python -W ignore -m pip install --upgrade pip
          python -W ignore -m pip install .[all] --group all
      - name: Check Links
        run: sphinx-build docs/source docs/build/html --keep-going -j auto -b linkcheck
      - name: Upload linkcheck output
        # Run also if the previous steps failed
        if: always()
        uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
        with:
          name: linkcheck-output
          path: docs/build/html/output.*
