Skip to content

Commit

Permalink
separate file change step so Docker pull only happens if files changed
Browse files Browse the repository at this point in the history
  • Loading branch information
oneillkza committed Sep 5, 2024
1 parent 7fc0ae0 commit 8b976a4
Showing 1 changed file with 49 additions and 26 deletions.
75 changes: 49 additions & 26 deletions .github/workflows/renderNotebooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,34 @@ jobs:
fi
- name: Run Docker container to compile assets
- name: Check for changed R Markdown files
id: check_rmd_files
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"
echo "::set-output name=has_changed::true"
echo "$CHANGED_RMD_FILES" > changed_rmd_files.txt
else
echo "No changed R Markdown files found."
echo "::set-output name=has_changed::false"
- name: Run Docker container to compile changed R Markdown files
if: steps.check_rmd_files.outputs.has_changed == 'true'
uses: addnab/docker-run-action@v3
with:
image: ${{ steps.meta_rmd.outputs.tags }}
options: -v ${{ github.workspace }}:/workspace --rm -u root
options: |
-v ${{ github.workspace }}:/workspace \
-v /tmp/cache:/root/.cache \
--rm -u root
run: |
RMD_FILES=$( find /workspace -name "*Rmd" -o -name "*rmd" )
if [ -n "$RMD_FILES" ]; then
echo $RMD_FILES
for RMD in $RMD_FILES
do
Rscript -e 'for (f in commandArgs(TRUE)) if (file.exists(f)) rmarkdown::render(f, output_format = "all")' $RMD
done
else
echo "No R markdown found. Skipping execution."
fi
CHANGED_RMD_FILES=$(cat changed_rmd_files.txt)
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
- uses: stefanzweifel/git-auto-commit-action@v5

Expand Down Expand Up @@ -120,23 +132,34 @@ jobs:



- name: Run Docker container to compile JupyterNotebook
- name: Check for changed Jupyter Notebook files
id: check_ipynb_files
run: |
CHANGED_IPYNB_FILES=$(git diff --name-only HEAD^ HEAD -- '*.ipynb')
if [ -n "$CHANGED_IPYNB_FILES" ]; then
echo "Changed Jupyter Notebook files:"
echo "$CHANGED_IPYNB_FILES"
echo "::set-output name=has_changed::true"
echo "$CHANGED_IPYNB_FILES" > changed_ipynb_files.txt
else
echo "No changed Jupyter Notebook files found."
echo "::set-output name=has_changed::false"
- name: Run Docker container to compile changed Jupyter Notebooks
if: steps.check_ipynb_files.outputs.has_changed == 'true'
uses: addnab/docker-run-action@v3
with:
image: ${{ steps.meta_jupyter.outputs.tags }}
options: -v ${{ github.workspace }}:/workspace --rm -u root

options: |
-v ${{ github.workspace }}:/workspace \
-v /tmp/cache:/root/.cache \
--rm -u root
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 changed Jupyter notebooks found. Skipping execution."
fi
CHANGED_IPYNB_FILES=$(cat changed_ipynb_files.txt)
for NOTEBOOK in $CHANGED_IPYNB_FILES; do
jupyter nbconvert --to html --execute /workspace/$NOTEBOOK
jupyter nbconvert --to markdown --execute /workspace/$NOTEBOOK
done
- uses: stefanzweifel/git-auto-commit-action@v5

0 comments on commit 8b976a4

Please sign in to comment.