Merge pull request #64 from berkeley-dsep-infra/test-nb-2 #38
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: Change directory | |
run: | | |
for file in $(find /__w/datahub-usage-analysis/datahub-usage-analysis -type f); do | |
new_path="${file/__w/github/workspace}" | |
mkdir -p "$(dirname "$new_path")" | |
mv "$file" "$new_path" | |
done | |
- 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 |