name: Deploy to Cloudflare Workers

on:
  push:
    branches:
      - main  # 当推送到 main 分支时触发

jobs:
  deploy:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '20'  # 使用 Node.js 20，你可以根据需要调整版本

      - name: Setup pnpm
        uses: pnpm/action-setup@v4
        with:
          version: 9.14.4  # 使用 package.json 中指定的 pnpm 版本

      - name: Install dependencies
        run: pnpm install

      - name: Build project
        run: npx astro build

      - name: Deploy to Cloudflare Workers
        run: npx wrangler deploy
        env:
          CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
