name: Docs CI/CD

on:
  push:
    branches:
      - main
    paths:
      - 'docs/**'
permissions:
  contents: read
  pages: write
  id-token: write
jobs:
  build_docs:
    runs-on: ubuntu-latest
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    concurrency:
      group: "pages"
      cancel-in-progress: false
    steps:
      - uses: actions/checkout@v4

      - name: Configure Git Credentials
        run: |
          git config user.name github-actions[bot]
          git config user.email 41898282+github-actions[bot]@users.noreply.github.com

      - name: Setup pnpm
        uses: pnpm/action-setup@v4
        with:
          version: '9.4.0'
          run_install: false

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '20.15.1'
          cache: pnpm

      - name: Install dependencies
        run: pnpm install --filter upage-docs...

      - name: Build docs website
        run: pnpm run docs:build

      - name: Setup Pages
        uses: actions/configure-pages@v4

      - name: Upload artifact
        uses: actions/upload-pages-artifact@v3
        with:
          path: ./docs/build

      - name: Deploy to GitHub Pages
        id: deployment
        uses: actions/deploy-pages@v4
