name: Check Documentation

on:
  pull_request:
    branches:
      - '*'
    paths:
      - '.github/workflows/check_doc.yaml'
      - 'docs/**'

jobs:

  docs:
    name: lint, build and verify
    runs-on: ubuntu-latest

    steps:
      - name: Check out code
        uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
        with:
          fetch-depth: 0

      - name: Install markdownlint
        run: |
          npm install --global markdownlint@0.29.0 markdownlint-cli@0.35.0

      - name: Lint
        run: ./docs/scripts/lint.sh docs

      - name: Setup python
        uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
        with:
          python-version: '3.12'
          cache: 'pip'
          cache-dependency-path: "./docs/requirements.txt"

      - name: Build documentation
        working-directory: ./docs
        run: |
          pip install -r requirements.txt
          mkdocs build --strict

      - name: Setup ruby
        uses: ruby/setup-ruby@90be1154f987f4dc0fe0dd0feedac9e473aa4ba8 # v1.286.0
        with:
          ruby-version: '3.4'

      - name: Install html-proofer
        run: |
          gem install nokogiri --version 1.18.6 --no-document -- --use-system-libraries
          gem install html-proofer --version 5.0.10 --no-document -- --use-system-libraries
        env:
          NOKOGIRI_USE_SYSTEM_LIBRARIES: "true"

      # Comes from https://github.com/gjtorikian/html-proofer?tab=readme-ov-file#caching-with-continuous-integration
      - name: Cache HTMLProofer
        uses: actions/cache@8b402f58fbc84540c8b491a91e594a4576fec3d7 # v5.0.2
        with:
          path: tmp/.htmlproofer
          key: ${{ runner.os }}-htmlproofer

      - name: Verify
        run: ./docs/scripts/verify.sh docs/site
