-
Notifications
You must be signed in to change notification settings - Fork 8
387 lines (366 loc) · 14.6 KB
/
ci.yml
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
name: CI
on:
merge_group:
pull_request:
push:
branches: [main, dev]
workflow_dispatch:
concurrency:
group: ${{ github.ref }}
cancel-in-progress: true
jobs:
# set yarn cache
cache-deps:
runs-on: self-hosted
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Setup Environment
uses: ./.github/actions/setup-env
with:
build-nextjs: true
env:
YARN_ENABLE_HARDENED_MODE: 0
- name: Show github refs
run: |
echo github.ref=${{ github.ref }}
echo github.head_ref=${{ github.head_ref }}
unit-tests:
name: Unit Tests
runs-on: self-hosted
needs: [cache-deps]
env:
ANVIL_MAINNET_FORK_URL: ${{ secrets.CI_ANVIL_MAINNET_FORK_URL }}
ANVIL_BASE_FORK_URL: ${{ secrets.CI_ANVIL_BASE_FORK_URL }}
FOUNDRY_BASE_SEPOLIA_RPC_URL: ${{ secrets.CI_FOUNDRY_BASE_SEPOLIA_RPC_URL }}
YARN_ENABLE_HARDENED_MODE: 0
steps:
- name: Install Tilt
id: tilt
shell: bash
run: |
cd /tmp
curl -fsSL https://raw.githubusercontent.com/tilt-dev/tilt/master/scripts/install.sh | bash
- name: Add hosts to /etc/hosts
run: |
sudo su
if grep -q "host.docker.internal" /etc/hosts; then
echo "Hosts file already contains host.docker.internal"
else
echo "127.0.0.1 host.docker.internal" | sudo tee -a /etc/hosts
fi
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Set up Homebrew
id: set-up-homebrew
uses: Homebrew/actions/setup-homebrew@master
- name: Brew Bundle
id: brew-bundle
run: |
brew bundle
brew cleanup
- name: Setup Environment
uses: ./.github/actions/setup-env
env:
YARN_ENABLE_HARDENED_MODE: 0
with:
yarn-install: false
- name: Load Next.js Build Cache
uses: actions/download-artifact@v4
with:
name: nextjs-build
path: ${{ github.workspace }}/apps/next/.next
# - name: Snaplet Login
# shell: bash
# run: bunx snaplet auth login ${{ secrets.CI_SNAPLET_AUTH_TOKEN }}
- name: Tilt CI
id: tilt-ci
shell: bash
run: tilt ci unit-tests --timeout=10m
- name: Lint
run: yarn lint
- name: Tilt Down
# always run tilt down if tilt ci started
if: always() && steps.tilt-ci.outcome != 'skipped'
shell: bash
run: tilt down
# @todo anvil fixtures cause dirty repo, but only in github actions 😢
- name: All Changes Committed
shell: bash
run: git diff # --exit-code
playwright-tests:
name: Playwright Tests
runs-on: self-hosted
needs: [cache-deps]
env:
ANVIL_MAINNET_FORK_URL: ${{ secrets.CI_ANVIL_MAINNET_FORK_URL }}
ANVIL_BASE_FORK_URL: ${{ secrets.CI_ANVIL_BASE_FORK_URL }}
YARN_ENABLE_HARDENED_MODE: 0
# for writing PR comments
permissions:
pull-requests: write
timeout-minutes: 40
steps:
- name: Install Tilt
id: tilt
shell: bash
run: |
cd /tmp
curl -fsSL https://raw.githubusercontent.com/tilt-dev/tilt/master/scripts/install.sh | bash
- name: Add hosts to /etc/hosts
run: |
sudo su
if grep -q "host.docker.internal" /etc/hosts; then
echo "Hosts file already contains host.docker.internal"
else
echo "127.0.0.1 host.docker.internal" | sudo tee -a /etc/hosts
fi
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Set up Homebrew
id: set-up-homebrew
uses: Homebrew/actions/setup-homebrew@master
- name: Brew Bundle
id: brew-bundle
run: |
brew bundle
brew cleanup
- name: Setup Environment
uses: ./.github/actions/setup-env
env:
YARN_ENABLE_HARDENED_MODE: 0
- name: Load Next.js Build Cache
uses: actions/download-artifact@v4
with:
name: nextjs-build
path: ${{ github.workspace }}/apps/next/.next
# - name: Snaplet Login
# shell: bash
# run: bunx snaplet auth login ${{ secrets.CI_SNAPLET_AUTH_TOKEN }}
- name: Install Playwright Dependencies
run: yarn playwright playwright install --with-deps
# @todo anvil fixtures cause dirty repo, but only in github actions 😢
# - name: All Changes Committed
# shell: bash
# run: git diff --exit-code
# this is on purpose so we get github annotations
- name: Build Next.js
shell: bash
run: |
tilt ci yarn:install # install and setup env
yarn web:docker:build # build nextjs docker image
- name: Playwright Tests
id: playwright
shell: bash
run: |
# set debug logs if runner.debug is set
# if [ "${{runner.debug}}" == "1" ]; then
# export DEBUG="test:*,app:*,api:*,next:*"
# fi
export DEBUG="api:*,app:*,test:*,-test:fixtures:snaplet:*"
nohup tilt up playwright:deps &
tilt_pid=$!
echo "Tilt process started with PID: $tilt_pid"
echo waiting for tilt to be ready
for i in {1..10}; do
curl -s http://localhost:10350 > /dev/null && break || echo "Attempt $i failed, trying again..."
sleep 1
done
sleep 1
echo tilt is ready
max_attempts=60
wait_timeout=7
for ((i=1; i<=max_attempts; i++)); do
echo "Attempt $i: Waiting for tilt with timeout ${wait_timeout}s"
# Check if the Tilt process is still running
if ! ps -p $tilt_pid > /dev/null; then
echo "Tilt process (PID: $tilt_pid) is no longer running, exiting"
exit 1
fi
# Check if any targets are in error
has_errors=$(tilt dump engine | jq '
.ManifestTargets
| to_entries
| map(
select(
.value.State.RuntimeState.Status == "error" or
(.value.State.BuildHistory | length > 0 and .[0].Error != null)
)
)
| length > 0
')
if [ "$has_errors" = "true" ]; then
echo "There are targets in error status:"
tilt dump engine | jq '
.ManifestTargets
| to_entries
| map(
select(
.value.State.RuntimeState.Status == "error" or
(.value.State.BuildHistory | length > 0 and .[0].Error != null)
)
)
| map(.key)
'
exit 1
fi
if tilt wait --timeout "${wait_timeout}s" --for=condition=Ready "uiresource/playwright:deps"; then
echo "Tilt is ready"
break
else
echo "Tilt not ready, retrying..."
if [ "${{runner.debug}}" == "1" ]; then
tilt dump engine | jq '
.ManifestTargets
| to_entries
| map({key: (.value.State.RuntimeState.Status // "in_progress"), value: .key})
| group_by(.key)
| map({key: .[0].key, value: map(.value)})
| from_entries
'
fi
fi
if ((i == max_attempts)); then
echo "Reached maximum attempts, exiting"
exit 1
fi
done
yarn playwright test
- name: Playwright Markdown Report
if: always() && steps.playwright.outcome != 'skipped'
id: playwright-md-report
shell: bash
run: |
echo "Markdown report:"
echo "------------------"
bun run packages/playwright/bin/report-markdown.ts > playwright-report.md
cat playwright-report.md
echo "------------------"
echo "Markdown report end"
- uses: mshick/add-pr-comment@v2
if: always() && steps.playwright.outcome != 'skipped'
with:
message-id: playwright-report
refresh-message-position: true
message-path: |
playwright-report.md
- name: Tilt Down
# always run tilt down if tilt ci started
if: always() && steps.playwright.outcome != 'skipped'
shell: bash
run: tilt down
- name: Playwright Report
uses: actions/upload-artifact@v4
if: always() && steps.playwright.outcome == 'failure'
with:
name: playwright-report
path: packages/playwright/playwright-report/
retention-days: 30
- name: Playwright Test Results
uses: actions/upload-artifact@v4
if: always() && steps.playwright.outcome == 'failure'
with:
name: playwright-test-results
path: packages/playwright/test-results/
retention-days: 30
vercel-deploy-preview:
# **always** skip if on dev and main since it will be deployed with another workflow
if: ${{ github.ref != 'refs/heads/dev' && github.ref != 'refs/heads/main' && github.head_ref != 'dev' && github.head_ref != 'main' }}
runs-on: ubuntu-latest
needs: [cache-deps]
permissions:
pull-requests: write
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Setup Environment
uses: ./.github/actions/setup-env
with:
yarn-install: false
env:
YARN_ENABLE_HARDENED_MODE: 0
- name: Load Next.js Build Cache
uses: actions/download-artifact@v4
with:
name: nextjs-build
path: ${{ github.workspace }}/apps/next/.next
- name: Extract branch name
id: extract-branch
uses: ./.github/actions/extract-branch
- name: Set Public Hostname
id: public-hostname
run: echo "public-hostname=sendapp-${{steps.extract-branch.outputs.branch}}-0xsend.vercel.app" >> $GITHUB_OUTPUT
- name: Vercel Deploy Preview with Supabase Branch
if: github.base_ref == 'dev'
id: vercel-deploy-with-branch
uses: ./.github/actions/vercel-deploy
with:
vercel-token: ${{ secrets.VERCEL_TOKEN }}
public-hostname: ${{ steps.public-hostname.outputs.public-hostname }}
deploy-preview-extra-args: >-
-e SUPABASE_DB_URL="${{ secrets.STAGING_SUPABASE_DB_URL }}"
-e SUPABASE_JWT_SECRET="${{ secrets.STAGING_SUPABASE_JWT_SECRET }}"
-e SUPABASE_SERVICE_ROLE="${{ secrets.STAGING_SUPABASE_SERVICE_ROLE }}"
-e NEXT_PUBLIC_SUPABASE_URL="https://${{ secrets.STAGING_SUPABASE_PROJECT_ID }}.supabase.co"
-e NEXT_PUBLIC_SUPABASE_PROJECT_ID="${{ secrets.STAGING_SUPABASE_PROJECT_ID }}"
-e NEXT_PUBLIC_SUPABASE_GRAPHQL_URL="https://${{ secrets.STAGING_SUPABASE_PROJECT_ID }}.supabase.co/graphql"
-e NEXT_PUBLIC_BASE_CHAIN_ID="84532"
-e NEXT_PUBLIC_MAINNET_CHAIN_ID="11155111"
-e NEXT_PUBLIC_BASE_RPC_URL="${{ secrets.BASE_SEPOLIA_RPC_URL }}"
-e NEXT_PUBLIC_MAINNET_RPC_URL="https://ethereum-sepolia-rpc.publicnode.com"
-e NEXT_PUBLIC_SUPABASE_ANON_KEY="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InVncXRvdWxleGh2YWhldnN5c3VxIiwicm9sZSI6ImFub24iLCJpYXQiOjE2OTMwOTE5MzUsImV4cCI6MjAwODY2NzkzNX0.RL8W-jw2rsDhimYl8KklF2B9bNTPQ-Kj5zZA0XlufUA"
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
VERCEL_GIT_COMMIT_SHA: ${{ github.sha }}
VERCEL_GIT_COMMIT_REF: ${{ github.head_ref }}
VERCEL_GIT_PULL_REQUEST_ID: ${{ github.event.pull_request.number }}
SUPABASE_DB_URL: ${{ secrets.STAGING_SUPABASE_DB_URL }}
SUPABASE_JWT_SECRET: ${{ secrets.STAGING_SUPABASE_JWT_SECRET }}
SUPABASE_SERVICE_ROLE: ${{ secrets.STAGING_SUPABASE_SERVICE_ROLE }}
NEXT_PUBLIC_SUPABASE_URL: https://${{ secrets.STAGING_SUPABASE_PROJECT_ID }}.supabase.co
NEXT_PUBLIC_SUPABASE_PROJECT_ID: ${{ secrets.STAGING_SUPABASE_PROJECT_ID }}
NEXT_PUBLIC_SUPABASE_GRAPHQL_URL: https://${{ secrets.STAGING_SUPABASE_PROJECT_ID }}.supabase.co/graphql
NEXT_PUBLIC_BASE_CHAIN_ID: 84532
NEXT_PUBLIC_MAINNET_CHAIN_ID: 11155111
NEXT_PUBLIC_BASE_RPC_URL: ${{ secrets.BASE_SEPOLIA_RPC_URL }}
NEXT_PUBLIC_MAINNET_RPC_URL: https://ethereum-sepolia-rpc.publicnode.com
NEXT_PUBLIC_SUPABASE_ANON_KEY: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InVncXRvdWxleGh2YWhldnN5c3VxIiwicm9sZSI6ImFub24iLCJpYXQiOjE2OTMwOTE5MzUsImV4cCI6MjAwODY2NzkzNX0.RL8W-jw2rsDhimYl8KklF2B9bNTPQ-Kj5zZA0XlufUA
- name: Vercel Deploy Preview
if: github.base_ref != 'dev'
id: vercel-deploy-preview
uses: ./.github/actions/vercel-deploy
with:
vercel-token: ${{ secrets.VERCEL_TOKEN }}
public-hostname: ${{ steps.public-hostname.outputs.public-hostname }}
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
VERCEL_GIT_COMMIT_SHA: ${{ github.sha }}
VERCEL_GIT_COMMIT_REF: ${{ github.head_ref }}
VERCEL_GIT_PULL_REQUEST_ID: ${{ github.event.pull_request.number }}
- uses: mshick/add-pr-comment@v2
if: github.base_ref == 'dev'
with:
message-id: vercel-preview-url
refresh-message-position: true
message: |
Vercel Unique URL: [${{ steps.vercel-deploy-with-branch.outputs.deployment-url }}](${{ steps.vercel-deploy-with-branch.outputs.deployment-url }})
Vercel Preview URL: [${{ steps.public-hostname.outputs.public-hostname }}](https://${{ steps.public-hostname.outputs.public-hostname }}/)
Last Commit: ${{ github.event.pull_request.head.sha }}
- uses: mshick/add-pr-comment@v2
if: github.base_ref != 'dev'
with:
message-id: vercel-preview-url
refresh-message-position: true
message: |
Vercel Unique URL: [${{ steps.vercel-deploy-preview.outputs.deployment-url }}](${{ steps.vercel-deploy-preview.outputs.deployment-url }})
Vercel Preview URL: [${{ steps.public-hostname.outputs.public-hostname }}](https://${{ steps.public-hostname.outputs.public-hostname }}/)
Last Commit: ${{ github.event.pull_request.head.sha }}