-
Notifications
You must be signed in to change notification settings - Fork 0
105 lines (92 loc) · 3.59 KB
/
deploy-worker.yml
File metadata and controls
105 lines (92 loc) · 3.59 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
name: Deploy Cloudflare Worker
on:
push:
branches: [main, master]
paths:
- 'worker/**'
- '.github/workflows/deploy-worker.yml'
pull_request:
branches: [main, master]
paths:
- 'worker/**'
workflow_dispatch:
inputs:
environment:
description: 'Deployment environment'
required: true
default: 'production'
type: choice
options:
- production
- staging
permissions:
contents: read
env:
NODE_VERSION: '20'
jobs:
deploy-worker:
name: Deploy Worker to Cloudflare
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: latest
- name: Cache Bun global packages
uses: actions/cache@v4
with:
path: ~/.bun/install/global
key: ${{ runner.os }}-bun-global-wrangler
restore-keys: |
${{ runner.os }}-bun-global-
- name: Install Wrangler CLI
run: bun install -g wrangler
- name: Verify Worker configuration
run: |
cd worker
if [ -f "wrangler.toml" ]; then
echo "Worker configuration found"
wrangler whoami
echo "✅ Worker setup validation passed"
else
echo "❌ Worker configuration not found"
exit 1
fi
- name: Deploy Worker (Production)
if: (github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')) || (github.event_name == 'workflow_dispatch' && github.event.inputs.environment == 'production')
run: |
cd worker
wrangler deploy --env production
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
- name: Deploy Worker (Staging)
if: github.event_name == 'pull_request' || (github.event_name == 'workflow_dispatch' && github.event.inputs.environment == 'staging')
run: |
cd worker
wrangler deploy --env staging
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
- name: Worker Deployment Summary
run: |
ENVIRONMENT="production"
if [ "${{ github.event_name }}" = "pull_request" ] || [ "${{ github.event.inputs.environment }}" = "staging" ]; then
ENVIRONMENT="staging"
fi
echo "## 🎉 Worker Deployment Successful!" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Your Cloudflare Worker has been deployed successfully." >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Deployment Information" >> $GITHUB_STEP_SUMMARY
echo "- **Environment**: $ENVIRONMENT" >> $GITHUB_STEP_SUMMARY
echo "- **Commit**: ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY
echo "- **Deploy Time**: $(date -u)" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### API Endpoints" >> $GITHUB_STEP_SUMMARY
echo "- Health Check: \`/api/health\`" >> $GITHUB_STEP_SUMMARY
echo "- Search Suggestions: \`/api/search/suggestions?q=query\`" >> $GITHUB_STEP_SUMMARY
echo "- Analytics: \`/api/analytics/event\` (POST)" >> $GITHUB_STEP_SUMMARY
echo "- Feedback: \`/api/feedback\` (POST)" >> $GITHUB_STEP_SUMMARY