# Build Snap companion site (pathPrefix /snap). Uploads artifact for deploy to your host.
# Optional: set secret GATSBY_SNAP_API_BASE_URL for production API in build.
name: Build Snap Site

on:
  push:
    branches: [main]
    paths:
      - 'packages/site/**'
      - 'packages/snap/**'
      - '.github/workflows/deploy-snap-site.yml'
  workflow_dispatch:

env:
  GATSBY_PATH_PREFIX: /snap

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

      - name: Enable pnpm
        run: corepack enable && corepack prepare pnpm@9.15.0 --activate

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

      - name: Build Snap site (pathPrefix /snap)
        run: pnpm --filter site run build
        env:
          GATSBY_PATH_PREFIX: /snap
          GATSBY_SNAP_API_BASE_URL: ${{ secrets.GATSBY_SNAP_API_BASE_URL }}

      - name: Upload site artifact
        uses: actions/upload-artifact@v4
        with:
          name: snap-site-${{ github.sha }}
          path: packages/site/public/
          retention-days: 7
