From 7c7e869b2f1c8c79a63fed7706602a8cf5d6d048 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bol=C3=ADvar=20Aponte=20Rol=C3=B3n?= <64099468+jibarozzo@users.noreply.github.com> Date: Fri, 13 Dec 2024 11:26:06 -0600 Subject: [PATCH] GH actions for rendering of README.Rmd (#17) * 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 * Update .github/workflows/render-rmarkdown.yaml Co-authored-by: Jackson Hoffart * 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 * Re-build RMarkdown files --------- Co-authored-by: Jackson Hoffart Co-authored-by: jibarozzo --- .github/workflows/render-rmarkdown.yaml | 78 +++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 .github/workflows/render-rmarkdown.yaml diff --git a/.github/workflows/render-rmarkdown.yaml b/.github/workflows/render-rmarkdown.yaml new file mode 100644 index 0000000..212b5e7 --- /dev/null +++ b/.github/workflows/render-rmarkdown.yaml @@ -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 "$GITHUB_ACTOR@users.noreply.github.com" + 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