GH actions for rendering of README.Rmd #24
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
# 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 | |
- 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 |