1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| name: Deploy to Cloudflare Workers
on: push: branches: - master - pre - test
jobs: build-and-deploy: runs-on: ubuntu-latest
steps: - name: Checkout source repository uses: actions/checkout@v3
- name: Set up Node.js uses: actions/setup-node@v3 with: node-version: '18.19.0'
- name: Install dependencies run: npm install --only=prod
- name: Set up Cloudflare token run: | echo "CLOUDFLARE_API_TOKEN=${{ secrets.CLOUDFLARE_API_TOKEN }}" >> $GITHUB_ENV
- name: Deploy to Cloudflare Workers run: | # 根据分支选择部署环境 if [ "${{ github.ref }}" == "refs/heads/master" ]; then DEPLOY_ENV=prod elif [ "${{ github.ref }}" == "refs/heads/pre" ]; then DEPLOY_ENV=pre elif [ "${{ github.ref }}" == "refs/heads/test" ]; then DEPLOY_ENV=test else echo "未知分支,跳过部署!" exit 1 fi
npm run cf:deploy:$DEPLOY_ENV
|