Skip to content

Commit

Permalink
update strip action
Browse files Browse the repository at this point in the history
  • Loading branch information
vsyrgkanis committed Jul 22, 2024
1 parent 46f2319 commit d01e773
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 35 deletions.
53 changes: 25 additions & 28 deletions .github/workflows/check-and-transform-R-notebooks.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
name: Check and Transform R Notebooks
name: Check R Notebooks

on:
push:
branches:
- main
pull_request:
branches:
- main
Expand Down Expand Up @@ -203,27 +200,27 @@ jobs:
rm -rf r_scripts
rm ${{ matrix.directory }}_r_scripts.zip
- name: Check out the branch for pull request
if: "(github.event_name == 'pull_request') && (env.notebooks_changed == 'true')"
run: |
git fetch --all
git checkout ${{ github.event.pull_request.head.ref }}
- name: Check if there are any changes
if: env.notebooks_changed == 'true'
id: verify_diff
run: |
git pull
git diff --quiet ${{ matrix.directory }}/*.irnb ${{ matrix.directory }}/*.Rmd || echo "changed=true" >> $GITHUB_OUTPUT
- name: Commit and push stripped .irnb and .Rmd files
if: "(env.notebooks_changed == 'true') && (steps.verify_diff.outputs.changed == 'true')"
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git pull
git add ${{ matrix.directory }}/*.irnb ${{ matrix.directory }}/*.Rmd
git commit -m 'Strip outputs from .irnb, convert to .Rmd, lint .Rmd files, and execute .R files in ${{ matrix.directory }} [skip ci]'
git push --force-with-lease
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# - name: Check out the branch for pull request
# if: "(github.event_name == 'pull_request') && (env.notebooks_changed == 'true')"
# run: |
# git fetch --all
# git checkout ${{ github.event.pull_request.head.ref }}

# - name: Check if there are any changes
# if: env.notebooks_changed == 'true'
# id: verify_diff
# run: |
# git pull
# git diff --quiet ${{ matrix.directory }}/*.irnb ${{ matrix.directory }}/*.Rmd || echo "changed=true" >> $GITHUB_OUTPUT

# - name: Commit and push stripped .irnb and .Rmd files
# if: "(env.notebooks_changed == 'true') && (steps.verify_diff.outputs.changed == 'true')"
# run: |
# git config --global user.name 'github-actions[bot]'
# git config --global user.email 'github-actions[bot]@users.noreply.github.com'
# git pull
# git add ${{ matrix.directory }}/*.irnb ${{ matrix.directory }}/*.Rmd
# git commit -m 'Strip outputs from .irnb, convert to .Rmd, lint .Rmd files, and execute .R files in ${{ matrix.directory }} [skip ci]'
# git push --force-with-lease
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
12 changes: 6 additions & 6 deletions .github/workflows/strip-python-notebooks.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
name: Strip Python and R Notebooks from Outputs
name: Strip Python and R Notebooks from Outputs and Transform .irnb to .Rmd

on:
push:

concurrency:
group: strip-notebooks-${{ github.ref }}
group: strip-transform-notebooks-${{ github.ref }}
cancel-in-progress: true

jobs:
strip-notebooks:
strip-transform-notebooks:
runs-on: ubuntu-latest

steps:
Expand Down Expand Up @@ -63,12 +63,12 @@ jobs:
fi
done
echo "Converting .irnb to .Rmd to update the .Rmd version"
R -e '
files <- list.files(path = "${{ dir }}", pattern = "\\.irnb$", full.names = TRUE, recursive = FALSE)
R -e "
files <- list.files(path = '$dir', pattern = '\\.irnb$', full.names = TRUE, recursive = FALSE)
lapply(files, function(input) {
rmarkdown::convert_ipynb(input)
})
'
"
else
echo "Directory $dir does not exist."
fi
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ pip install -r requirements.txt

# For Contributors

The .Rmd files are auto-generated by a Github Action, whenever one pushes a .irnb (R Jupyter notebook) to one of the main folders of the repo. So .Rmd files, should never be altered directly. Only changes to .irnb files should be made. Any change to a .Rmd file will be over-written by the corresponding .irnb file and will not survive the Github Action.
The .Rmd files are auto-generated by a Github Action, whenever one pushes a .irnb (R Jupyter notebook) to one of the main folders of the repo on the main branch. So .Rmd files, should never be altered directly. Only changes to .irnb files should be made. Any change to a .Rmd file will be over-written by the corresponding .irnb file and will not survive the Github Action.

Moreover, whenever a push happens to the main branch, all python and R notebooks and all R Markdown files are stripped from their outputs. It is advisable that you always strip the notebooks before pushing to the repo. You can use `nbstripout --install` on your local git directory, which does this automatically for you.

0 comments on commit d01e773

Please sign in to comment.