---
name: "🤠 Wrangler"

on:
  workflow_dispatch: {}
  push:
    branches: [main]
    paths:
      - "lib/**"
      - "workers/**"

jobs:
  deploy-worker:
    strategy:
      fail-fast: false
      matrix:
        worker: [get, init, raw, r2-store, cache]
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - if: startsWith(matrix.worker, 'get')
        name: "🤠 Deploy > get"
        uses: cloudflare/wrangler-action@2.0.0
        with:
          apiToken: ${{ secrets.CF_API_TOKEN }}
          accountId: ${{ secrets.CF_ACCOUNT_ID }}
          workingDirectory: "workers/get"
          command: "publish"
      - if: startsWith(matrix.worker, 'init')
        name: "🤠 Deploy > init"
        uses: cloudflare/wrangler-action@2.0.0
        with:
          apiToken: ${{ secrets.CF_API_TOKEN }}
          accountId: ${{ secrets.CF_ACCOUNT_ID }}
          workingDirectory: "workers/init"
          command: "publish"
      - if: startsWith(matrix.worker, 'raw')
        name: "🤠 Deploy > raw"
        uses: cloudflare/wrangler-action@2.0.0
        with:
          apiToken: ${{ secrets.CF_API_TOKEN }}
          accountId: ${{ secrets.CF_ACCOUNT_ID }}
          workingDirectory: "workers/raw"
          command: "publish"
      - if: startsWith(matrix.worker, 'r2-store')
        name: "🤠 Deploy > r2-store"
        uses: cloudflare/wrangler-action@2.0.0
        with:
          apiToken: ${{ secrets.CF_API_TOKEN }}
          accountId: ${{ secrets.CF_ACCOUNT_ID }}
          workingDirectory: "workers/r2-store"
          command: "publish"
      - if: startsWith(matrix.worker, 'cache')
        name: "🤠 Deploy > cache"
        uses: cloudflare/wrangler-action@2.0.0
        with:
          apiToken: ${{ secrets.CF_API_TOKEN }}
          accountId: ${{ secrets.CF_ACCOUNT_ID }}
          workingDirectory: "workers/cache"
          command: "publish"
