{{=[[ ]]=}}
on:
  pull_request:
    branches:
      - master
      - development
  push:
    branches:
      - master
      - development
    paths:
      - [[name]].Rmd
      - [[name]].R

name: Render module Rmd

jobs:
  render:
    name: Render module Rmd
    runs-on: macOS-latest
    steps:
      - uses: actions/checkout@v2
      - uses: r-lib/actions/setup-r@v1
      - uses: r-lib/actions/setup-pandoc@v1
      - name: Install devtools, knitr and rmarkdown
        run: Rscript -e 'install.packages(c("devtools", "knitr", "rmarkdown"))'
      - name: Install SpaDES
        run: |
          Rscript -e 'devtools::install_github("PredictiveEcology/reproducible@development")'
          Rscript -e 'devtools::install_github("PredictiveEcology/SpaDES.core@development", dependencies = TRUE)'
          Rscript -e 'devtools::install_github("PredictiveEcology/SpaDES.tools@development", dependencies = TRUE)'
      - name: Install module package dependencies
        run: Rscript -e 'pkgs <- SpaDES.core::packages(modules = "[[name]]", paths = "..")[[1]]; reproducible::Require(pkgs)'
      - name: Render module Rmd
        run: Rscript -e 'rmarkdown::render("[[name]].Rmd", encoding = "UTF-8")'
      - name: Commit results
        run: |
          git commit [[name]].html -m 'Re-build [[name]].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"
