-
Notifications
You must be signed in to change notification settings - Fork 0
443 lines (379 loc) · 17 KB
/
release.yml
File metadata and controls
443 lines (379 loc) · 17 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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
name: Build and Release Widget
on:
push:
tags:
- 'v*' # Trigger on version tags (e.g., v1.4.0)
permissions:
contents: write # Required to create GitHub releases
id-token: write # Required for Cloudflare authentication (if using OIDC)
jobs:
build-and-release:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: npm install
# Note: Since this project has no dependencies, npm install just creates/updates package-lock.json
- name: Install Wrangler CLI
run: npm install -g wrangler
- name: Verify Wrangler and Cloudflare credentials
run: |
echo "=== Verifying Wrangler Installation ==="
wrangler --version
echo "=== Verifying Cloudflare Credentials ==="
if [ -z "$CLOUDFLARE_API_TOKEN" ]; then
echo "❌ CLOUDFLARE_API_TOKEN is not set"
exit 1
fi
if [ -z "$CLOUDFLARE_ACCOUNT_ID" ]; then
echo "❌ CLOUDFLARE_ACCOUNT_ID is not set"
exit 1
fi
if [ -z "$CLOUDFLARE_R2_BUCKET_NAME" ]; then
echo "❌ CLOUDFLARE_R2_BUCKET_NAME is not set"
exit 1
fi
echo "✅ All required secrets are set"
echo "Account ID: $CLOUDFLARE_ACCOUNT_ID"
echo "Bucket: $CLOUDFLARE_R2_BUCKET_NAME"
# Note: Authentication will be tested during the actual upload
# If credentials are wrong, the upload step will fail with a clear error
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
CLOUDFLARE_R2_BUCKET_NAME: ${{ secrets.CLOUDFLARE_R2_BUCKET_NAME }}
- name: Extract version from tag
id: get_version
run: |
VERSION=${GITHUB_REF#refs/tags/v}
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Version extracted: $VERSION"
- name: Build widget
run: |
echo "Building widget from Git tag..."
npm run build:tag
echo "Build completed. Files in dist/:"
ls -lh dist/ || echo "dist/ directory not found"
- name: Verify build output
run: |
VERSION="${{ steps.get_version.outputs.version }}"
echo "=== Checking widget files ==="
for file in \
"dist/widget-${VERSION}.js" \
"dist/widget-${VERSION}.min.js" \
"dist/widget-${VERSION}.css" \
"dist/widget-${VERSION}.min.css" \
"dist/widget.js" \
"dist/widget.min.js" \
"dist/widget.css" \
"dist/widget.min.css"
do
if [ ! -f "$file" ]; then
echo "❌ Error: $file not found"
exit 1
fi
echo "✓ $file"
done
echo ""
echo "=== Checking ezform files ==="
for file in \
"dist/ezform-${VERSION}.js" \
"dist/ezform-${VERSION}.min.js" \
"dist/ezform.js" \
"dist/ezform.min.js"
do
if [ ! -f "$file" ]; then
echo "❌ Error: $file not found"
exit 1
fi
echo "✓ $file"
done
echo ""
echo "✅ Build verification passed"
echo ""
echo "=== File sizes ==="
ls -lh dist/
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
files: |
dist/widget-${{ steps.get_version.outputs.version }}.js
dist/widget-${{ steps.get_version.outputs.version }}.min.js
dist/widget-${{ steps.get_version.outputs.version }}.css
dist/widget-${{ steps.get_version.outputs.version }}.min.css
dist/widget.js
dist/widget.min.js
dist/widget.css
dist/widget.min.css
dist/ezform-${{ steps.get_version.outputs.version }}.js
dist/ezform-${{ steps.get_version.outputs.version }}.min.js
dist/ezform.js
dist/ezform.min.js
draft: false
prerelease: false
generate_release_notes: true
token: ${{ secrets.GITHUB_TOKEN }}
- name: Upload to Cloudflare R2 (Versioned Files)
run: |
set -e # Exit on error
VERSION="${{ steps.get_version.outputs.version }}"
BUCKET="${{ secrets.CLOUDFLARE_R2_BUCKET_NAME }}"
echo "=== Upload Configuration ==="
echo "Version: $VERSION"
echo "Bucket: $BUCKET"
echo "Account ID: $CLOUDFLARE_ACCOUNT_ID"
echo "API Token: ${CLOUDFLARE_API_TOKEN:0:10}..." # Show first 10 chars only
if [ -z "$BUCKET" ]; then
echo "❌ Error: CLOUDFLARE_R2_BUCKET_NAME secret is not set"
exit 1
fi
if [ -z "$CLOUDFLARE_API_TOKEN" ]; then
echo "❌ Error: CLOUDFLARE_API_TOKEN secret is not set"
exit 1
fi
if [ -z "$CLOUDFLARE_ACCOUNT_ID" ]; then
echo "❌ Error: CLOUDFLARE_ACCOUNT_ID secret is not set"
exit 1
fi
# Verify files exist before uploading
if [ ! -f "dist/widget-${VERSION}.js" ]; then
echo "❌ Error: dist/widget-${VERSION}.js not found"
exit 1
fi
if [ ! -f "dist/widget-${VERSION}.css" ]; then
echo "❌ Error: dist/widget-${VERSION}.css not found"
exit 1
fi
if [ ! -f "dist/ezform-${VERSION}.js" ]; then
echo "❌ Error: dist/ezform-${VERSION}.js not found"
exit 1
fi
if [ ! -f "dist/widget-${VERSION}.min.js" ]; then
echo "❌ Error: dist/widget-${VERSION}.min.js not found"
exit 1
fi
if [ ! -f "dist/ezform-${VERSION}.min.js" ]; then
echo "❌ Error: dist/ezform-${VERSION}.min.js not found"
exit 1
fi
echo "=== Uploading versioned files ==="
# Upload versioned files with cache headers (--remote flag required!)
echo "Uploading widget-${VERSION}.js..."
wrangler r2 object put ${BUCKET}/widget-${VERSION}.js \
--file=dist/widget-${VERSION}.js \
--content-type="application/javascript" \
--cache-control="public, max-age=31536000, immutable" \
--remote || {
echo "❌ Failed to upload widget-${VERSION}.js"
exit 1
}
echo "Uploading widget-${VERSION}.css..."
wrangler r2 object put ${BUCKET}/widget-${VERSION}.css \
--file=dist/widget-${VERSION}.css \
--content-type="text/css" \
--cache-control="public, max-age=31536000, immutable" \
--remote || {
echo "❌ Failed to upload widget-${VERSION}.css"
exit 1
}
echo "Uploading ezform-${VERSION}.js..."
wrangler r2 object put ${BUCKET}/ezform-${VERSION}.js \
--file=dist/ezform-${VERSION}.js \
--content-type="application/javascript" \
--cache-control="public, max-age=31536000, immutable" \
--remote || {
echo "❌ Failed to upload ezform-${VERSION}.js"
exit 1
}
# Upload minified versioned files
echo "Uploading widget-${VERSION}.min.js..."
wrangler r2 object put ${BUCKET}/widget-${VERSION}.min.js \
--file=dist/widget-${VERSION}.min.js \
--content-type="application/javascript" \
--cache-control="public, max-age=31536000, immutable" \
--remote || {
echo "❌ Failed to upload widget-${VERSION}.min.js"
exit 1
}
echo "Uploading widget-${VERSION}.min.css..."
wrangler r2 object put ${BUCKET}/widget-${VERSION}.min.css \
--file=dist/widget-${VERSION}.min.css \
--content-type="text/css" \
--cache-control="public, max-age=31536000, immutable" \
--remote || {
echo "❌ Failed to upload widget-${VERSION}.min.css"
exit 1
}
echo "Uploading ezform-${VERSION}.min.js..."
wrangler r2 object put ${BUCKET}/ezform-${VERSION}.min.js \
--file=dist/ezform-${VERSION}.min.js \
--content-type="application/javascript" \
--cache-control="public, max-age=31536000, immutable" \
--remote || {
echo "❌ Failed to upload ezform-${VERSION}.min.js"
exit 1
}
echo "✅ Uploaded versioned files for v${VERSION}"
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
- name: Upload to Cloudflare R2 (Latest Files)
run: |
set -e # Exit on error
BUCKET="${{ secrets.CLOUDFLARE_R2_BUCKET_NAME }}"
echo "=== Uploading latest files ==="
if [ -z "$BUCKET" ]; then
echo "❌ Error: CLOUDFLARE_R2_BUCKET_NAME secret is not set"
exit 1
fi
# Verify files exist before uploading
if [ ! -f "dist/widget.js" ]; then
echo "❌ Error: dist/widget.js not found"
exit 1
fi
if [ ! -f "dist/widget.css" ]; then
echo "❌ Error: dist/widget.css not found"
exit 1
fi
if [ ! -f "dist/ezform.js" ]; then
echo "❌ Error: dist/ezform.js not found"
exit 1
fi
if [ ! -f "dist/widget.min.js" ]; then
echo "❌ Error: dist/widget.min.js not found"
exit 1
fi
if [ ! -f "dist/ezform.min.js" ]; then
echo "❌ Error: dist/ezform.min.js not found"
exit 1
fi
# Upload latest files with shorter cache (--remote flag required!)
echo "Uploading widget.js..."
wrangler r2 object put ${BUCKET}/widget.js \
--file=dist/widget.js \
--content-type="application/javascript" \
--cache-control="public, max-age=3600" \
--remote || {
echo "❌ Failed to upload widget.js"
exit 1
}
echo "Uploading widget.css..."
wrangler r2 object put ${BUCKET}/widget.css \
--file=dist/widget.css \
--content-type="text/css" \
--cache-control="public, max-age=3600" \
--remote || {
echo "❌ Failed to upload widget.css"
exit 1
}
echo "Uploading ezform.js..."
wrangler r2 object put ${BUCKET}/ezform.js \
--file=dist/ezform.js \
--content-type="application/javascript" \
--cache-control="public, max-age=3600" \
--remote || {
echo "❌ Failed to upload ezform.js"
exit 1
}
# Upload minified latest files
echo "Uploading widget.min.js..."
wrangler r2 object put ${BUCKET}/widget.min.js \
--file=dist/widget.min.js \
--content-type="application/javascript" \
--cache-control="public, max-age=3600" \
--remote || {
echo "❌ Failed to upload widget.min.js"
exit 1
}
echo "Uploading widget.min.css..."
wrangler r2 object put ${BUCKET}/widget.min.css \
--file=dist/widget.min.css \
--content-type="text/css" \
--cache-control="public, max-age=3600" \
--remote || {
echo "❌ Failed to upload widget.min.css"
exit 1
}
echo "Uploading ezform.min.js..."
wrangler r2 object put ${BUCKET}/ezform.min.js \
--file=dist/ezform.min.js \
--content-type="application/javascript" \
--cache-control="public, max-age=3600" \
--remote || {
echo "❌ Failed to upload ezform.min.js"
exit 1
}
echo "✅ Uploaded latest files"
# Note: Verification skipped - upload success is confirmed by "Upload complete" message
# Files may take a moment to propagate, but upload was successful
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
- name: Purge Cloudflare Cache
run: |
set -e
VERSION="${{ steps.get_version.outputs.version }}"
ZONE_ID="${CLOUDFLARE_ZONE_ID}"
CUSTOM_DOMAIN="${CLOUDFLARE_CUSTOM_DOMAIN:-cdn.ezcontactform.com}"
# Skip if ZONE_ID is not set
if [ -z "$ZONE_ID" ]; then
echo "⚠️ CLOUDFLARE_ZONE_ID not set, skipping cache purge"
echo "To enable cache purging, add CLOUDFLARE_ZONE_ID to your repository secrets"
exit 0
fi
echo "=== Purging Cloudflare Cache ==="
echo "Zone ID: ${ZONE_ID:0:10}..."
echo "Custom Domain: ${CUSTOM_DOMAIN}"
# Build the list of files to purge as JSON
FILES_TO_PURGE='{"files":["https://'"${CUSTOM_DOMAIN}"'/widget-'"${VERSION}"'.js","https://'"${CUSTOM_DOMAIN}"'/widget-'"${VERSION}"'.min.js","https://'"${CUSTOM_DOMAIN}"'/widget-'"${VERSION}"'.css","https://'"${CUSTOM_DOMAIN}"'/widget-'"${VERSION}"'.min.css","https://'"${CUSTOM_DOMAIN}"'/widget.js","https://'"${CUSTOM_DOMAIN}"'/widget.min.js","https://'"${CUSTOM_DOMAIN}"'/widget.css","https://'"${CUSTOM_DOMAIN}"'/widget.min.css","https://'"${CUSTOM_DOMAIN}"'/ezform-'"${VERSION}"'.js","https://'"${CUSTOM_DOMAIN}"'/ezform-'"${VERSION}"'.min.js","https://'"${CUSTOM_DOMAIN}"'/ezform.js","https://'"${CUSTOM_DOMAIN}"'/ezform.min.js"]}'
echo "Files to purge:"
echo "$FILES_TO_PURGE" | jq -r '.files[]' 2>/dev/null || echo "$FILES_TO_PURGE"
# Make the API call
RESPONSE=$(curl -s -X POST "https://api.cloudflare.com/client/v4/zones/${ZONE_ID}/purge_cache" \
-H "Authorization: Bearer ${CLOUDFLARE_API_TOKEN}" \
-H "Content-Type: application/json" \
--data "$FILES_TO_PURGE")
# Check response
SUCCESS=$(echo "$RESPONSE" | jq -r '.success' 2>/dev/null || echo "unknown")
if [ "$SUCCESS" = "true" ]; then
echo "✅ Cache purge successful"
else
echo "⚠️ Cache purge response:"
echo "$RESPONSE" | jq . 2>/dev/null || echo "$RESPONSE"
# Don't fail the build on cache purge issues
fi
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ZONE_ID: ${{ secrets.CLOUDFLARE_ZONE_ID }}
CLOUDFLARE_CUSTOM_DOMAIN: ${{ vars.CLOUDFLARE_CUSTOM_DOMAIN }}
- name: Build Summary
run: |
VERSION="${{ steps.get_version.outputs.version }}"
echo "## Build Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- **Version:** ${VERSION}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Widget Files" >> $GITHUB_STEP_SUMMARY
echo "| File | Size |" >> $GITHUB_STEP_SUMMARY
echo "|------|------|" >> $GITHUB_STEP_SUMMARY
echo "| widget-${VERSION}.js | $(du -h dist/widget-${VERSION}.js | cut -f1) |" >> $GITHUB_STEP_SUMMARY
echo "| widget-${VERSION}.min.js | $(du -h dist/widget-${VERSION}.min.js | cut -f1) |" >> $GITHUB_STEP_SUMMARY
echo "| widget-${VERSION}.css | $(du -h dist/widget-${VERSION}.css | cut -f1) |" >> $GITHUB_STEP_SUMMARY
echo "| widget-${VERSION}.min.css | $(du -h dist/widget-${VERSION}.min.css | cut -f1) |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### EZForm Files" >> $GITHUB_STEP_SUMMARY
echo "| File | Size |" >> $GITHUB_STEP_SUMMARY
echo "|------|------|" >> $GITHUB_STEP_SUMMARY
echo "| ezform-${VERSION}.js | $(du -h dist/ezform-${VERSION}.js | cut -f1) |" >> $GITHUB_STEP_SUMMARY
echo "| ezform-${VERSION}.min.js | $(du -h dist/ezform-${VERSION}.min.js | cut -f1) |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- **R2 Upload:** ✅ Completed" >> $GITHUB_STEP_SUMMARY
echo "- **Cache Purge:** ✅ Completed (if CLOUDFLARE_ZONE_ID is set)" >> $GITHUB_STEP_SUMMARY