Trouble using the render-readme GH Action

I have been trying to use the render-readme.yaml GitHub Action file from https://github.com/r-lib/actions, suitably modified to suit the setting of rendering a README.md from README.Rmd in the root of a Github repo. The workflow I am using is here: https://github.com/gavinsimpson/gratia/blob/master/.github/workflows/render-readme.yaml (and below)

I've tried to reconcile difference between the example from r-lib and the other workflow files they have their, and to install the package(s) needed to render the README.md. I am having trouble even getting the workflow to show up in the Actions tab for the package repo. An older attempt got it to show up but under a weird name,

Can anyone see what I'm doing wrong or point me to a repo with a working example of using a GH Action workflow to render a README.md from README.Rmd?

on:
  push:
    paths:
      - README.Rmd

name: render-readme

jobs:
  render-readme:
    runs-on: macOS-latest
    steps:
      - uses: actions/checkout@v2
      
      - uses: r-lib/actions/setup-r@master
      
      - uses: r-lib/actions/setup-pandoc@master
      
      - name: Install rmarkdown
        run: Rscript -e 'install.packages("rmarkdown")'

      - name: Install required packages
        run: Rscript -e 'install.packages("gratia")'

      - name: Render README
        run: Rscript -e 'rmarkdown::render("README.Rmd")'

      - name: Commit results
        run: |
          git config --local user.email "action@github.com"
          git config --local user.name "GitHub Action"
          git commit README.md -m 'Re-build README.Rmd' || echo "No changes to commit"
          git push https://${{github.actor}}:${{secrets.GITHUB_TOKEN}}@github.com/${{github.repository}}.git HEAD:${{ github.ref }} || echo "No changes to commit"

There is a slightly tweaked example in the workflow for that repo

Thanks @jimhester. I am trying this or a modified version now.

In investigating why the workflow isn't showing up, I came across a solution to another issue in the GitHub Community site where it was stated that a workflow has to be triggered before it will show up in the Actions tab. Changing the on: part to trigger on any push to my master branch triggered the workflow and the workflow showed up in the list.

I'm not sure that the current behaviour of the workflow is the correct one for rendering a README.Rmd, certainly not in my use case. I can see the logic of triggering the workflow only when README.Rmd is included in a commit pushed to a repo. However, if the README.Rmd is unchanged but the code it runs has changed due to other commits, unless one needlessly edits and pushes the README.Rmd the workflow won't trigger and the README.md won't get updated. In my use case I may change the code in the package that is called in the README.Rmd and I want that to be reflected in the README.md even if I don't edit README.Rmd.

Might be worth adding a comment to the .yaml indicating that this workflow will only trigger if README.Rmd is part of a commit/push. And suggest an alternative on: if the user wants to rebuild the README.Rmd on every push.?

1 Like