Repository navigation
205 lines (180 loc) · 7.42 KB
/
Copy pathdeploy-cloudflare.yml
File metadata and controls
205 lines (180 loc) · 7.42 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
name: Deploy to Cloudflare Workers
on:
push:
branches: [main]
pull_request:
types: [opened, synchronize, reopened, closed]
workflow_dispatch:
permissions:
contents: read
pull-requests: write
concurrency:
group: deploy-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
deploy:
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
- run: corepack enable
- run: pnpm install
- name: Generate docs search index
run: pnpm ingest
env:
ANUMA_API_KEY: ${{ secrets.ANUMA_API_KEY }}
- name: Upload docs index to R2
run: |
pnpm exec wrangler r2 object put docs-index/docs-index.json --file public/docs-index.json --remote
pnpm exec wrangler r2 object put docs-index/docs-index.bin --file public/docs-index.bin --remote
rm public/docs-index.json public/docs-index.bin
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN_PUBLIC_REPO }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
- run: pnpm build:cloudflare
env:
NODE_OPTIONS: '--max-old-space-size=4096'
- run: pnpm exec wrangler deploy
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN_PUBLIC_REPO }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
- name: Set worker secrets
run: echo "$ANUMA_API_KEY" | pnpm exec wrangler secret put ANUMA_API_KEY
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN_PUBLIC_REPO }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
ANUMA_API_KEY: ${{ secrets.ANUMA_API_KEY }}
deploy-preview:
if: github.event_name == 'pull_request' && github.event.action != 'closed'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Post deploying comment
uses: actions/github-script@v7
with:
script: |
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const existing = comments.find(c => c.body.includes('Cloudflare Workers Preview'));
const body = '⏳ **Cloudflare Workers Preview** — Deploying...';
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body,
});
}
- uses: actions/setup-node@v4
with:
node-version: 22
- run: corepack enable
- run: pnpm install
- name: Generate docs search index
run: pnpm ingest
env:
ANUMA_API_KEY: ${{ secrets.ANUMA_API_KEY }}
- name: Upload docs index to R2
run: |
pnpm exec wrangler r2 object put docs-index/docs-index.json --file public/docs-index.json --remote
pnpm exec wrangler r2 object put docs-index/docs-index.bin --file public/docs-index.bin --remote
rm public/docs-index.json public/docs-index.bin
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN_PUBLIC_REPO }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
- run: pnpm build:cloudflare
env:
NODE_OPTIONS: '--max-old-space-size=4096'
- name: Deploy preview worker
id: deploy
run: |
WORKER_NAME="docs-pr-${{ github.event.pull_request.number }}"
pnpm exec wrangler deploy --name "$WORKER_NAME"
echo "$ANUMA_API_KEY" | pnpm exec wrangler secret put ANUMA_API_KEY --name "$WORKER_NAME"
echo "url=https://${WORKER_NAME}.zetachain.workers.dev" >> "$GITHUB_OUTPUT"
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN_PUBLIC_REPO }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
ANUMA_API_KEY: ${{ secrets.ANUMA_API_KEY }}
- name: Update PR comment with URL
uses: actions/github-script@v7
with:
script: |
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const existing = comments.find(c => c.body.includes('Cloudflare Workers Preview'));
const body = `✅ **Cloudflare Workers Preview** — Deployed!\n\n${{ steps.deploy.outputs.url }}`;
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body,
});
}
- name: Update PR comment on failure
if: failure()
uses: actions/github-script@v7
with:
script: |
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const existing = comments.find(c => c.body.includes('Cloudflare Workers Preview'));
const body = `❌ **Cloudflare Workers Preview** — Deploy failed.\n\n[View logs](${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId})`;
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body,
});
}
cleanup-preview:
if: github.event_name == 'pull_request' && github.event.action == 'closed'
runs-on: ubuntu-latest
steps:
- name: Delete preview worker
run: |
WORKER_NAME="docs-pr-${{ github.event.pull_request.number }}"
npx wrangler delete --name "$WORKER_NAME" --force
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN_PUBLIC_REPO }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
- name: Update PR comment
uses: actions/github-script@v7
with:
script: |
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const existing = comments.find(c => c.body.includes('Cloudflare Workers Preview'));
if (existing) {
const action = context.payload.pull_request.merged ? 'merged' : 'closed';
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body: `🧹 **Cloudflare Workers Preview** — Cleaned up (PR ${action}).`,
});
}