name: Publish docs

on:
  push:
    tags:
      - 'OFDLV*'
    paths:
      - 'docs/**'
      - '.gitea/workflows/publish-docs.yml'
  workflow_dispatch:

jobs:
  build-and-deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version-file: './docs/.nvmrc'

      - name: Install dependencies
        working-directory: ./docs
        run: npm ci

      - name: Build Docusaurus site
        working-directory: ./docs
        run: npm run build

      - name: Deploy to `.gitea/pages/`
        run: |
          git config user.name "Gitea Actions"
          git config user.email "actions@ofdl.tools"

          rm -rf .gitea/pages/*
          mkdir -p .gitea/pages
          cp -r docs/build/* .gitea/pages/

          git add .gitea/pages
          git commit -m "Auto-deploy Docusaurus site to .gitea/pages [skip ci]" || echo "No changes to commit"
          git push origin HEAD
