name: Deploy static js to Cloudflare

on:
  push:
    branches:
      - main
      - production

jobs:
  deploy-main:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v3

      - name: Set up Node.js
        uses: actions/setup-node@v3
        with:
          node-version: 20.18.0
          cache: 'npm'

      - run: |
          export NODE_ENV=production
          npm ci --legacy-peer-deps
        name: Install production dependencies

      - run: npm run build
        name: Build project

      - name: Install Yarn
        run: npm install --global yarn

      - name: Publish slateboxjs to Cloudflare Worker site
        run: yarn wrangler2 publish --env production
        env:
          CF_API_TOKEN: ${{ secrets.CF_API_TOKEN }}
          CF_ZONE_ID: ${{ secrets.CF_ZONE_ID }}
          CF_ACCOUNT_ID: ${{ secrets.CF_ACCOUNT_ID }}
