Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[setup-r-dependencies]: install quarto if needed #895

Merged
merged 9 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Package: testpackage
Title: A Simple Test Description File to Test Packages
Version: 1.0.0
Authors@R:
Authors@R:
c(person(given = "Jim",
family = "Hester",
role = c("aut", "cre"),
email = "[email protected]"))
Description: This is a simple package used to test the workflow files.
Imports: xml2, curl
Suggests: covr, knitr, rmarkdown, testthat
Suggests: covr, knitr, rmarkdown, testthat, quarto
License: GPL (>= 2)
VignetteBuilder: knitr, rmarkdown
VignetteBuilder: knitr, rmarkdown, quarto
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
unchanged, on all R versions. To avoid using a P3M snapshot on R 3.6.x,
set the `RSPM_PIN_3_6` environment variable to `false`.

* `[setup-r-dependencies]` now automatically installs Quarto if the repo
has a qmd file, and it isn't installed. See the `install-quarto` and
`quarto-version` input parameters (#866).

* `[setup-r]` now avoids spurious warnings from Homebrew (#864).

* `[setup-r-dependencies]` now accepts `pak-version: none` to skip pak
Expand Down
2 changes: 2 additions & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
template:
bootstrap: 5
16 changes: 12 additions & 4 deletions setup-r-dependencies/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ Inputs available
- `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.
if it is not already on the PATH and the R package depends on rmarkdown.
- `install-quarto` - Whether to install quarto. If it is 'auto' (the
default), it is installed if there is at least one `.qmd` file in the
repository, inside `working-directory`. Set to 'true' to always install
it. Set to 'false' to never install it.
- `needs` - `Config/Needs` fields to install from the DESCRIPTION, the
`Config/Needs/` prefix will be automatically included.
- `lockfile-create-lib` - The package library to consider when creating
Expand All @@ -44,11 +48,15 @@ Inputs available
install. The default installs the dependencies of the package in the
working directory and the sessioninfo package. Separate multiple packages
by newlines or commas.
- `pak-version`: Which pak version to use. Possible values are
- `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
- `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
- `quarto-version` - Version of quarto to install, if quarto is installed.
It is passed to the `quarto-dev/quarto-actions/setup@v2` action. The
default is 'release' to install the latest release. Other possible values
are a version number number (without the `v` prefix), and 'pre-release'.
- `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`.
- `working-directory` - default `'.'`. If the DESCRIPTION file is not in the
Expand Down
51 changes: 51 additions & 0 deletions setup-r-dependencies/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ s.'
pandoc-version:
description: 'Pandoc version to install.'
default: '3.1.11'
install-quarto:
description: |
Whether to install quarto. If it is 'auto' (the default), it is
installed if there is at least one `.qmd` file in the repository,
inside `working-directory`. Set to 'true' to always install it.
Set to 'false' to never install it.
default: 'auto'
quarto-version:
description: |
Version of quarto to install, if quarto is installed. It is passed
to the `quarto-dev/quarto-actions/setup@v2` action. The default is
'release' to install the latest release. Other possible values are
a version number number (without the `v` prefix), and 'pre-release'.
default: 'release'
runs:
using: "composite"
steps:
Expand Down Expand Up @@ -156,20 +170,25 @@ runs:
- name: Check whether pandoc needs to be installed
id: check-pandoc
run: |
# Pandoc check
cat("::group::Check if package needs pandoc\n")
o <- '${{ inputs.install-pandoc }}'
if (! o %in% c('true', 'false')) {
if (Sys.which("pandoc") != "") {
cat("Pandoc is already installed at", Sys.which("pandoc"), "\n")
o <- 'false'
} else if (file.exists("DESCRIPTION")) {
deptypes <- list(direct = "all", indirect = character())
deps <- pak::pkg_deps(".", dependencies = deptypes)
if ("rmarkdown" %in% deps$package) {
cat("Pandoc is needed for rmarkdown\n")
o <- 'true'
} else {
cat("Pandoc is not needed\n")
o <- 'false'
}
} else {
cat("Pandoc is not needed, no R package found\n")
o <- 'false'
}
}
Expand All @@ -184,6 +203,38 @@ runs:
with:
pandoc-version: ${{ inputs.pandoc-version }}

- name: Check whether quarto if needed
id: check-quarto
run: |
# Quarto check
cat("::group::Check if package needs quarto\n")
o <- '${{ inputs.install-quarto }}'
if (! o %in% c('true', 'false')) {
if (Sys.which("quarto") != "") {
cat("Quarto is already installed at", Sys.which("quarto"), "\n")
o <- "false"
} else {
qmd <- dir(recursive = TRUE, pattern = "[.]qmd$")
if (length(qmd) > 0) {
cat("Quarto is needed for qmd file(s):", qmd[1], "...\n")
o <- "true"
} else {
cat("No qmd files found, Quarto is not needed.\n")
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 quarto if needed
if: ${{ steps.check-quarto.outputs.install == 'true' }}
uses: quarto-dev/quarto-actions/setup@v2
with:
version: ${{ inputs.quarto-version }}

- name: Session info
run: |
# Session info
Expand Down
19 changes: 19 additions & 0 deletions vignettes/quarto-test.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
title: "Quarto HTML Vignettes"
vignette: >
%\VignetteIndexEntry{Quarto HTML Vignettes}
%\VignetteEngine{quarto::html}
%\VignetteEncoding{UTF-8}
---

## HTML Vignette Engines

The **quarto** R package registers vignette engines that can be used in `%\VignetteEngine{}` directives in vignette headers.

To learn more about how vignettes engine works, and how to write vignette engines, see the [Writing R Extensions](https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Non_002dSweave-vignettes) manual and the [R Packages (2e)](https://r-pkgs.org/vignettes.html) book.

Irure ad excepteur aliqua esse id sint ex aliquip laborum. Officia laborum ex cupidatat exercitation velit. Nisi elit incididunt nisi ullamco. Ut Lorem eiusmod anim ipsum dolore cupidatat officia non. Culpa voluptate consectetur in ullamco minim sit sunt. Ad aute laborum laborum cillum qui consequat proident sit ad incididunt. Enim nisi nulla aliquip anim fugiat deserunt aliqua aliqua sunt nisi commodo magna reprehenderit. Reprehenderit dolor sunt nulla mollit est magna exercitation dolore magna. Mollit qui labore tempor commodo veniam cupidatat esse irure nisi eiusmod qui dolore nisi.

```{r}
summary(mtcars)
```
3 changes: 1 addition & 2 deletions vignettes/test.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: "Test vignette for GH Actions"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Test vignette for GH Actopns}
%\VignetteIndexEntry{Test vignette for GH Actions}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
Expand All @@ -19,4 +19,3 @@ Irure ad excepteur aliqua esse id sint ex aliquip laborum. Officia laborum ex cu
```{r}
summary(mtcars)
```

Loading