-
Notifications
You must be signed in to change notification settings - Fork 0
143 lines (122 loc) · 5.23 KB
/
Copy pathdeploy.yml
File metadata and controls
143 lines (122 loc) · 5.23 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
name: Deploy Cloudflare
on:
pull_request:
branches:
- main
- master
push:
branches:
- main
- master
workflow_dispatch:
inputs:
target:
description: Cloudflare deployment target
required: true
default: preview
type: choice
options:
- preview
- production
concurrency:
group: tgbot-cloudflare-${{ github.ref }}-${{ github.event_name }}
cancel-in-progress: true
jobs:
preflight:
runs-on: ubuntu-latest
env:
DEPLOY_TARGET: ${{ github.event_name == 'push' && 'production' || github.event_name == 'workflow_dispatch' && github.event.inputs.target || 'preview' }}
steps:
- name: Checkout
uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: 24
cache: npm
- name: Install dependencies
run: npm ci
- name: Run check, build, and performance budgets
run: npm run deploy:preflight -- --target="${DEPLOY_TARGET}"
deploy_preview:
name: Deploy preview
needs: preflight
if: >-
(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) ||
(github.event_name == 'workflow_dispatch' && github.event.inputs.target == 'preview')
runs-on: ubuntu-latest
timeout-minutes: 30
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
BOT_TOKEN: ${{ secrets.BOT_TOKEN }}
ADMIN_TOKEN: ${{ secrets.ADMIN_TOKEN }}
TELEGRAM_WEBHOOK_SECRET: ${{ secrets.TELEGRAM_WEBHOOK_SECRET }}
TELEGRAPH_ACCESS_TOKEN: ${{ secrets.TELEGRAPH_ACCESS_TOKEN }}
steps:
- name: Checkout
uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: 24
cache: npm
- name: Install dependencies
run: npm ci
- name: Validate preview deployment secrets
run: |
node -e "const missing=['CLOUDFLARE_API_TOKEN','CLOUDFLARE_ACCOUNT_ID','BOT_TOKEN','ADMIN_TOKEN'].filter((name)=>!process.env[name]); if (missing.length) { console.error('Missing GitHub secrets: ' + missing.join(', ')); process.exit(1); }"
- name: Build WebUI assets
run: npm run pages:build
- name: Deploy preview Worker and Pages
run: npm run deploy:preview -- --skip-preflight
- name: Sync preview Worker secrets
run: |
node -e "const fs=require('fs'); const payload=Object.fromEntries(Object.entries({ BOT_TOKEN: process.env.BOT_TOKEN, ADMIN_TOKEN: process.env.ADMIN_TOKEN, TELEGRAM_WEBHOOK_SECRET: process.env.TELEGRAM_WEBHOOK_SECRET || undefined, TELEGRAPH_ACCESS_TOKEN: process.env.TELEGRAPH_ACCESS_TOKEN || undefined }).filter(([, value]) => value)); fs.writeFileSync('.cloudflare-secrets.json', JSON.stringify(payload));"
npx wrangler secret bulk .cloudflare-secrets.json --config packages/bot-worker/wrangler.toml --env preview
rm .cloudflare-secrets.json
deploy_production:
name: Deploy production
needs: preflight
if: >-
github.event_name == 'push' ||
(github.event_name == 'workflow_dispatch' && github.event.inputs.target == 'production')
runs-on: ubuntu-latest
timeout-minutes: 30
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
BOT_TOKEN: ${{ secrets.BOT_TOKEN }}
ADMIN_TOKEN: ${{ secrets.ADMIN_TOKEN }}
TELEGRAM_WEBHOOK_SECRET: ${{ secrets.TELEGRAM_WEBHOOK_SECRET }}
TELEGRAPH_ACCESS_TOKEN: ${{ secrets.TELEGRAPH_ACCESS_TOKEN }}
steps:
- name: Checkout
uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: 24
cache: npm
- name: Install dependencies
run: npm ci
- name: Validate production deployment secrets
run: |
node -e "const missing=['CLOUDFLARE_API_TOKEN','CLOUDFLARE_ACCOUNT_ID','BOT_TOKEN','ADMIN_TOKEN'].filter((name)=>!process.env[name]); if (missing.length) { console.error('Missing GitHub secrets: ' + missing.join(', ')); process.exit(1); }"
- name: Build WebUI assets
run: npm run pages:build
- name: Deploy production Worker and Pages
run: npm run deploy:production -- --skip-preflight
- name: Sync production Worker secrets
run: |
node -e "const fs=require('fs'); const payload=Object.fromEntries(Object.entries({ BOT_TOKEN: process.env.BOT_TOKEN, ADMIN_TOKEN: process.env.ADMIN_TOKEN, TELEGRAM_WEBHOOK_SECRET: process.env.TELEGRAM_WEBHOOK_SECRET || undefined, TELEGRAPH_ACCESS_TOKEN: process.env.TELEGRAPH_ACCESS_TOKEN || undefined }).filter(([, value]) => value)); fs.writeFileSync('.cloudflare-secrets.json', JSON.stringify(payload));"
npx wrangler secret bulk .cloudflare-secrets.json --config packages/bot-worker/wrangler.toml --env production
rm .cloudflare-secrets.json
- name: Register Telegram webhook
run: npm run webhook:set -- --direct-telegram