-
Notifications
You must be signed in to change notification settings - Fork 1
322 lines (280 loc) · 9.15 KB
/
Copy pathci.yml
File metadata and controls
322 lines (280 loc) · 9.15 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
name: CI
on:
workflow_call:
jobs:
actionlint:
name: actionlint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run actionlint
run: |
docker run --rm -v "$PWD:/repo" -w /repo \
rhysd/actionlint:1.7.7 -color
lint:
name: Lint & depcheck
runs-on: ubuntu-latest
services:
redis:
image: redis:6-alpine
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 6379:6379
postgres:
image: debezium/postgres:14
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- uses: actions/checkout@v4
- name: Setup Node and pnpm
uses: ./.github/actions/node-and-cache
- name: Install pg_dump
uses: ./.github/actions/install-pg-dump
- name: Setup environment and database
run: |
cp .env.ci .env
CONFIRM_DROP=1 pnpm run setup
- name: Verify data/schema.sql is up to date
run: |
if ! git diff --exit-code -- data/schema.sql; then
echo "::error::data/schema.sql is stale. Run 'pnpm --filter @app/db run dump' locally and commit the result."
exit 1
fi
- name: Build
run: pnpm build
- name: Lint (tsc + prettier + eslint)
run: pnpm lint
- name: Depcheck
run: pnpm depcheck
test:
name: Unit tests
runs-on: ubuntu-latest
services:
redis:
image: redis:6-alpine
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 6379:6379
postgres:
image: debezium/postgres:14
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- uses: actions/checkout@v4
- name: Setup Node and pnpm
uses: ./.github/actions/node-and-cache
- name: Install pg_dump
uses: ./.github/actions/install-pg-dump
- name: Setup environment and database
run: |
cp .env.ci .env
CONFIRM_DROP=1 pnpm run setup
- name: Build
run: pnpm build
- name: Test
# --runInBand: debezium/postgres has a single replication slot,
# so parallel jest workers race on it.
run: pnpm test --ci --runInBand
docker:
name: Production Docker build
runs-on: ubuntu-latest
services:
redis:
image: redis:6-alpine
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 6379:6379
postgres:
image: debezium/postgres:14
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- uses: actions/checkout@v4
- name: Setup Node and pnpm
uses: ./.github/actions/node-and-cache
- name: Install pg_dump
uses: ./.github/actions/install-pg-dump
- name: Setup environment and database
run: |
cp .env.ci .env
CONFIRM_DROP=1 pnpm run setup
env:
CI: "true"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build production image
uses: docker/build-push-action@v6
with:
file: ./Dockerfile
load: true
push: false
build-args: ROOT_URL=https://ilmo.prodeko.org
tags: |
ilmo-server:ci
ilmo-worker:ci
secrets: |
GITHUB_SHA=${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Start server container
run: |
docker run -d -p 5678:5678 \
--add-host=host.docker.internal:host-gateway \
--env-file .env \
-e CI=true \
-e NODE_ENV=production \
-e DATABASE_HOST=host.docker.internal \
-e REDIS_URL=redis://host.docker.internal:6379 \
--name ilmo-server ilmo-server:ci
- name: Start worker container
run: |
docker run -d \
--add-host=host.docker.internal:host-gateway \
--env-file .env \
-e CI=true \
-e NODE_ENV=production \
-e DATABASE_HOST=host.docker.internal \
-e REDIS_URL=redis://host.docker.internal:6379 \
--name ilmo-worker ilmo-worker:ci \
pnpm --filter @app/worker run start
- name: Wait for server to come up
run: |
curl --fail --retry 30 --retry-delay 1 --retry-all-errors \
--silent --show-error http://localhost:5678 > /tmp/homepage.html
- name: Assert homepage rendered
run: grep -q Prodeko /tmp/homepage.html
- name: Dump container logs
if: always()
run: |
echo "::group::ilmo-server logs"
docker logs ilmo-server || true
echo "::endgroup::"
echo "::group::ilmo-worker logs"
docker logs ilmo-worker || true
echo "::endgroup::"
- name: Tear down containers
if: always()
run: |
docker stop ilmo-server ilmo-worker 2>/dev/null || true
docker rm ilmo-server ilmo-worker 2>/dev/null || true
bundle:
name: Next.js bundle analysis
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./@app/client
steps:
- uses: actions/checkout@v4
- name: Setup Node and pnpm
uses: ./.github/actions/node-and-cache
- name: Prepare CI env file
run: cp .env.ci .env
working-directory: .
- name: Restore Next.js build cache
uses: actions/cache@v4
with:
path: "@app/client/.next/cache"
key: ${{ runner.os }}-nextcache-${{ hashFiles('pnpm-lock.yaml') }}-${{ hashFiles('@app/client/**/*.{js,jsx,ts,tsx,json}') }}
restore-keys: |
${{ runner.os }}-nextcache-${{ hashFiles('pnpm-lock.yaml') }}-
${{ runner.os }}-nextcache-
- name: Build workspace dependencies
run: pnpm -r --workspace-concurrency=1 --filter "!@app/client" run build
working-directory: .
- name: Build Next.js app
run: pnpm --filter @app/client run build
working-directory: .
- name: Analyze bundle
run: npx -p nextjs-bundle-analysis report
- name: Upload bundle stats
uses: actions/upload-artifact@v4
with:
name: bundle
path: "@app/client/.next/analyze/__bundle_analysis.json"
- name: Download base branch bundle stats
id: download-base
if: github.event_name == 'pull_request'
uses: dawidd6/action-download-artifact@v6
continue-on-error: true
with:
workflow: pipeline.yml
branch: ${{ github.event.pull_request.base.ref }}
name: bundle
path: "@app/client/.next/analyze/base/bundle"
- name: Check baseline presence
id: baseline
if: github.event_name == 'pull_request'
run: |
if [ -f "@app/client/.next/analyze/base/bundle/__bundle_analysis.json" ]; then
echo "found=true" >> "$GITHUB_OUTPUT"
else
echo "found=false" >> "$GITHUB_OUTPUT"
echo "::notice::No baseline bundle artifact for ${{ github.event.pull_request.base.ref }}; skipping comparison."
fi
working-directory: .
- name: Compare with base branch bundle
if: steps.baseline.outputs.found == 'true'
run: npx -p nextjs-bundle-analysis compare
- name: Read comment body
id: get-comment-body
if: steps.baseline.outputs.found == 'true'
run: |
{
echo 'body<<EOF'
cat .next/analyze/__bundle_analysis_comment.txt
echo 'EOF'
} >> "$GITHUB_OUTPUT"
- name: Find existing comment
if: steps.baseline.outputs.found == 'true'
uses: peter-evans/find-comment@v3
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
body-includes: "<!-- __NEXTJS_BUNDLE -->"
- name: Create or update bundle comment
if: steps.baseline.outputs.found == 'true'
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.pull_request.number }}
comment-id: ${{ steps.fc.outputs.comment-id }}
body: ${{ steps.get-comment-body.outputs.body }}
edit-mode: replace