From 8b976a4c60d8360aaab3cc8df8bcdd44373d84d5 Mon Sep 17 00:00:00 2001 From: koneill Date: Thu, 5 Sep 2024 13:55:09 -0700 Subject: [PATCH] separate file change step so Docker pull only happens if files changed --- .github/workflows/renderNotebooks.yaml | 75 +++++++++++++++++--------- 1 file changed, 49 insertions(+), 26 deletions(-) diff --git a/.github/workflows/renderNotebooks.yaml b/.github/workflows/renderNotebooks.yaml index 2cec687..6f3a297 100644 --- a/.github/workflows/renderNotebooks.yaml +++ b/.github/workflows/renderNotebooks.yaml @@ -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 @@ -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