Skip to content

Commit

Permalink
add check to only recompile notebooks that have changed
Browse files Browse the repository at this point in the history
  • Loading branch information
oneillkza committed Sep 5, 2024
1 parent fed2767 commit d21ccd9
Showing 1 changed file with 31 additions and 8 deletions.
39 changes: 31 additions & 8 deletions .github/workflows/renderNotebooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,25 @@ jobs:
push: true
tags: ${{ steps.meta_rmd.outputs.tags }}
labels: ${{ steps.meta_rmd.outputs.labels }}


- name: Run Docker container to compile changed R Markdown files
uses: addnab/docker-run-action@v3
with:
image: ${{ steps.meta_rmd.outputs.tags }}
options: -v ${{ github.workspace }}:/workspace --rm -u root
run: |
CHANGED_RMD_FILES=$(git diff --name-only HEAD^ HEAD -- '*.Rmd' '*.rmd')
if [ -n "$CHANGED_RMD_FILES" ]; then
echo "Changed R Markdown files:"
echo "$CHANGED_RMD_FILES"
for RMD in $CHANGED_RMD_FILES; do
Rscript -e 'for (f in commandArgs(TRUE)) if (file.exists(f)) rmarkdown::render(f, output_format = "all")' /workspace/$RMD
done
else
echo "No changed R Markdown files found. Skipping execution."
fi
- name: Run Docker container to compile assets
uses: addnab/docker-run-action@v3
with:
Expand Down Expand Up @@ -108,13 +126,18 @@ jobs:
with:
image: ${{ steps.meta_jupyter.outputs.tags }}
options: -v ${{ github.workspace }}:/workspace --rm -u root
run: |
notebooks=$(find /workspace -name "*.ipynb")
if [ -n "$notebooks" ]; then
find /workspace -name "*.ipynb" -exec jupyter nbconvert --to html --execute {} \;
find /workspace -name "*.ipynb" -exec jupyter nbconvert --to markdown --execute {} \;

run: |
changed_notebooks=$(git diff --name-only HEAD^ HEAD -- '*.ipynb')
if [ -n "$changed_notebooks" ]; then
echo "Changed notebooks:"
echo "$changed_notebooks"
for notebook in $changed_notebooks; do
jupyter nbconvert --to html --execute /workspace/$notebook
jupyter nbconvert --to markdown --execute /workspace/$notebook
done
else
echo "No Jupyter notebooks found. Skipping execution."
fi
echo "No changed Jupyter notebooks found. Skipping execution."
fi
- uses: stefanzweifel/git-auto-commit-action@v5

0 comments on commit d21ccd9

Please sign in to comment.