name: Deploy to GitHub Pages

on:
  push:
    branches: [main]
    paths-ignore:
      - "**/*.md"
      - "docs-local/**"
      - ".github/ISSUE_TEMPLATE/**"
      - ".github/labeler.yml"
      - ".github/dependabot.yml"
      - ".github/workflows/triage-icon-issue.yml"
      - ".github/workflows/labeler.yml"
      - ".github/workflows/dependabot-auto-merge.yml"
      - "LICENSE"
      - "TRADEMARK.md"
      - "LEGAL.md"
  workflow_dispatch:

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

concurrency:
  group: pages
  cancel-in-progress: false

env:
  NODE_VERSION: "20"

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

      - name: Install pnpm
        uses: pnpm/action-setup@v6
        with:
          version: 9

      - uses: actions/setup-node@v6
        with:
          node-version: ${{ env.NODE_VERSION }}
          cache: pnpm

      - name: Install dependencies
        run: pnpm install --frozen-lockfile

      - name: Restore Next.js build cache
        uses: actions/cache@v5
        with:
          path: |
            .next/cache
          key: nextjs-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }}-${{ hashFiles('**/*.[jt]s', '**/*.[jt]sx', '!**/node_modules/**') }}
          restore-keys: |
            nextjs-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }}-

      - name: Build (next export -> out/)
        run: pnpm build

      - name: Disable Jekyll on Pages
        run: touch out/.nojekyll

      - name: Report build size
        run: |
          echo "Total files: $(find out -type f | wc -l)"
          echo "Total size:  $(du -sh out | cut -f1)"

      - name: Upload Pages artifact
        uses: actions/upload-pages-artifact@v5
        with:
          path: ./out

  deploy:
    name: Deploy to Pages
    needs: build
    runs-on: ubuntu-latest
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    steps:
      - id: deployment
        uses: actions/deploy-pages@v5
