name: Deploy Docs

on:
  push:
    branches:
      - master
    paths:
      - "docs/**"
      - "README.md"
      - "Cargo.toml"
      - "CHANGELOG.md"
      - ".github/workflows/docs.yml"
  pull_request:
    paths:
      - "docs/**"
      - "README.md"
      - "Cargo.toml"
      - "CHANGELOG.md"
      - ".github/workflows/docs.yml"

permissions:
  contents: read
  pages: write
  id-token: write

concurrency:
  group: pages-${{ github.ref }}
  cancel-in-progress: true

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v6

      - name: Setup Bun
        uses: oven-sh/setup-bun@v2

      - name: Install dependencies
        run: bun install
        working-directory: docs

      - name: Build static site
        run: bun run build
        working-directory: docs

      - name: Upload artifact
        if: github.ref == 'refs/heads/master'
        uses: actions/upload-pages-artifact@v5
        with:
          path: docs/build

  deploy:
    if: github.ref == 'refs/heads/master'
    needs: build
    runs-on: ubuntu-latest
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    steps:
      - name: Deploy to GitHub Pages
        id: deployment
        uses: actions/deploy-pages@v5
