-
Notifications
You must be signed in to change notification settings - Fork 153
478 lines (427 loc) · 15.6 KB
/
unit-tests-framework.yml
File metadata and controls
478 lines (427 loc) · 15.6 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
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
# BioNeMo Framework CI Workflow
#
# This workflow runs tests for BioNeMo framework sub-packages using a matrix
# strategy where each sub-package runs in its own container -- matching the
# pattern used by unit-tests-recipes.yml.
#
# TRIGGERS:
# - Push to main branch, pull-request branches, or dependabot branches
# - Merge group events (when PRs are merged via merge queue)
# - Scheduled runs (daily at 7 AM UTC)
#
# WORKFLOW OVERVIEW:
# 1. changed-files: Detects which sub-packages changed and computes the test matrix
# 2. pre-commit: Runs static code checks and linting
# 3. get-pr-labels: Retrieves PR labels for conditional job execution
# 4. run-tests / run-tests-slow / run-tests-notebooks: Per-sub-package matrix jobs
# 5. verify-tests-status: Verifies all test jobs completed successfully
name: "BioNeMo Framework CI"
on:
push:
branches:
- main
- "pull-request/[0-9]+"
- "dependabot/**"
merge_group:
types: [checks_requested]
schedule:
- cron: "0 7 * * *" # Runs at 7 AM UTC daily (12 AM MST)
defaults:
run:
shell: bash -x -e -u -o pipefail {0}
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
changed-files:
runs-on: ubuntu-latest
outputs:
any_changed: ${{ steps.changed-files.outputs.any_changed }}
matrix: ${{ steps.matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get merge-base commit
id: merge-base
run: |
MERGE_BASE=$(git merge-base HEAD origin/main)
echo "merge-base=$MERGE_BASE" >> $GITHUB_OUTPUT
- uses: step-security/changed-files@v46
id: changed-files
with:
json: true
matrix: true
base_sha: ${{ steps.merge-base.outputs.merge-base }}
dir_names: true
dir_names_max_depth: 2
files: |
sub-packages/**
.github/workflows/unit-tests-framework.yml
- name: Show output
run: |
echo '${{ toJSON(steps.changed-files.outputs) }}'
shell: bash
- name: Compute test matrix from changed files
id: matrix
env:
CHANGED_JSON: ${{ steps.changed-files.outputs.all_changed_files }}
ANY_CHANGED: ${{ steps.changed-files.outputs.any_changed }}
IS_SCHEDULE: ${{ github.event_name == 'schedule' }}
run: |
python3 - <<'PY'
import json, os, tomllib
# --- Parse tach.toml for the dependency graph ---
with open("tach.toml", "rb") as f:
tach = tomllib.load(f)
# Map each module to its sub-package by checking which source root
# actually contains the module directory on disk.
mod_to_pkg = {}
for mod in tach.get("modules", []):
mod_dir = mod["path"].replace(".", "/")
for sr in tach.get("source_roots", []):
parts = sr.split("/")
if len(parts) >= 2 and parts[0] == "sub-packages" and os.path.isdir(os.path.join(sr, mod_dir)):
mod_to_pkg[mod["path"]] = parts[1]
break
# Build the package dependency dict from tach modules.
packages = {}
for mod in tach.get("modules", []):
pkg = mod_to_pkg.get(mod["path"])
if pkg is None:
continue
deps = []
for dep_mod in mod.get("depends_on", []):
dep_pkg = mod_to_pkg.get(dep_mod)
if dep_pkg and dep_pkg != pkg:
deps.append(dep_pkg)
packages[pkg] = sorted(set(deps))
print(f"Packages from tach.toml: { {k: v for k, v in sorted(packages.items())} }")
# --- Determine which packages changed ---
raw = (os.environ.get("CHANGED_JSON") or "").strip()
if raw:
try:
changed = json.loads(raw)
except json.JSONDecodeError:
changed = json.loads(raw.replace('\\"', '"'))
else:
changed = []
any_changed = os.environ.get("ANY_CHANGED", "false") == "true"
is_schedule = os.environ.get("IS_SCHEDULE", "false") == "true"
# Reverse dependency map: package -> downstream dependents.
reverse_deps = {name: [] for name in packages}
for name, deps in packages.items():
for dep in deps:
reverse_deps.setdefault(dep, []).append(name)
if is_schedule:
to_test = set(packages.keys())
elif any_changed:
infra_changed = any(not c.startswith("sub-packages/") for c in changed)
if infra_changed:
to_test = set(packages.keys())
else:
directly_changed = set()
for c in changed:
parts = c.split("/")
if len(parts) >= 2 and parts[0] == "sub-packages":
pkg = parts[1]
if pkg in packages:
directly_changed.add(pkg)
to_test = set(directly_changed)
queue = list(directly_changed)
while queue:
pkg = queue.pop()
for rdep in reverse_deps.get(pkg, []):
if rdep not in to_test:
to_test.add(rdep)
queue.append(rdep)
else:
to_test = set()
# --- Build matrix output ---
matrix = []
for name in sorted(to_test):
matrix.append({
"name": name,
"dir": f"sub-packages/{name}",
"deps": [f"sub-packages/{d}" for d in packages[name]],
})
result = json.dumps(matrix)
with open(os.environ["GITHUB_OUTPUT"], "a") as f:
f.write(f"matrix={result}\n")
print(f"Matrix ({len(matrix)} packages): {result}")
PY
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-python@v5
with:
python-version: "3.13"
- name: Setup UV
uses: astral-sh/setup-uv@v6
with:
enable-cache: true
- run: |
uv tool install pre-commit --with pre-commit-uv --force-reinstall
uv tool install tach>=0.9.0
uv tool update-shell
- run: ./ci/scripts/static_checks.sh
get-pr-labels:
runs-on: ubuntu-latest
outputs:
labels: ${{ steps.get-labels.outputs.labels || steps.get-labels-empty.outputs.labels }}
steps:
- name: Get PR number from branch
if: startsWith(github.ref, 'refs/heads/pull-request/')
id: get-pr-num
run: |
PR_NUM=$(echo ${{ github.ref_name }} | grep -oE '[0-9]+$')
echo "pr_num=$PR_NUM" >> $GITHUB_OUTPUT
- name: Get PR labels
id: get-labels
if: startsWith(github.ref, 'refs/heads/pull-request/')
env:
GH_TOKEN: ${{ github.token }}
run: |
LABELS=$(gh api repos/${{ github.repository }}/pulls/${{ steps.get-pr-num.outputs.pr_num }} --jq '[.labels[].name]' || echo "[]")
echo "labels=$LABELS" >> $GITHUB_OUTPUT
- name: Set empty labels for non-PR branches
if: ${{ !startsWith(github.ref, 'refs/heads/pull-request/') }}
id: get-labels-empty
run: |
echo "labels=[]" >> $GITHUB_OUTPUT
run-tests:
needs:
- pre-commit
- changed-files
- get-pr-labels
runs-on: linux-amd64-gpu-l4-latest-1
if: |
(github.event_name == 'schedule') ||
contains(fromJSON(needs.get-pr-labels.outputs.labels || '[]'), 'ciflow:all') ||
(
!contains(fromJSON(needs.get-pr-labels.outputs.labels || '[]'), 'ciflow:skip') &&
(needs.changed-files.outputs.any_changed == 'true')
)
name: "unit-tests (${{ matrix.pkg.name }})"
container:
image: svcbionemo023/bionemo-framework:pytorch26.04-py3-squashed
options: --shm-size=16G
env:
CI: true
HF_TOKEN: ${{ secrets.HF_TOKEN }}
HF_HOME: /cache/huggingface
BIONEMO_DATA_SOURCE: ngc
strategy:
matrix:
pkg: ${{ fromJson(needs.changed-files.outputs.matrix) }}
fail-fast: false
steps:
- name: Show GPU info
run: nvidia-smi
- name: Setup proxy cache
uses: nv-gha-runners/setup-proxy-cache@main
- name: Checkout repository
uses: actions/checkout@v4
with:
sparse-checkout: |
sub-packages
LICENSE
sparse-checkout-cone-mode: true
- name: Install dependencies and package
working-directory: ${{ matrix.pkg.dir }}
env:
DEPS: ${{ toJson(matrix.pkg.deps) }}
run: |
# Install internal dependencies from local checkout first.
for dep in $(echo "$DEPS" | jq -r '.[]'); do
PIP_CONSTRAINT= pip install -e "../../$dep"
done
# Install the target sub-package.
if [ -f .ci_build.sh ]; then
bash .ci_build.sh
else
PIP_CONSTRAINT= pip install -e .
fi
# Install test dependencies if declared.
PIP_CONSTRAINT= pip install pytest pytest-cov pytest-timeout || true
PIP_CONSTRAINT= pip install -e ".[test]" 2>/dev/null || true
- name: Run tests
working-directory: ${{ matrix.pkg.dir }}
run: |
pytest -v \
--cov=bionemo \
--cov-report=xml:coverage.xml \
--junitxml=results.junit.xml \
-o junit_family=legacy \
.
- name: Upload coverage to Codecov
if: github.event_name != 'merge_group' && github.event_name != 'schedule'
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
flags: ${{ matrix.pkg.name }}
files: coverage.xml
- name: Upload test results to Codecov
if: ${{ !cancelled() && github.event_name != 'merge_group' && github.event_name != 'schedule' }}
uses: codecov/test-results-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
flags: ${{ matrix.pkg.name }}
files: results.junit.xml
run-tests-slow:
needs:
- pre-commit
- changed-files
- get-pr-labels
runs-on: linux-amd64-gpu-l4-latest-1
if: |
(
(github.event_name == 'schedule') ||
contains(fromJSON(needs.get-pr-labels.outputs.labels || '[]'), 'ciflow:all') ||
(
!contains(fromJSON(needs.get-pr-labels.outputs.labels || '[]'), 'ciflow:skip') &&
(needs.changed-files.outputs.any_changed == 'true')
)
) &&
(
(github.event_name == 'schedule') ||
(github.event_name == 'merge_group') ||
contains(fromJSON(needs.get-pr-labels.outputs.labels || '[]'), 'ciflow:all') ||
contains(fromJSON(needs.get-pr-labels.outputs.labels || '[]'), 'ciflow:slow')
)
name: "slow-tests (${{ matrix.pkg.name }})"
container:
image: svcbionemo023/bionemo-framework:pytorch26.04-py3-squashed
options: --shm-size=16G
env:
CI: true
HF_TOKEN: ${{ secrets.HF_TOKEN }}
HF_HOME: /cache/huggingface
BIONEMO_DATA_SOURCE: ngc
strategy:
matrix:
pkg: ${{ fromJson(needs.changed-files.outputs.matrix) }}
fail-fast: false
steps:
- name: Show GPU info
run: nvidia-smi
- name: Setup proxy cache
uses: nv-gha-runners/setup-proxy-cache@main
- name: Checkout repository
uses: actions/checkout@v4
with:
sparse-checkout: |
sub-packages
LICENSE
sparse-checkout-cone-mode: true
- name: Install dependencies and package
working-directory: ${{ matrix.pkg.dir }}
env:
DEPS: ${{ toJson(matrix.pkg.deps) }}
run: |
for dep in $(echo "$DEPS" | jq -r '.[]'); do
PIP_CONSTRAINT= pip install -e "../../$dep"
done
if [ -f .ci_build.sh ]; then
bash .ci_build.sh
else
PIP_CONSTRAINT= pip install -e .
fi
PIP_CONSTRAINT= pip install pytest pytest-cov pytest-timeout || true
PIP_CONSTRAINT= pip install -e ".[test]" 2>/dev/null || true
- name: Run slow tests
working-directory: ${{ matrix.pkg.dir }}
run: |
pytest -v -m slow \
--junitxml=results-slow.junit.xml \
-o junit_family=legacy \
. || test $? -eq 5 # exit 5 = no tests collected, which is OK
run-tests-notebooks:
needs:
- pre-commit
- changed-files
- get-pr-labels
runs-on: linux-amd64-gpu-l4-latest-1
if: |
(
(github.event_name == 'schedule') ||
contains(fromJSON(needs.get-pr-labels.outputs.labels || '[]'), 'ciflow:all') ||
(
!contains(fromJSON(needs.get-pr-labels.outputs.labels || '[]'), 'ciflow:skip') &&
(needs.changed-files.outputs.any_changed == 'true')
)
) &&
(
(github.event_name == 'schedule') ||
(github.event_name == 'merge_group') ||
contains(fromJSON(needs.get-pr-labels.outputs.labels || '[]'), 'ciflow:all') ||
contains(fromJSON(needs.get-pr-labels.outputs.labels || '[]'), 'ciflow:notebooks')
)
name: "notebook-tests (${{ matrix.pkg.name }})"
container:
image: svcbionemo023/bionemo-framework:pytorch26.04-py3-squashed
options: --shm-size=16G
env:
CI: true
HF_TOKEN: ${{ secrets.HF_TOKEN }}
HF_HOME: /cache/huggingface
BIONEMO_DATA_SOURCE: ngc
strategy:
matrix:
pkg: ${{ fromJson(needs.changed-files.outputs.matrix) }}
fail-fast: false
steps:
- name: Show GPU info
run: nvidia-smi
- name: Setup proxy cache
uses: nv-gha-runners/setup-proxy-cache@main
- name: Checkout repository
uses: actions/checkout@v4
with:
sparse-checkout: |
sub-packages
LICENSE
sparse-checkout-cone-mode: true
- name: Install dependencies and package
working-directory: ${{ matrix.pkg.dir }}
env:
DEPS: ${{ toJson(matrix.pkg.deps) }}
run: |
for dep in $(echo "$DEPS" | jq -r '.[]'); do
PIP_CONSTRAINT= pip install -e "../../$dep"
done
if [ -f .ci_build.sh ]; then
bash .ci_build.sh
else
PIP_CONSTRAINT= pip install -e .
fi
PIP_CONSTRAINT= pip install nbval testbook || true
PIP_CONSTRAINT= pip install -e ".[test]" 2>/dev/null || true
- name: Run notebook tests
working-directory: ${{ matrix.pkg.dir }}
run: |
FAST_CI_MODE=true pytest -v --nbval-lax -x -p no:python . \
|| test $? -eq 5 # exit 5 = no notebooks found, which is OK
verify-tests-status:
needs:
- pre-commit
- changed-files
- get-pr-labels
- run-tests
- run-tests-slow
- run-tests-notebooks
runs-on: ubuntu-latest
if: always()
steps:
- name: Check test job statuses
run: |
if [[ "${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }}" == "true" ]]; then
echo "Some test jobs have failed or been cancelled!"
exit 1
else
echo "All test jobs have completed successfully or been skipped!"
exit 0
fi