name: Deploy CULTSHOT to Cloudflare Pages

on:
  push:
    branches:
      - main
    paths:
      - 'src/sites/cultshot/**'
      - 'src/shared/**'
      - 'src/assets/src/cultshot-*'
      - 'src/assets/out/cultshot-*'
      - 'src/assets/lib/**'
      - 'src/assets/src/icons/**'
      - 'functions/**'
      - 'astro.config.cultshot.mjs'
      - 'wrangler.cultshot.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 CULTSHOT site
        run: npm run build:cultshot

      - 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/cultshot --project-name=cultshot-web
          gitHubToken: ${{ secrets.GITHUB_TOKEN }}
