Skip to content

Commit

Permalink
Update main.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
rogerwangzy authored Feb 21, 2025
1 parent c5bd79c commit 20239f8
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: Deploy to Cloudflare Workers
on:
push:
branches: [ main ]
workflow_dispatch:

jobs:
deploy:
Expand All @@ -16,23 +17,23 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm' # 加缓存,加速安装
cache: 'npm'

- name: Install latest Wrangler
run: |
npm install -g @cloudflare/wrangler@latest
npm link @cloudflare/wrangler # 强制链接,确保可用
echo "NODE_PATH=$(npm root -g)" >> $GITHUB_ENV # 更新PATH
echo "$(npm bin -g)" >> $GITHUB_PATH # 加全局bin到PATH
npm uninstall -g @cloudflare/wrangler # 卸载老版
npm install -g wrangler # 装最新版(现在直接叫wrangler)
npm link wrangler # 确保链接
echo "$(npm bin -g)" >> $GITHUB_PATH # 更新PATH
- name: Verify Wrangler installation
run: wrangler --version # 检查版本
run: wrangler --version # 确认版本(应该看到3.x.x)

- name: Replace KV_NAME in wrangler.toml
run: sed -i "s/KV_NAME/${{ secrets.KV_NAME }}/g" wrangler.toml

- name: Deploy to Cloudflare
run: wrangler deploy --api-token ${{ secrets.CF_API_TOKEN }} --account-id ${{ secrets.CF_ACCOUNT_ID }}
run: wrangler deploy # 新版用法,不用--api-token和--account-id,直接用Secrets配置
env:
CF_API_TOKEN: ${{ secrets.CF_API_TOKEN }}
CF_ACCOUNT_ID: ${{ secrets.CF_ACCOUNT_ID }}
CLOUDFLARE_API_TOKEN: ${{ secrets.CF_API_TOKEN }} # 新版用这个环境变量
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CF_ACCOUNT_ID }} # 新版用这个环境变量

0 comments on commit 20239f8

Please sign in to comment.