forked from huilang-me/CF-Server-Monitor
-
Notifications
You must be signed in to change notification settings - Fork 0
99 lines (82 loc) · 3.08 KB
/
Copy pathdeploy.yml
File metadata and controls
99 lines (82 loc) · 3.08 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
name: Deploy to Cloudflare Workers
on:
push:
branches:
- main
paths-ignore:
- '**.md'
- '.gitignore'
- 'LICENSE'
workflow_dispatch:
jobs:
deploy:
runs-on: ubuntu-latest
name: Deploy
steps:
- name: 📥 Checkout code
uses: actions/checkout@v4
- name: 🔧 Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
- name: 📦 Install dependencies
run: npm install
- name: 🏗️ Build frontend assets
run: npm run build:frontend
- name: 📝 Create wrangler.toml
run: |
cat > wrangler.toml << 'WEOF'
name = "server-monitor-pro"
main = "src/index.js"
compatibility_date = "2024-12-01"
compatibility_flags = ["nodejs_compat"]
# 定时任务配置(UTC)
# - 每天UTC 23点50分:执行数据清理
# - 每分钟:执行离线节点检测
[triggers]
crons = ["50 23 * * *", "*/1 * * * *"]
[assets]
directory = "./dist"
binding = "ASSETS"
[[d1_databases]]
binding = "DB"
database_name = "server-monitor-db"
database_id = "D1_PLACEHOLDER"
# Durable Objects:实时指标广播中心
[[durable_objects.bindings]]
name = "METRICS_BROADCASTER"
class_name = "MetricsBroadcaster"
[[migrations]]
tag = "v1"
new_sqlite_classes = ["MetricsBroadcaster"]
[vars]
API_SECRET = "SECRET_PLACEHOLDER"
API_USER_NAME = "USER_NAME_PLACEHOLDER"
WEOF
# 替换占位符
sed -i "s|D1_PLACEHOLDER|${{ secrets.D1_DATABASE_ID }}|g" wrangler.toml
sed -i "s|SECRET_PLACEHOLDER|${{ secrets.API_SECRET }}|g" wrangler.toml
sed -i "s|USER_NAME_PLACEHOLDER|${{ secrets.API_USER_NAME }}|g" wrangler.toml
echo "✅ wrangler.toml 已生成"
# wrangler v4 的 `deploy` 会自动根据 wrangler.toml 中的 [[durable_objects.bindings]]
# 声明创建 DO namespace(幂等:已存在则跳过),无需单独命令。
# 前提:MetricsBroadcaster 类必须从 index.js 导出(已通过 src/index.js 实现)。
- name: 🚀 Deploy to Cloudflare Workers
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CF_API_TOKEN }}
accountId: ${{ secrets.CF_ACCOUNT_ID }}
wranglerVersion: '4'
command: deploy
- name: ✅ Deployment Success
if: success()
run: |
echo "============================================"
echo " 🎉 部署成功!"
echo "============================================"
- name: ❌ Deployment Failed
if: failure()
run: |
echo "============================================"
echo " 💥 部署失败!请检查 Actions 日志"
echo "============================================"