Repository navigation
417 lines (378 loc) · 16.5 KB
/
Copy pathci.yml
File metadata and controls
417 lines (378 loc) · 16.5 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
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
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
name: CI
on:
pull_request:
push:
branches:
- main
- dev
permissions:
contents: read
concurrency:
group: ci-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
changes:
name: Changes
runs-on: openscholar-light
timeout-minutes: 5
permissions:
actions: read
contents: read
outputs:
tested: ${{ steps.tested.outputs.passed }}
runtime_required: ${{ steps.detect.outputs.runtime_required }}
steps:
# A pull request run tests the merge result and, when every check ran and
# passed, records the tree it tested. A push to dev with that tree has
# nothing new to test. Pushes to main always run.
- name: Look for a passed pull request run of this tree
id: tested
if: github.event_name == 'push' && github.ref == 'refs/heads/dev'
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
set -uo pipefail
api="$GITHUB_API_URL/repos/$GITHUB_REPOSITORY"
auth="Authorization: Bearer $GITHUB_TOKEN"
# Any lookup failure runs the full suite.
passed=false
tree="$(curl -fsS -H "$auth" "$api/git/commits/$GITHUB_SHA" | jq -r .tree.sha)" || tree=""
runs=""
if [ -n "$tree" ]; then
runs="$(curl -fsS -H "$auth" "$api/actions/artifacts?name=ci-passed-$tree" \
| jq -r '.artifacts[] | select(.expired | not) | .workflow_run.id')" || runs=""
fi
# Only a successful pull request run of this workflow from this
# repository counts. A fork could upload the same artifact name.
for run in $runs; do
if curl -fsS -H "$auth" "$api/actions/runs/$run" | jq -e --arg repository "$GITHUB_REPOSITORY" \
'.path == ".github/workflows/ci.yml" and .event == "pull_request" and .conclusion == "success" and .head_repository.full_name == $repository' > /dev/null; then
passed=true
echo "Pull request run $run already passed tree $tree."
break
fi
done
echo "passed=$passed" >> "$GITHUB_OUTPUT"
- if: steps.tested.outputs.passed != 'true'
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Detect runtime changes
id: detect
if: steps.tested.outputs.passed != 'true'
shell: bash
env:
EVENT_NAME: ${{ github.event_name }}
BASE_SHA: ${{ github.event.pull_request.base.sha }}
run: |
set -euo pipefail
if [[ "$EVENT_NAME" != "pull_request" ]]; then
echo "runtime_required=true" >> "$GITHUB_OUTPUT"
exit 0
fi
if [[ -z "$BASE_SHA" ]] || ! git cat-file -e "$BASE_SHA^{commit}"; then
echo "Could not resolve the pull request base. Running runtime tests."
echo "runtime_required=true" >> "$GITHUB_OUTPUT"
exit 0
fi
if ! changed_files="$(git diff --name-only --no-renames "$BASE_SHA" "$GITHUB_SHA")"; then
echo "Could not resolve changed files. Running runtime tests."
echo "runtime_required=true" >> "$GITHUB_OUTPUT"
exit 0
fi
runtime_required=false
while IFS= read -r changed_file; do
[[ -z "$changed_file" ]] && continue
case "$changed_file" in
*.md|*.png|*.jpg|*.jpeg|*.webp|docs/*|plans/*|.agents/*|.claude/*|convex/_generated/*)
;;
*)
runtime_required=true
break
;;
esac
done <<< "$changed_files"
echo "runtime_required=$runtime_required" >> "$GITHUB_OUTPUT"
unit-tests:
name: Unit tests
runs-on: openscholar-light
timeout-minutes: 20
needs: changes
if: needs.changes.outputs.tested != 'true'
outputs:
email_source: ${{ steps.email-source-access.outputs.available }}
env:
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY: pk_test_placeholder
CLERK_SECRET_KEY: sk_test_placeholder
NEXT_PUBLIC_CLERK_SIGN_IN_URL: /sign-in
NEXT_PUBLIC_CLERK_SIGN_UP_URL: /sign-up
NEXT_PUBLIC_CONVEX_URL: https://example.convex.cloud
steps:
# Full history: the Convex rules compare pending lists with the branch's base.
- uses: actions/checkout@v6
with:
fetch-depth: 0
- uses: ./.github/actions/setup-project
- name: Check email source access
id: email-source-access
env:
SOURCE_KEY: ${{ secrets.EVIDENCE_LIBRARY_SOURCE_KEY }}
run: |
if [ -n "$SOURCE_KEY" ]; then
echo "available=true" >> "$GITHUB_OUTPUT"
elif [ "${{ github.event_name }}" = "pull_request" ]; then
echo "available=false" >> "$GITHUB_OUTPUT"
echo "::notice::Shared email source verification needs repository secrets; unit tests will still run."
else
echo "::error::The shared email source key is missing."
exit 1
fi
- name: Read the pinned email source revision
if: steps.email-source-access.outputs.available == 'true'
id: email-source
run: echo "commit=$(node -p 'require("./lib/emails/source-lock.json").commit')" >> "$GITHUB_OUTPUT"
- name: Check out the shared email source
if: steps.email-source-access.outputs.available == 'true'
uses: actions/checkout@v6
with:
repository: OpenDevEd/evidence-community
ref: ${{ steps.email-source.outputs.commit }}
fetch-depth: 0
ssh-key: ${{ secrets.EVIDENCE_LIBRARY_SOURCE_KEY }}
path: .email-source
sparse-checkout: |
src/lib/emails/library-template.ts
src/lib/escape-html.ts
sparse-checkout-cone-mode: false
persist-credentials: false
- name: Verify the shared email source
if: steps.email-source-access.outputs.available == 'true'
run: npm run check:email-template -- .email-source
- name: Remove the source checkout
if: always()
run: rm -rf .email-source
- name: Check UI rules
run: npm run check:ui-rules
- name: Check every OpenAlex request carries the key
run: npm run check:openalex-key
- name: Check only extraction imports its mutations and queries
run: npm run check:extraction-imports
- name: Check only the assistant's modules load its agent
run: npm run check:module-weight
- name: Check every user action is registered for the assistant
run: npm run check:user-actions
- name: Check the Convex rules (every list paged, returns validators, no clock in queries)
env:
# A pull request compares with its base; a push with the commit it moved from.
RULES_BASE: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.before }}
run: npm run check:convex-rules
# The browser job builds Next.js on the same guest at the same time. Fifteen jsdom workers on a shared CPU share pushed single tests
# past their timeouts; eight finish sooner.
# CI's one type check (the e2e build skips its own) runs beside the tests.
- name: Type check, and run unit and contract tests
run: |
(npx next typegen && npx tsc --noEmit) > "$RUNNER_TEMP/types.log" 2>&1 &
types=$!
tests_status=0
npm run test -- --maxWorkers=8 || tests_status=$?
types_status=0
wait "$types" || types_status=$?
echo "::group::Type check"
cat "$RUNNER_TEMP/types.log"
echo "::endgroup::"
if (( tests_status != 0 || types_status != 0 )); then
printf '::error::Failed: tests=%s types=%s\n' "$tests_status" "$types_status"
exit 1
fi
e2e-auth:
runs-on: openscholar-secret
timeout-minutes: 30
# Starts with the unit tests instead of after them. Its production build is CI's only
# Next.js build; the unit job type-checks, so this one doesn't.
needs: changes
if: needs.changes.outputs.runtime_required == 'true'
outputs:
ran: ${{ steps.auth-environment.outputs.available }}
# One test backend: each run pushes its own Convex functions, so runs take turns.
concurrency:
group: e2e-auth-convex
cancel-in-progress: false
env:
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY: ${{ secrets.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY }}
CLERK_PUBLISHABLE_KEY: ${{ secrets.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY }}
CLERK_SECRET_KEY: ${{ secrets.CLERK_SECRET_KEY }}
NEXT_PUBLIC_CLERK_SIGN_IN_URL: ${{ secrets.NEXT_PUBLIC_CLERK_SIGN_IN_URL }}
NEXT_PUBLIC_CLERK_SIGN_UP_URL: ${{ secrets.NEXT_PUBLIC_CLERK_SIGN_UP_URL }}
# Self-hosted test backend on the Hetzner Coolify (service openscholar-e2e).
NEXT_PUBLIC_CONVEX_URL: https://convex-e2e.opendev.space
NEXT_PUBLIC_CONVEX_SITE_URL: https://convex-e2e-site.opendev.space
CLERK_JWT_ISSUER_DOMAIN: ${{ secrets.CLERK_JWT_ISSUER_DOMAIN }}
CLERK_WEBHOOK_SIGNING_SECRET: ${{ secrets.CLERK_WEBHOOK_SIGNING_SECRET }}
E2E_CLERK_USER_EMAIL: ${{ secrets.E2E_CLERK_USER_EMAIL }}
E2E_CLERK_USER_PASSWORD: ${{ secrets.E2E_CLERK_USER_PASSWORD }}
E2E_CLERK_ORGANIZATION_ID: ${{ secrets.E2E_CLERK_ORGANIZATION_ID }}
E2E_BASE_URL: http://localhost:3000
# Anonymous OpenAlex search is paused whenever its cluster is under load.
OPENALEX_API_KEY: ${{ secrets.OPENALEX_API_KEY }}
PLAYWRIGHT_WEB_SERVER_COMMAND: npm run build && npm run start -- --hostname localhost --port 3000
NEXT_BUILD_SKIP_VERIFIED_TYPES: "1"
steps:
- uses: actions/checkout@v6
- name: Check auth test environment
id: auth-environment
run: |
required_vars=(
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY
CLERK_PUBLISHABLE_KEY
CLERK_SECRET_KEY
NEXT_PUBLIC_CLERK_SIGN_IN_URL
NEXT_PUBLIC_CLERK_SIGN_UP_URL
NEXT_PUBLIC_CONVEX_URL
CLERK_JWT_ISSUER_DOMAIN
CLERK_WEBHOOK_SIGNING_SECRET
E2E_CLERK_USER_EMAIL
E2E_CLERK_USER_PASSWORD
)
missing_vars=()
for var_name in "${required_vars[@]}"; do
if [ -z "${!var_name}" ]; then
missing_vars+=("$var_name")
fi
done
if [ "${#missing_vars[@]}" -eq 0 ]; then
echo "available=true" >> "$GITHUB_OUTPUT"
exit 0
fi
if [ "${{ github.event_name }}" = "push" ]; then
printf '::error::Missing required auth secret/env: %s\n' "${missing_vars[*]}"
exit 1
fi
echo "available=false" >> "$GITHUB_OUTPUT"
printf '::notice::Skipping auth E2E because this pull request has no auth test environment: %s\n' "${missing_vars[*]}"
- uses: ./.github/actions/setup-project
# Without the auth environment, as on a fork's pull request, the browser tests can't
# run, but CI's one production build still must.
- name: Build without the auth environment
if: steps.auth-environment.outputs.available != 'true'
env:
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY: pk_test_placeholder
CLERK_SECRET_KEY: sk_test_placeholder
NEXT_PUBLIC_CLERK_SIGN_IN_URL: /sign-in
NEXT_PUBLIC_CLERK_SIGN_UP_URL: /sign-up
run: npm run build
- name: Install Playwright browser
if: steps.auth-environment.outputs.available == 'true'
run: npx playwright install chromium
# The test runs this change's frontend, so the backend gets this change's functions.
# The admin key is given to this step only, not to install, build or tests.
- name: Push Convex functions to the test backend
if: steps.auth-environment.outputs.available == 'true'
env:
CONVEX_SELF_HOSTED_URL: https://convex-e2e.opendev.space
CONVEX_SELF_HOSTED_ADMIN_KEY: ${{ secrets.E2E_CONVEX_SELF_HOSTED_ADMIN_KEY }}
run: |
if [ -z "$CONVEX_SELF_HOSTED_ADMIN_KEY" ]; then
echo "::error::E2E_CONVEX_SELF_HOSTED_ADMIN_KEY is not set"
exit 1
fi
npx convex deploy --yes --typecheck=disable
# Each run reserves a library, and an organization holds 200 at most: the test
# backend starts every run with none. Its only libraries are the ones runs made.
: > "$RUNNER_TEMP/no-rows.jsonl"
for table in evidenceLibraries evidenceLibraryConfigDrafts evidenceLibraryConfigRevisions evidenceLibraryConfigSections evidenceLibraryConfigOperations evidenceLibraryRuntimeBindings; do
npx convex import --table "$table" --replace --yes "$RUNNER_TEMP/no-rows.jsonl"
done
# An import skips the triggers that count those rows, so the counts kept from them go too.
npx convex run migrations/pagedLibraryList:reset
# The runner keeps the Next.js build cache between runs: without its type check, a build
# a few merged pull requests later takes a quarter of the CPU of a cold one.
- name: Restore the Next.js build cache
if: steps.auth-environment.outputs.available == 'true'
run: |
mkdir -p .next
if [ -d "$HOME/.cache/openscholar-next" ]; then mv "$HOME/.cache/openscholar-next" .next/cache; fi
- name: Run auth and citation E2E
if: steps.auth-environment.outputs.available == 'true'
run: npx playwright test e2e/auth.spec.ts e2e/citations.spec.ts --config=playwright.config.ts
- name: Keep the Next.js build cache
if: always() && steps.auth-environment.outputs.available == 'true'
run: |
if [ -d .next/cache ]; then
mkdir -p "$HOME/.cache"
rm -rf "$HOME/.cache/openscholar-next"
mv .next/cache "$HOME/.cache/openscholar-next"
fi
- name: Upload Playwright report
if: failure() && steps.auth-environment.outputs.available == 'true'
continue-on-error: true
uses: actions/upload-artifact@v7
with:
name: playwright-report
path: playwright-report
if-no-files-found: ignore
retention-days: 7
- name: Upload app logs
if: failure() && steps.auth-environment.outputs.available == 'true'
continue-on-error: true
uses: actions/upload-artifact@v7
with:
name: playwright-output
path: test-results
if-no-files-found: ignore
retention-days: 7
ci:
name: CI
runs-on: openscholar-light
timeout-minutes: 5
if: always()
needs:
- changes
- unit-tests
- e2e-auth
steps:
- name: Require every selected CI lane to pass
env:
TESTED: ${{ needs.changes.outputs.tested }}
CHANGES: ${{ needs.changes.result }}
UNIT_TESTS: ${{ needs.unit-tests.result }}
RUNTIME_REQUIRED: ${{ needs.changes.outputs.runtime_required }}
AUTH: ${{ needs.e2e-auth.result }}
run: |
if [ "$TESTED" = true ]; then
echo "A pull request run already passed this tree."
exit 0
fi
test "$CHANGES" = success
test "$UNIT_TESTS" = success
if test "$RUNTIME_REQUIRED" = true; then
test "$AUTH" = success
else
test "$AUTH" = skipped
fi
# A check that skipped its steps for missing secrets proves nothing, so
# only a run where every check ran records its tree.
- name: Name the tested tree
id: tree
if: >-
github.event_name == 'pull_request' &&
needs.unit-tests.outputs.email_source == 'true' &&
(needs.changes.outputs.runtime_required != 'true' ||
needs.e2e-auth.outputs.ran == 'true')
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
tree="$(curl -fsS -H "Authorization: Bearer $GITHUB_TOKEN" \
"$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/git/commits/$GITHUB_SHA" | jq -r .tree.sha)"
echo "$tree" > "$RUNNER_TEMP/tested-tree"
echo "sha=$tree" >> "$GITHUB_OUTPUT"
# A record that can't be saved, such as when the organisation's artifact
# storage is full, only makes the push run the full suite again.
- name: Record the tested tree
if: steps.tree.outcome == 'success'
continue-on-error: true
uses: actions/upload-artifact@v7
with:
name: ci-passed-${{ steps.tree.outputs.sha }}
path: ${{ runner.temp }}/tested-tree
retention-days: 14