Skip to content

Merge pull request #48 from berkeley-dsep-infra/test-nb-1 #26

Merge pull request #48 from berkeley-dsep-infra/test-nb-1

Merge pull request #48 from berkeley-dsep-infra/test-nb-1 #26

name: Test Jupyter Notebooks
on:
workflow_dispatch:
push:
branches:
- main
paths:
- '**.ipynb'
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Authenticate to Google Cloud
uses: google-github-actions/setup-gcloud@v2
with:
service_account_key: ${{ secrets.GCP_SERVICE_ACCOUNT_KEY }}
project_id: ucb-datahub-2018
- name: Login to GAR
uses: docker/login-action@v3
with:
registry: us-central1-docker.pkg.dev
username: _json_key
password: ${{ secrets.GCP_SERVICE_ACCOUNT_KEY }}
- name: Pull Docker image
run: docker pull us-central1-docker.pkg.dev/ucb-datahub-2018/user-images/data100-user-image:4497642d
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v44
- name: Install Jupyter
run: pip install jupyter
- name: Execute changed notebooks
run: |
for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
if [ -f "${file}" ]; then
if [[ $file == *.ipynb ]]; then
echo "Converting: '${file}'"
jupyter nbconvert --to notebook --execute --inplace "$file"
fi
else
echo "No such file: '${file}'"
fi
done
- name: Check for errors
run: |
for file in $(find . -type f -name "*.ipynb"); do
if grep -q "Execution failed" "$file"; then
echo "Notebook execution failed: $file"
exit 1
fi
done