布灵图床前端网页 #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: 部署布灵图床前端到Cloudflare Pages | |
on: | |
push: | |
branches: [main] | |
pull_request: | |
branches: [main] | |
workflow_dispatch: | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
deployments: write | |
steps: | |
- uses: actions/checkout@v4 | |
- name: 1.Setup Node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20' | |
- name: 2.Install Dependencies | |
run: | | |
echo "开始安装依赖..." | |
npm install &>/dev/null || { | |
echo "❌ 依赖安装失败" | |
exit 1 | |
} | |
npm install -g wrangler &>/dev/null || { | |
echo "❌ wrangler 安装失败" | |
exit 1 | |
} | |
which wrangler # 显示 wrangler 的安装位置 | |
wrangler --version # 显示 wrangler 版本 | |
echo "✅ 依赖安装成功" | |
- name: 3.Create Cloudflare Pages Project | |
env: | |
CLOUDFLARE_API_TOKEN: ${{ secrets.CF_API_TOKEN }} | |
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CF_ACCOUNT_ID }} | |
run: | | |
echo "检查并创建 Pages 项目..." | |
curl -X POST "https://api.cloudflare.com/client/v4/accounts/${{ secrets.CF_ACCOUNT_ID }}/pages/projects" \ | |
-H "Authorization: Bearer ${{ secrets.CF_API_TOKEN }}" \ | |
-H "Content-Type: application/json" \ | |
--data '{ | |
"name": "buling-imgbed-frontend", | |
"production_branch": "main" | |
}' > /dev/null 2>&1 || true | |
echo "✅ Pages 项目检查完成" | |
- name: 4.Deploy to Cloudflare Pages | |
env: | |
CLOUDFLARE_API_TOKEN: ${{ secrets.CF_API_TOKEN }} | |
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CF_ACCOUNT_ID }} | |
NUXT_PUBLIC_API_BASE: ${{ secrets.NUXT_PUBLIC_API_BASE }} | |
run: | | |
echo "开始部署到 Cloudflare Pages..." | |
npm run pages:deploy &>/dev/null || { | |
echo "❌ 部署失败" | |
exit 1 | |
} | |
echo "✅ 部署成功" |