name: Deploy CULTSCALE to Cloudflare Pages

on:
  push:
    branches:
      - main
    paths:
      - 'src/sites/cultscale/**'
      - 'src/shared/**'
      - 'src/assets/**'
      - 'functions/**'
      - 'astro.config.cultscale.mjs'
      - 'wrangler.cultscale.toml'
  workflow_dispatch:

jobs:
  deploy:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      deployments: write

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          lfs: true

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

      - name: Install dependencies
        run: npm ci

      - name: Build CULTSCALE site
        run: npm run build:cultscale

      - name: Deploy to Cloudflare Pages
        uses: cloudflare/wrangler-action@v3
        with:
          apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
          accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
          command: pages deploy dist/cultscale --project-name=cultscale-web
          gitHubToken: ${{ secrets.GITHUB_TOKEN }}
