-
Notifications
You must be signed in to change notification settings - Fork 8
[RHAIENG-1115] Smoke tests for notebooks #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RHAIENG-1115] Smoke tests for notebooks #20
Conversation
WalkthroughAdds a GitHub Actions workflow that validates notebooks (ensures code cells have no outputs/execution counts) and executes notebooks via Papermill with a base64-encoded external-file parameter; both jobs run on Python 3.12, register an ipykernel, and use matrix strategies. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Dev as Developer
participant GH as GitHub Actions
participant V as validate_tests
participant E as execute_tests
participant PM as Papermill
participant NB as Notebook
Dev->>GH: push / PR triggers workflow
GH->>V: start validate_tests (matrix over notebooks/files)
V->>V: checkout, setup-python 3.12, pip cache, install nbformat/ipykernel, register kernel
loop per notebook
V->>NB: load with nbformat, check validity, assert no code-cell outputs/execution counts
NB-->>V: validation result (fail on violations)
end
GH->>E: start execute_tests (matrix selects notebook + external file)
E->>E: checkout, setup-python 3.12, pip cache, install papermill/ipykernel, register kernel
E->>PM: papermill run (pass base64-encoded external file param)
PM->>NB: execute notebook with registered kernel
NB-->>PM: execution outputs/logs
PM-->>E: exit status / logs (success/failure)
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Depends on #19. |
|
@alinaryan Still WIP, but let me know if you have comments about how this is going. Tks! |
|
@shruthis4 Still WIP, but let me know if you have comments about how this is going. Tks! |
d6a578f to
d5d081a
Compare
|
Ready for review. |
d5d081a to
5b76306
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
.github/workflows/validate-and-execute-notebooks.yml(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: execute_tests (notebooks/use-cases/document-conversion-standard.ipynb, https://raw.githubusercont...
6bc5f85 to
abe1ade
Compare
|
|
||
| # Check if the notebook has any code cells with outputs or execution counts | ||
| for cell in n.cells: | ||
| if cell.cell_type == 'code': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also add s check to ensure that the notebook has atleast one parameter tag. This will make the notebook testable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added!
| set -ux | ||
|
|
||
| NOTEBOOK="${{ matrix.notebook_to_execute }}" | ||
| FILE="${{ matrix.file_to_use }}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great to have something in CI to validate notebook. As a long term solution, I plan to create pytests and call them from workflows. This will lets us scale and maintain as the repo grows.
| fi | ||
| done | ||
|
|
||
| execute_tests: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we run execute only if validate_tests pass? To do so
execute_tests:
needs: validate_tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, changed.
abe1ade to
0bbfd2e
Compare
|
@shruthis4 thanks for the review, comments addressed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
|
Forgot to ask, can you also add the workflow run to the PR? |
Signed-off-by: Fabiano Franz <[email protected]>
Signed-off-by: Fabiano Franz <[email protected]>
0bbfd2e to
7b1f2a1
Compare
| for cell in n.cells: | ||
| if cell.cell_type == 'code': | ||
|
|
||
| # Fail test if notebook has any code cell with outputs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For these checks here, I wonder if it would be cleaner to use https://pypi.org/project/nb-clean/ instead of writing our own script to do it.
| if [ -f "$FILE" ]; then | ||
| echo "Validating notebook '$FILE'..." | ||
|
|
||
| FILE="$FILE" python - <<'PY' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a fan of having a python script in line within the action. As follow up work could we split this out into it's own file. I really like the nbformat.validate() check here.
Description
Basic GitHub actions with smoke tests for notebooks. It performs basic validation with
nbformat'svalidateon all notebooks innotebooks/**/*.ipynband does a full run (with default settings) of selected notebooks usingpapermill.How Has This Been Tested?
Tested using act CLI:
Workflow run:
https://github.com/opendatahub-io/odh-data-processing/actions/runs/18574482508?pr=20
Merge criteria:
Summary by CodeRabbit
Tests
Chores