name: Docs And Style
on:
  push:
    branches: ["main"]
  pull_request:
  merge_group:

permissions:
  contents: read

jobs:

  app-regression-tests:
    runs-on: ubuntu-latest
    concurrency:
      group: ${{ github.workflow }}-app-regression-${{ github.ref }}
      cancel-in-progress: true
    steps:
      - uses: actions/checkout@v5
      - name: Setup Node.js
        uses: actions/setup-node@v5
        with:
          node-version: '20'
      - name: Run app regression tests
        run: node test/app/run-app-regression-tests.cjs

  backend-docs-drift:
    # The backend reference doc (docs/dev/backends-reference.md) is generated from
    # the self-describing backend descriptors. Build lemond, regenerate, and fail
    # if the committed doc is stale — the same guarantee a lint provides.
    runs-on: ubuntu-latest
    concurrency:
      group: ${{ github.workflow }}-backend-docs-${{ github.ref }}
      cancel-in-progress: true
    steps:
      - uses: actions/checkout@v5
      - name: Configure and install build dependencies
        run: ./setup.sh
      - name: Build lemond
        run: cmake --build --preset default --target lemond
      - name: Check backend reference docs are up to date
        run: python3 docs/tools/gen_backend_boilerplate.py --check

  markdown-link-check:
    runs-on: ubuntu-latest
    concurrency:
      group: ${{ github.workflow }}-${{ github.ref }}
      cancel-in-progress: true
    steps:
      - uses: actions/checkout@v5
      - name: Setup Node.js
        uses: actions/setup-node@v5
        with:
          node-version: '20'
      - name: Install markdown-link-check
        run: npm install -g markdown-link-check
      - name: Check Markdown links
        shell: bash
        run: |
          # To run this manually on Windows, run:
          #   npm install -g markdown-link-check
          #   Get-ChildItem -Recurse -Filter *.md | ForEach-Object { markdown-link-check $_.FullName -c .\.github\workflows\mlc_config.json }
          set -euo pipefail
          find . -type f -name "*.md" -not -path "./node_modules/*" \
            -exec markdown-link-check -c .github/workflows/mlc_config.json {} \;
