Skip to content

Commit

Permalink
GH actions for rendering of README.Rmd (#17)
Browse files Browse the repository at this point in the history
* Included render-markdown.yaml for GH actions rendering of README.Rmd. Added dummy test in .Rmd

* Update render-rmarkdown.yaml

Removed use of `renv`  through `- uses: r-lib/actions/setup-renv@v2`

* Update README.Rmd

R chunk renamed

* Improved render-rmarkdown.yaml structure

Split jobs to increase clarity. Installed R dependencies and `rmarkdown`.

* Update render-rmarkdown.yaml

Adding `name: render-rmarkdown.yaml` so it includes it in checks

* New permissions

Adding `read-all` permissions

* Removing control flow to trigger GH action

* Changing GH action trigger

* Yet another GH action trigger update

* Adding control flow

R dependencies and rendering seem to work. Action failed at Rmarkdown render files job

* Update README.Rmd

* Adding concurrency grout to  render-rmarkdown.yaml

* Ensuring render-rmarkdown.yaml doesn't fail even if .Rmd has no changes

* Revert testing example

Co-authored-by: Jackson Hoffart <[email protected]>

* Update .github/workflows/render-rmarkdown.yaml

Co-authored-by: Jackson Hoffart <[email protected]>

* Checking out PR branch

Modified checkout to PR branch in order to render README and commit to PR branch which then gets merged to main. At least that is what should happen.

* Adding fetch-dept = 0

Not having this caused `fatal: bad object ...` 
Check https://stackoverflow.com/questions/71204693/git-diff-not-working-on-github-actions-fatal-bad-object-7100c3bbc34a9667ca9034

* Update README.Rmd

Minor change to trigger GH action render of README.md

* Adding GH context refs

Added step to show GH context refs and understand where this job would be committing changes.

* Change to PR branch job

Revert to actions/checkout@v4

* PR branch job to github.ref

* Targeting github.base.ref

* typo fix

* Reverting to github.ref

* Update README.Rmd

* Typo in R chunk README.Rmd

* Adding push origin HEAD: to Commit Results job

* Update README.Rmd

* Setting correct HEAD for commit

* Update README.Rmd

* Re-build RMarkdown files

* Update README.Rmd

* Install local package through `local::.`

* Update README.Rmd

Co-authored-by: Jackson Hoffart <[email protected]>

* Re-build RMarkdown files

---------

Co-authored-by: Jackson Hoffart <[email protected]>
Co-authored-by: jibarozzo <[email protected]>
  • Loading branch information
3 people authored Dec 13, 2024
1 parent ac3d506 commit 7c7e869
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions .github/workflows/render-rmarkdown.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main]
pull_request:
release:
types: [published]
workflow_dispatch:

name: render-rmarkdown.yaml

permissions: read-all

jobs:
render-rmarkdown:
runs-on: ubuntu-latest
# Only restrict concurrency for non-PR jobs
concurrency:
group: rmarkdown-${{ github.event_name != 'pull_request' || github.run_id }}
env:
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
permissions:
contents: write

steps:
- name: Showing GH context refs
shell: bash
run: |
echo github.head_ref: ${{ github.head_ref }}
echo github.ref: ${{ github.ref }}
echo github.ref_name: ${{ github.ref_name }}
echo github.base.ref: ${{ github.base_ref }}
- name: Checkout PR branch
uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
fetch-depth: 0

- name: Setup R
uses: r-lib/actions/setup-r@v2
with:
r-version: 'latest'

- name: Setup Pandoc
uses: r-lib/actions/setup-pandoc@v2

- name: Setup R Dependencies
uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rmarkdown, local::.

- name: Render RMarkdown files
shell: bash
run: |
RMD_PATH=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep '\.Rmd$' || true)
if [ -n "$RMD_PATH" ]; then
Rscript -e 'for (f in commandArgs(TRUE)) if (file.exists(f)) rmarkdown::render(f)' ${RMD_PATH[*]}
echo "RMD_PATH=$RMD_PATH" >> $GITHUB_ENV
else
echo "No RMarkdown files changed."
fi
- name: Commit Results
shell: bash
run: |
if [ -n "$RMD_PATH" ]; then
MD_FILES=$(echo "$RMD_PATH" | sed 's/\.Rmd$/\.md/')
git config --local user.name "$GITHUB_ACTOR"
git config --local user.email "[email protected]"
git add $MD_FILES
git commit -m 'Re-build RMarkdown files' || echo "Re-build changes to commit"
git push origin HEAD:${{ github.head_ref }} || echo "Changes pushed to ${{ github.head_ref }} to commit"
else
echo "No Markdown files to commit."
fi

0 comments on commit 7c7e869

Please sign in to comment.