# .gitea/workflows/docs.yml
# Documentation quality checks and preview artefacts

name: Docs CI

on:
  push:
    paths:
      - 'docs/**'
      - 'scripts/render_docs.py'
      - '.gitea/workflows/docs.yml'
  pull_request:
    paths:
      - 'docs/**'
      - 'scripts/render_docs.py'
      - '.gitea/workflows/docs.yml'
  workflow_dispatch: {}

env:
  NODE_VERSION: '20'
  PYTHON_VERSION: '3.11'

jobs:
  lint-and-preview:
    runs-on: ubuntu-22.04
    env:
      DOCS_OUTPUT_DIR: ${{ github.workspace }}/artifacts/docs-preview
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: ${{ env.NODE_VERSION }}

      - name: Install markdown linters
        run: |
          npm install markdown-link-check remark-cli remark-preset-lint-recommended

      - name: Link check
        run: |
          find docs -name '*.md' -print0 | \
            xargs -0 -n1 -I{} npx markdown-link-check --quiet '{}'

      - name: Remark lint
        run: |
          npx remark docs -qf

      - name: Setup Python
        uses: actions/setup-python@v5
        with:
          python-version: ${{ env.PYTHON_VERSION }}

      - name: Install documentation dependencies
        run: |
          python -m pip install --upgrade pip
          python -m pip install markdown pygments

      - name: Render documentation preview bundle
        run: |
          python scripts/render_docs.py --source docs --output "$DOCS_OUTPUT_DIR" --clean

      - name: Upload documentation preview
        if: always()
        uses: actions/upload-artifact@v4
        with:
          name: feedser-docs-preview
          path: ${{ env.DOCS_OUTPUT_DIR }}
          retention-days: 7
