Skip to content

Commit

Permalink
[setup-r-dependencies]: install pandoc if needed
Browse files Browse the repository at this point in the history
Automatically, but provide a way to opt in and opt out.
  • Loading branch information
gaborcsardi committed Feb 27, 2024
1 parent 134c6d5 commit 890cb24
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
4 changes: 4 additions & 0 deletions setup-r-dependencies/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ Inputs available
Note that you often need to quote it, see details below.
- `extra-packages` - One or more extra package references to install.
Separate each reference by newlines or commas for more than one package.
- `install-pandoc` - Whether to install pandoc. By default it is installed
if it is not already on the PATH and the R package depends in rmarkdown.
- `needs` - `Config/Needs` fields to install from the DESCRIPTION, the
`Config/Needs/` prefix will be automatically included.
- `packages`: - default `deps::., any::sessioninfo`. Which package(s) to
Expand All @@ -35,6 +37,8 @@ Inputs available
by newlines or commas.
- `pak-version`: Which pak version to use. Possible values are
`stable`, `rc` and `devel`. Defaults to `stable`.
- `pandoc-version`: Which pandoc version to install (see the
`r-lib/actions/setup-pandoc` action), if pandoc is installed.
- `upgrade`: Whether to install the latest available versions of the
dependencies. Must be an R expression. See the README for details if
you need quoting. Defaults to `FALSE`.
Expand Down
36 changes: 36 additions & 0 deletions setup-r-dependencies/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ inputs:
upgrade:
description: 'Whether to install the latest available versions of the dependencies. Must be an R expression. See the README for details if you need quoting.'
default: 'FALSE'
install-pandoc:
description: 'Whether to install pandoc. By default it is installed if it is not on the PATH and the local package suggests or depends on the rmarkdown package.'
pandoc-version:
description: 'Pandoc version to install.'
default: '3.1.11'
runs:
using: "composite"
steps:
Expand Down Expand Up @@ -121,6 +126,37 @@ runs:
key: ${{ format('{0}-{1}-{2}-{3}', steps.install.outputs.os-version, steps.install.outputs.r-version, inputs.cache-version, hashFiles(format('{0}/.github/pkg.lock', inputs.working-directory ))) }}
restore-keys: ${{ steps.install.outputs.os-version }}-${{ steps.install.outputs.r-version }}-${{inputs.cache-version }}-

- name: Check whether pandoc needs to be installed
id: check-pandoc
run: |
cat("::group::Check if package needs pandoc\n")
o <- '${{ inputs.install-pandoc }}'
if (! o %in% c('true', 'false')) {
if (Sys.which("pandoc") != "") {
o <- 'false'
} else if (file.exists("DESCRIPTION")) {
deptypes <- list(direct = "all", indirect = character())
deps <- pak::pkg_deps(".", dependencies = deptypes)
if ("rmarkdown" %in% deps$package) {
o <- 'true'
} else {
o <- 'false'
}
} else {
o <- 'false'
}
}
cat("install=", o, "\n", file = Sys.getenv("GITHUB_OUTPUT"), sep = "", append = TRUE)
cat("::endgroup::\n")
shell: Rscript {0}
working-directory: ${{ inputs.working-directory }}

- name: Install pandoc if needed
if: ${{ steps.check-pandoc.outputs.install }}
uses: r-lib/actions/setup-pandoc@v2
with:
pandoc-version: ${{ inputs.pandoc-version }}

- name: Install dependencies
run: |
# Install/Update packages
Expand Down

0 comments on commit 890cb24

Please sign in to comment.