Test Jupyter Notebooks #41
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Test Jupyter Notebooks | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- main | |
paths: | |
- '**.ipynb' | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
container: | |
image: us-central1-docker.pkg.dev/ucb-datahub-2018/user-images/data100-user-image:4497642d | |
options: --user root | |
credentials: | |
username: _json_key | |
password: ${{ secrets.GCP_SERVICE_ACCOUNT_KEY }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Get changed files | |
id: changed-files | |
run: | | |
echo GITHUB_WORKSPACE: $GITHUB_WORKSPACE | |
if [ -d $GITHUB_WORKSPACE ]; then | |
cd $GITHUB_WORKSPACE | |
echo "::set-output name=workspace_dir::${GITHUB_WORKSPACE}" | |
else | |
echo GITHUB_WORKSPACE does not exist | |
echo REPO_FULL_NAME="${{ github.repository }}" | |
REPO_FULL_NAME="${{ github.repository }}" | |
echo REPO_NAME="${REPO_FULL_NAME#*/}" | |
REPO_NAME="${REPO_FULL_NAME#*/}" | |
cd /__w/${REPO_NAME}/${REPO_NAME} | |
echo "::set-output name=workspace_dir::/__w/${REPO_NAME}/${REPO_NAME}" | |
fi | |
CHANGED_FILES=$(git diff --name-only HEAD^) | |
echo "::set-output name=all_changed_files::${CHANGED_FILES}" | |
- name: Add debugging | |
run: | | |
echo "pwd: " `pwd` | |
echo "${{ steps.changed-files.outputs.all_changed_files }}" | |
echo "steps.changed-files.outputs.all_changed_files:" "${{ steps.changed-files.outputs.all_changed_files }}" | |
echo ============================ | |
echo "ls" | |
ls | |
echo ============================ | |
echo "ls ${{ steps.changed-files.outputs.workspace_dir }}" | |
ls ${{ steps.changed-files.outputs.workspace_dir }} | |
echo ============================ | |
echo "ls /__w" | |
ls /__w | |
echo ============================ | |
shell: bash | |
#- name: Get changed files | |
# id: changed-files | |
# uses: tj-actions/changed-files@v44 | |
- 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 |