Add github action to knit Rmd #12
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: Knit Rmd Files | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
workflow_dispatch: | |
jobs: | |
knit: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
pull-requests: write | |
steps: | |
- name: Setup pandoc | |
uses: r-lib/actions/setup-pandoc@v2 | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
# Only pull current branch, not the merge outcome so that we can commit the output | |
with: | |
ref: ${{ github.head_ref || github.ref_name }} | |
fetch-depth: 0 | |
- name: Set up R | |
uses: r-lib/actions/setup-r@v2 | |
- name: Setup Renv | |
uses: r-lib/actions/setup-renv@v2 | |
env: | |
GITHUB_PAT: ${{ secrets.READ_OMOPCEPT_PAT }} | |
- name: Tmp install omopcept in rmd # doesnt install on local because of arrow error | |
run: | | |
Rscript -e ' | |
remotes::install_github("SAFEHR-data/omopcept") | |
renv::snapshot() | |
' | |
env: | |
GITHUB_PAT: ${{ secrets.READ_OMOPCEPT_PAT }} | |
- name: Find and knit Rmd files | |
run: | | |
Rscript -e ' | |
rmd_files <- list.files(pattern = "\\.Rmd$", recursive = TRUE) | |
for (file in rmd_files) { | |
rmarkdown::render(file) | |
} | |
' | |
- name: Commit changes | |
run: | | |
git config --global user.name "github-actions[bot]" | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
git add -A | |
git commit -m "Knit Rmd files" || echo "No changes to commit" | |
- name: Push changes | |
uses: ad-m/[email protected] | |
with: | |
branch: ${{ github.head_ref || github.ref_name }} |