Skip to content

New script called refactor_testing_query_courseid.py #11

New script called refactor_testing_query_courseid.py

New script called refactor_testing_query_courseid.py #11

name: Execute Jupyter Notebooks With Changes
on:
workflow_dispatch:
pull_request:
branches:
- main
paths:
- '**.ipynb'
jobs:
test-changed-notebooks:
runs-on: ubuntu-latest
container:
image: us-central1-docker.pkg.dev/ucb-datahub-2018/user-images/data100-user-image@sha256:a5ac1fd44d1a978b5d19c07996db87fd3e7e3291644c5d448d0d68450763a4db
options: --user root
credentials:
username: _json_key
password: ${{ secrets.GCP_SERVICE_ACCOUNT_KEY }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Get changed files
id: changed-files-git
run: |
cd ${GITHUB_WORKSPACE}
ls -a
chown -R root .
git status || true
# Captures changed Jupyter notebooks between the last commit and the previous one
CHANGED_NOTEBOOKS=$(git diff --name-only HEAD^ || true)
echo "changed_files=${CHANGED_NOTEBOOKS}" >> $GITHUB_OUTPUT
- name: Execute changed notebooks
if: steps.changed-files-git.outputs.changed_files
run: |
echo "Changed Notebooks: ${CHANGED_NOTEBOOKS}"
for file in $CHANGED_NOTEBOOKS; do
if [[ $file == *.ipynb ]]; then
echo "Executing notebook: $file"
jupyter nbconvert --to notebook --execute --inplace "$file" || echo "FAILED: ${file}"
fi
done
- name: Check for errors
run: |
for file in $CHANGED_NOTEBOOKS; do
if [[ $file == *.ipynb && -f "$file" ]]; then
if grep -q "Execution failed" "$file"; then
echo "Notebook execution failed: $file"
exit 1
fi
fi
done