Github action to render documents using rmarkdown. Uses rocker/r-rmd
docker image which includes rmardkown, pandoc and latex.
input_file
: path or name of input file, all with respect to root directory of the repo (e.g:my_doc.Rmd
,path/to/my_doc.Rmd
)output_format
: (defaults topdf_document
), options are:word_document
,html_document
andpdf_document
.
output_file
: This is automatically generated as the name that precedes.Rmd
+ the output format extension (e.g: formy_doc.Rmd
withoutput_format
aspdf_document
->my_doc.pdf
Disclaimer: By default, the rmarkdown-action
will simply render the document to desired format. If you also wish to upload the document back to the repo please see the later section
name: Render documents with rmarkdown-action
on: [push]
jobs:
render_document:
runs-on: ubuntu-latest
steps:
- name: Set up Git repository
uses: actions/checkout@v2
- name: Render document
uses: lc5415/rmarkdown-action@v1
with:
input_file: path/to/my_doc.Rmd
output_format: pdf_document
This makes use of the github-push-action to automatically upload the rendered document to the branch that trigerred the rmarkdown-action. This is useful when the quality of the rendering needs to be reviewed as well (which is almost always the case).
By default, the rendered document will be uploaded to the same location that the input file. If you want to be able to specify the output location please submit an issue.
name: Render documents and upload
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
render_document:
runs-on: ubuntu-latest
steps:
- name: Set up Git repository
uses: actions/checkout@v2
- name: Render document
uses: lc5415/rmarkdown-action@v1
with:
input_file: path/to/my_doc.Rmd
output_format: pdf_document
- name: Commit files
run: |
git config --local core.autocrlf false
git config --local user.email "${{ github.actor }}@users.noreply.github.com"
git config --local user.name "${{ github.actor }}"
git add . && git add --renormalize .
git pull origin ${{ github.head_ref }} --autostash --rebase -X ours
git commit --allow-empty -am "AUTO-GH ACTION: ${{ github.workflow }}"
NO_PAGER=1 git --no-pager diff HEAD^
- name: Push changes
uses: ad-m/github-push-action@master
with:
branch: ${{ github.head_ref }}
github_token: ${{ secrets.GITHUB_TOKEN }}