-
Notifications
You must be signed in to change notification settings - Fork 323
345 lines (311 loc) · 12.7 KB
/
deploy_examples.yml
File metadata and controls
345 lines (311 loc) · 12.7 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
name: Deploy Examples
on:
push:
branches: ['main']
# pull_request:
# paths: ['examples/*/**']
concurrency:
group: ${{ github.event_name == 'push' && 'prod-deploy-group' || format('examples-pr-{0}', github.event.number) }}
jobs:
changed-files:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.create-example-matrix.outputs.matrix }}
has_changes: ${{ steps.create-example-matrix.outputs.has_changes }}
steps:
- uses: actions/checkout@v4
- name: Check for changed files
id: changed-files
uses: tj-actions/changed-files@ed68ef82c095e0d48ec87eccea555d944a631a4c
with:
path: 'examples'
diff_relative: true
dir_names: true
dir_names_max_depth: 1
# Whitelist examples that need to be deployed
files: |
yjs/**
linearlite-read-only/**
write-patterns/**
nextjs/**
todo-app/**
proxy-auth/**
phoenix-liveview/**
tanstack/**
remix/**
react/**
burn/**
tanstack-db-web-starter/**
- name: Create example matrix
id: create-example-matrix
run: |
# Get changed example directories
CHANGED_DIRS="${{ steps.changed-files.outputs.all_changed_files }}"
# Initialize empty JSON array
MATRIX='{"example":[]}'
HAS_CHANGES="false"
# Add each changed directory to the matrix
if [ -n "$CHANGED_DIRS" ]; then
for dir in $CHANGED_DIRS; do
name=$(basename $dir)
MATRIX=$(echo $MATRIX | jq --arg name "$name" --arg path "examples/$name" '.example += [{"name": $name, "path": $path}]')
HAS_CHANGES="true"
done
fi
# Use jq to properly format and escape the JSON
echo "matrix=$(echo $MATRIX | jq -c '.')" >> $GITHUB_OUTPUT
echo "has_changes=$HAS_CHANGES" >> $GITHUB_OUTPUT
deploy:
name: Deploy ${{ matrix.example.name }}
environment: ${{ github.event_name == 'push' && 'Production' || 'Pull request' }}
runs-on: ubuntu-latest
continue-on-error: true
needs: changed-files
if: ${{ needs.changed-files.outputs.has_changes == 'true' }}
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.changed-files.outputs.matrix) }}
outputs:
yjs: ${{ steps.deploy.outputs.yjs }}
linearlite-read-only: ${{ steps.deploy.outputs.linearlite-read-only }}
write-patterns: ${{ steps.deploy.outputs.write-patterns }}
nextjs: ${{ steps.deploy.outputs.nextjs }}
todo-app: ${{ steps.deploy.outputs.todo-app }}
proxy-auth: ${{ steps.deploy.outputs.proxy-auth }}
phoenix-liveview: ${{ steps.deploy.outputs.phoenix-liveview }}
tanstack: ${{ steps.deploy.outputs.tanstack }}
remix: ${{ steps.deploy.outputs.remix }}
react: ${{ steps.deploy.outputs.react }}
burn: ${{ steps.deploy.outputs.burn }}
tanstack-db-web-starter: ${{ steps.deploy.outputs.tanstack-db-web-starter }}
env:
DEPLOY_ENV: ${{ github.event_name == 'push' && 'production' || format('pr-{0}', github.event.number) }}
PULUMI_LOG_LEVEL: debug
SST_DEBUG: '1'
SHARED_INFRA_VPC_ID: ${{ vars.SHARED_INFRA_VPC_ID }}
SHARED_INFRA_CLUSTER_ARN: ${{ vars.SHARED_INFRA_CLUSTER_ARN }}
SHARED_EXAMPLES_DATABASE_URI: ${{ secrets.SHARED_EXAMPLES_DATABASE_URI }}
SHARED_EXAMPLES_POOLED_DATABASE_URI: ${{ secrets.SHARED_EXAMPLES_POOLED_DATABASE_URI }}
SHARED_EXAMPLES_SOURCE_ID: ${{ vars.SHARED_EXAMPLES_SOURCE_ID }}
SHARED_EXAMPLES_SOURCE_SECRET: ${{ secrets.SHARED_EXAMPLES_SOURCE_SECRET }}
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_DEFAULT_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_DEFAULT_ACCOUNT_ID }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
NEON_API_KEY: ${{ secrets.NEON_API_KEY }}
NEON_PROJECT_ID: ${{ secrets.NEON_PROJECT_ID }}
ELECTRIC_API: ${{ secrets.ELECTRIC_API }}
ELECTRIC_ADMIN_API: ${{ secrets.ELECTRIC_ADMIN_API }}
ELECTRIC_TEAM_ID: ${{ secrets.ELECTRIC_TEAM_ID }}
ELECTRIC_ADMIN_API_AUTH_TOKEN: ${{ secrets.ELECTRIC_ADMIN_API_AUTH_TOKEN }}
SECRET_KEY_BASE: ${{ secrets.LIVEVIEW_EXAMPLE_SECRET_KEY_BASE }}
ANTHROPIC_KEY: ${{ secrets.ANTHROPIC_KEY }}
QUICKSTART_DATABASE_URI: ${{ secrets.QUICKSTART_DATABASE_URI }}
QUICKSTART_POOLED_DATABASE_URI: ${{ secrets.QUICKSTART_POOLED_DATABASE_URI }}
QUICKSTART_SOURCE_ID: ${{ vars.QUICKSTART_SOURCE_ID }}
QUICKSTART_SOURCE_SECRET: ${{ secrets.QUICKSTART_SOURCE_SECRET }}
BETTER_AUTH_SECRET: ${{ secrets.BETTER_AUTH_SECRET }}
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version-file: '.tool-versions'
cache: 'pnpm'
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Cache SST state
uses: actions/cache@v4
with:
path: .sst
key: sst-cache-${{ matrix.example.name }}-${{ runner.os }}
restore-keys: |
sst-cache-${{ matrix.example.name }}-${{ runner.os }}
- name: Deploy
id: deploy
working-directory: ./${{ matrix.example.path }}
run: |
pnpm --filter @electric-sql/client --filter @electric-sql/experimental --filter @electric-sql/react run build
pnpm sst deploy --stage ${{ env.DEPLOY_ENV }}
if [ -f ".sst/outputs.json" ]; then
website=$(jq -r '.website' .sst/outputs.json)
echo "${{ matrix.example.name }}=$website" >> $GITHUB_OUTPUT
else
echo "sst outputs file not found. Exiting."
exit 123
fi
test-examples:
name: Test examples
needs: deploy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Test remix example
id: remix
continue-on-error: true
uses: ./.github/actions/test-example
with:
test_folder: remix
example_url: ${{ needs.deploy.outputs.remix || '' }}
- name: Test nextjs example
id: nextjs
continue-on-error: true
uses: ./.github/actions/test-example
with:
test_folder: nextjs
example_url: ${{ needs.deploy.outputs.nextjs || '' }}
- name: Test tanstack example
id: tanstack
continue-on-error: true
uses: ./.github/actions/test-example
with:
test_folder: tanstack
example_url: ${{ needs.deploy.outputs.tanstack || '' }}
- name: Test react example
id: react
continue-on-error: true
uses: ./.github/actions/test-example
with:
test_folder: '.shared'
example_url: ${{ needs.deploy.outputs.react || '' }}
- name: Test phoenix liveview example
id: liveview
continue-on-error: true
uses: ./.github/actions/test-example
with:
test_folder: phoenix-liveview
example_url: ${{ needs.deploy.outputs.phoenix-liveview || '' }}
- name: Test burn example
id: burn
continue-on-error: true
uses: ./.github/actions/test-example
with:
test_folder: burn
example_url: ${{ needs.deploy.outputs.burn || '' }}
- name: Test yjs example
id: yjs
continue-on-error: true
uses: ./.github/actions/test-example
with:
test_folder: '.shared'
example_url: ${{ needs.deploy.outputs.yjs || '' }}
- name: Test linearlite read-only example
id: linearlite-read-only
continue-on-error: true
uses: ./.github/actions/test-example
with:
test_folder: '.shared'
example_url: ${{ needs.deploy.outputs.linearlite-read-only || '' }}
- name: Test write patterns example
id: write-patterns
continue-on-error: true
uses: ./.github/actions/test-example
with:
test_folder: '.shared'
example_url: ${{ needs.deploy.outputs.write-patterns || '' }}
- name: Test todo-app example
id: todo-app
continue-on-error: true
uses: ./.github/actions/test-example
with:
test_folder: '.shared'
example_url: ${{ needs.deploy.outputs.todo-app || '' }}
- name: Report test failures
if: |
steps.remix.outcome == 'failure' ||
steps.nextjs.outcome == 'failure' ||
steps.tanstack.outcome == 'failure' ||
steps.react.outcome == 'failure' ||
steps.liveview.outcome == 'failure' ||
steps.yjs.outcome == 'failure' ||
steps.linearlite-read-only.outcome == 'failure' ||
steps.write-patterns.outcome == 'failure' ||
steps.todo-app.outcome == 'failure'
run: |
echo "The following examples failed:"
if [ "${{ steps.remix.outcome }}" == "failure" ]; then
echo "- Remix example"
fi
if [ "${{ steps.nextjs.outcome }}" == "failure" ]; then
echo "- Next.js example"
fi
if [ "${{ steps.tanstack.outcome }}" == "failure" ]; then
echo "- TanStack example"
fi
if [ "${{ steps.react.outcome }}" == "failure" ]; then
echo "- React example"
fi
if [ "${{ steps.liveview.outcome }}" == "failure" ]; then
echo "- Phoenix LiveView example"
fi
if [ "${{ steps.yjs.outcome }}" == "failure" ]; then
echo "- Yjs example"
fi
if [ "${{ steps.linearlite-read-only.outcome }}" == "failure" ]; then
echo "- LinearLite read-only example"
fi
if [ "${{ steps.write-patterns.outcome }}" == "failure" ]; then
echo "- Write patterns example"
fi
if [ "${{ steps.todo-app.outcome }}" == "failure" ]; then
echo "- Todo app example"
fi
exit 1
comment:
if: github.event_name == 'pull_request' && needs.changed-files.outputs.has_changes == 'true'
needs: [changed-files, deploy]
runs-on: ubuntu-latest
steps:
- name: Create PR comment with deployment URLs
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
// Get the matrix of examples that were deployed
const matrix = JSON.parse(${{ toJSON(needs.changed-files.outputs.matrix) }})
const urls = {
yjs: "${{ needs.deploy.outputs.yjs }}",
"linearlite-read-only": "${{ needs.deploy.outputs.linearlite-read-only }}",
"write-patterns": "${{ needs.deploy.outputs.write-patterns }}",
nextjs: "${{ needs.deploy.outputs.nextjs }}",
"todo-app": "${{ needs.deploy.outputs.todo-app }}",
"proxy-auth": "${{ needs.deploy.outputs.proxy-auth }}",
"phoenix-liveview": "${{ needs.deploy.outputs.phoenix-liveview }}",
"tanstack": "${{ needs.deploy.outputs.tanstack }}",
"remix": "${{ needs.deploy.outputs.remix }}",
"react": "${{ needs.deploy.outputs.react }}",
"tanstack-db-web-starter": "${{ needs.deploy.outputs.tanstack-db-web-starter }}"
}
// Create deployments array only for examples that were deployed
const deployments = matrix.example.map(example => ({
name: example.name,
url: urls[example.name]
}))
const commentBody = [
"## Examples",
...deployments.map(d => `- ${d.name}: ${d.url || '*deploy failed*'}`),
].join('\n')
const prNumber = context.issue.number
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
})
const existingComment = comments.find(comment => comment.user.login ==='github-actions[bot]' && comment.body.startsWith("## Examples"))
if (existingComment) {
// Update the existing comment
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existingComment.id,
body: commentBody,
})
} else {
// Create a new comment if none exists
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: commentBody,
})
}