name: Deploy to Cloudflare Workers

on:
  push:
    branches:
      - master

jobs:
  deploy:
    runs-on: ubuntu-latest
    name: Deploy
    
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Setup Bun
        uses: oven-sh/setup-bun@v2
        with:
          bun-version: latest

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

      - name: Build
        run: bun run build
        env:
          NUXT_DISCORD_ID: ${{ vars.NUXT_DISCORD_ID }}
          NUXT_DISCORD_TOKEN: ${{ vars.NUXT_DISCORD_TOKEN }}
          NUXT_DISCORD_USER_ID: ${{ vars.NUXT_DISCORD_USER_ID }}

          NUXT_WAKATIME_CODING: ${{ vars.NUXT_WAKATIME_CODING }}
          NUXT_WAKATIME_EDITORS: ${{ vars.NUXT_WAKATIME_EDITORS }}
          NUXT_WAKATIME_LANGUAGES: ${{ vars.NUXT_WAKATIME_LANGUAGES }}
          NUXT_WAKATIME_OS: ${{ vars.NUXT_WAKATIME_OS }}
          NUXT_WAKATIME_USER_ID: ${{ vars.NUXT_WAKATIME_USER_ID }}
          
          NUXT_STATUS_PAGE: ${{ vars.NUXT_STATUS_PAGE }}
          STUDIO_GITHUB_CLIENT_ID: ${{ vars.STUDIO_GITHUB_CLIENT_ID }}
          STUDIO_GITHUB_CLIENT_SECRET: ${{ vars.STUDIO_GITHUB_CLIENT_SECRET }}   

      - name: Publish to Cloudflare Workers
        uses: cloudflare/wrangler-action@v3
        with:
          apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
          accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
          command: deploy
        env:
          CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
          CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}