Update transform-R-to-Rmd.yml #5
Workflow file for this run
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: Convert and Lint R Notebooks | |
on: | |
push | |
jobs: | |
convert-lint-notebooks: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Set up Python | |
uses: actions/setup-python@v2 | |
with: | |
python-version: '3.8' # Specify your Python version here | |
- name: Install nbstripout | |
run: | | |
python -m pip install --upgrade pip | |
pip install nbstripout | |
- name: Set up R | |
uses: r-lib/actions/setup-r@v2 | |
- name: Install rmarkdown, knitr, and lintr packages | |
run: | | |
R -e 'install.packages(c("rmarkdown", "knitr", "lintr", "xfun"), repos="https://cloud.r-project.org")' | |
- name: Strip outputs from .irnb files | |
run: | | |
for notebook in PM1/*.irnb; do | |
ipynb_notebook="${notebook%.irnb}.ipynb" | |
mv "$notebook" "$ipynb_notebook" | |
nbstripout "$ipynb_notebook" | |
mv "$ipynb_notebook" "$notebook" | |
done | |
- name: Convert .irnb to .Rmd and .R | |
run: | | |
R -e ' | |
files <- list.files(path = "PM1", pattern = "\\.irnb$", full.names = TRUE, recursive = FALSE) | |
lapply(files, function(input) { | |
rmarkdown::convert_ipynb(input) | |
rmd_file <- xfun::with_ext(input, "Rmd") | |
knitr::purl(rmd_file, output = xfun::with_ext(input, "R")) | |
}) | |
' | |
- name: Lint .Rmd files | |
run: | | |
R -e ' | |
library(lintr) | |
linters <- with_defaults(line_length_linter = line_length_linter(120)) | |
rmd_files <- list.files(path = "PM1", pattern = "\\.Rmd$", full.names = TRUE) | |
lapply(rmd_files, function(file) { | |
lint(file, linters) | |
}) | |
' | |
- name: Zip .R files | |
run: | | |
mkdir r_scripts | |
mv PM1/*.R r_scripts/ | |
zip -r r_scripts.zip r_scripts | |
- name: Upload artifact | |
uses: actions/upload-artifact@v2 | |
with: | |
name: r-scripts | |
path: r_scripts.zip | |
- name: Commit and push stripped .irnb and .Rmd files | |
run: | | |
git config --global user.name 'github-actions[bot]' | |
git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
git add PM1/*.irnb PM1/*.Rmd | |
git commit -m 'Strip outputs from .irnb, convert to .Rmd, and lint .Rmd files' | |
git push | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |