-
Notifications
You must be signed in to change notification settings - Fork 3
144 lines (124 loc) · 3.95 KB
/
Copy pathcloudflare-worker.yml
File metadata and controls
144 lines (124 loc) · 3.95 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
name: Cloudflare Worker
on:
push:
branches: [main]
paths:
- 'cloudflare-worker/**'
- 'data/festivals.json'
- '.github/workflows/cloudflare-worker.yml'
pull_request:
paths:
- 'cloudflare-worker/**'
- 'data/festivals.json'
- '.github/workflows/cloudflare-worker.yml'
workflow_dispatch:
permissions:
contents: read
pull-requests: write
concurrency:
group: cloudflare-worker-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
jobs:
# Detect which files have changed
changes:
runs-on: ubuntu-latest
outputs:
worker: ${{ steps.filter.outputs.worker }}
festivals: ${{ steps.filter.outputs.festivals }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Check for file changes
uses: dorny/paths-filter@v3
id: filter
with:
filters: |
worker:
- 'cloudflare-worker/**'
festivals:
- 'data/festivals.json'
# Validate festivals.json against schema
validate-festivals:
needs: changes
runs-on: ubuntu-latest
if: |
github.event_name == 'workflow_dispatch' ||
needs.changes.outputs.festivals == 'true'
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: scripts/package-lock.json
- name: Install validation dependencies
working-directory: scripts
run: npm ci
- name: Validate festivals.json
run: node scripts/validate-festivals.js
# Validate Cloudflare Worker on PRs (dry-run)
validate-worker:
needs: changes
runs-on: ubuntu-latest
if: |
github.event_name == 'pull_request' &&
(needs.changes.outputs.worker == 'true' || needs.changes.outputs.festivals == 'true')
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: cloudflare-worker/package-lock.json
- name: Install worker dependencies
working-directory: cloudflare-worker
run: npm ci
- name: Copy festivals.json to worker directory
run: cp data/festivals.json cloudflare-worker/festivals.json
- name: Validate worker (dry-run)
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
workingDirectory: cloudflare-worker
command: deploy --dry-run
# Deploy Cloudflare Worker to production
deploy-worker:
needs: changes
runs-on: ubuntu-latest
if: |
github.ref == 'refs/heads/main' &&
(github.event_name == 'workflow_dispatch' ||
needs.changes.outputs.worker == 'true' ||
needs.changes.outputs.festivals == 'true')
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: '**/package-lock.json'
- name: Validate festivals.json
if: |
github.event_name == 'workflow_dispatch' ||
needs.changes.outputs.festivals == 'true'
run: |
cd scripts && npm ci
node validate-festivals.js
- name: Install worker dependencies
working-directory: cloudflare-worker
run: npm ci
- name: Copy festivals.json to worker directory
run: cp data/festivals.json cloudflare-worker/festivals.json
- name: Deploy Cloudflare Worker
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
workingDirectory: cloudflare-worker