name: Deploy Oranda to GitHub Pages

on:
  push:
    tags:
      - "v*.*.*"

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

jobs:
  deploy-oranda:
    runs-on: ubuntu-latest
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    steps:
      - uses: actions/checkout@v4

      - name: Install Rust
        uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          override: true

      - name: Install Oranda
        run: cargo install oranda

      - name: Debug before build
        run: |
          echo "Oranda version:"
          oranda --version
          echo "Current directory contents:"
          ls -la
          echo "Oranda config:"
          cat oranda.json || echo "No oranda.json found"

      - name: Build Oranda site
        run: oranda build

      - name: Debug after build
        run: |
          echo "All files after build:"
          find . -type f | grep -E '\.(css|js|html)$' | head -20
          echo "Public directory contents:"
          ls -la ./public/ || echo "No public directory"
          echo "Dist directory contents:"
          ls -la ./dist/ || echo "No dist directory"
          echo "CSS files location:"
          find . -name "*.css" -type f

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

      - name: Upload artifact
        uses: actions/upload-pages-artifact@v3
        with:
          path: "./public"

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