Skip to content

Commit ccc1cf6

Browse files
authored
Replace renv with a rig project for the R test environment
Setting up the test R environment in several worktrees at once could hang for tens of minutes: concurrent cold renv::restore() runs sharing one renv cache stalled for over 28 minutes, and every R started under tests/ paid for the renv autoloader. The tests/ R environment is now a rig project, so rig proj sync installs packages from a lock file without running R or renv's shared lock. - Replace DESCRIPTION, renv.lock and renv/ with tests/rproj.toml and tests/rproj.lock, solved for Windows, macOS arm64, Linux x86_64 and source - Point QUARTO_R at tests/.rvenv/bin in run-tests and drop the per-fixture .Rprofile that activated renv - Make configure-test-env run rig proj sync, then install dev rmarkdown and knitr into the project library - Install a pinned rig in CI and sync with --locked so a stale lock fails the job; remove the renv cache and renv::status() steps
1 parent cdcc1d5 commit ccc1cf6

37 files changed

Lines changed: 11878 additions & 7412 deletions

‎.claude/rules/testing/overview.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Run configuration script to set up:
5353
```
5454

5555
Managed via:
56-
- **R**: renv (`renv.lock`)
56+
- **R**: rig project (`rproj.toml`, `rproj.lock`); `run-tests` sets `QUARTO_R` to `tests/.rvenv/bin`
5757
- **Python**: uv (`pyproject.toml`, `uv.lock`)
5858
- **Julia**: Pkg.jl (`Project.toml`, `Manifest.toml`)
5959

‎.claude/rules/testing/unit-test-with-r.md‎

Lines changed: 0 additions & 18 deletions
This file was deleted.

‎.gitattributes‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,6 @@ tools/codemod/** text eol=lf
4848
*.otf binary
4949

5050

51+
# rig proj sync rewrites this file with LF line endings; a CRLF checkout
52+
# would then show it as modified after every sync.
53+
tests/.Renviron text eol=lf
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: "Set up rig"
2+
description: "Installs a pinned rig release and adds it to PATH. rig proj is experimental, so callers get one pinned version rather than latest."
3+
inputs:
4+
version:
5+
description: "rig version to install, without the leading v"
6+
required: false
7+
default: "0.11.1"
8+
9+
runs:
10+
using: "composite"
11+
steps:
12+
- name: Install rig (Windows)
13+
if: runner.os == 'Windows'
14+
shell: pwsh
15+
env:
16+
RIG_VERSION: ${{ inputs.version }}
17+
run: |
18+
$zip = Join-Path $env:RUNNER_TEMP "rig.zip"
19+
$dest = Join-Path $env:RUNNER_TEMP "rig"
20+
Invoke-WebRequest -Uri "https://github.com/r-lib/rig/releases/download/v$($env:RIG_VERSION)/rig-windows-x86_64-$($env:RIG_VERSION).zip" -OutFile $zip
21+
Expand-Archive -Path $zip -DestinationPath $dest -Force
22+
Join-Path $dest "bin" | Out-File -FilePath $env:GITHUB_PATH -Append -Encoding utf8
23+
& (Join-Path $dest "bin/rig.exe") --version
24+
25+
- name: Install rig
26+
if: runner.os != 'Windows'
27+
shell: bash
28+
env:
29+
RIG_VERSION: ${{ inputs.version }}
30+
run: |
31+
case "$RUNNER_OS-$RUNNER_ARCH" in
32+
Linux-X64) asset="rig-linux-x86_64-${RIG_VERSION}.tar.gz" ;;
33+
macOS-ARM64) asset="rig-macos-arm64-${RIG_VERSION}.tar.gz" ;;
34+
*) echo "::error::No rig build configured for $RUNNER_OS-$RUNNER_ARCH"; exit 1 ;;
35+
esac
36+
dest="$RUNNER_TEMP/rig"
37+
mkdir -p "$dest"
38+
curl -fsSL "https://github.com/r-lib/rig/releases/download/v${RIG_VERSION}/${asset}" | tar -xz -C "$dest"
39+
echo "$dest/bin" >> "$GITHUB_PATH"
40+
"$dest/bin/rig" --version

‎.github/workflows/test-ff-matrix.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
workflow_call:
55
inputs:
66
extra-r-packages:
7-
description: "Comma-separated R packages to pass to renv::install"
7+
description: "Comma-separated R packages to pass to rig pkg install (see test-smokes.yml)"
88
required: false
99
type: string
1010
default: ""
@@ -46,7 +46,7 @@ on:
4646
workflow_dispatch:
4747
inputs:
4848
extra-r-packages:
49-
description: "extra R package to install for the runs (like a dev version of one of the deps) - comma separated, passed to renv::install"
49+
description: "extra R packages installed on top of tests/rproj.lock (like a dev version of one of the deps) - comma separated, passed to rig pkg install: pkg, owner/repo[@ref], gitlab::group/project, url::https://...; pkg@1.2.3 means exactly 1.2.3"
5050
required: false
5151
type: string
5252
default: ""

‎.github/workflows/test-smokes-parallel.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ on:
1010
default: 10
1111
type: number
1212
extra-r-packages:
13-
description: "extra R package to install for the tests runs (like a dev version of one of the deps) - comma separated, passed to renv::install"
13+
description: "extra R packages installed on top of tests/rproj.lock (like a dev version of one of the deps) - comma separated, passed to rig pkg install: pkg, owner/repo[@ref], gitlab::group/project, url::https://...; pkg@1.2.3 means exactly 1.2.3"
1414
required: false
1515
type: string
1616
default: ""

‎.github/workflows/test-smokes.yml‎

Lines changed: 77 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ on:
1515
type: boolean
1616
default: false
1717
extra-r-packages:
18-
description: "extra R package to install for the runs (like a dev version of one of the deps) - comma separated, passed to renv::install"
18+
description: "extra R packages installed on top of tests/rproj.lock (like a dev version of one of the deps) - comma separated, passed to rig pkg install: pkg, owner/repo[@ref], gitlab::group/project, url::https://...; pkg@1.2.3 means exactly 1.2.3"
1919
required: false
2020
type: string
2121
default: ""
@@ -67,7 +67,7 @@ on:
6767
type: boolean
6868
default: false
6969
extra-r-packages:
70-
description: "extra R package to install for the runs (like a dev version of one of the deps) - comma separated, passed to renv::install"
70+
description: "extra R packages installed on top of tests/rproj.lock (like a dev version of one of the deps) - comma separated, passed to rig pkg install: pkg, owner/repo[@ref], gitlab::group/project, url::https://...; pkg@1.2.3 means exactly 1.2.3"
7171
required: false
7272
type: string
7373
default: ""
@@ -110,6 +110,16 @@ jobs:
110110
# Empty keeps the standard checkout behavior.
111111
ref: ${{ inputs.ref }}
112112

113+
- name: Check the ref supports the rig test environment
114+
shell: bash
115+
run: |
116+
for f in tests/rproj.lock .github/actions/setup-rig/action.yml; do
117+
if [ ! -f "$f" ]; then
118+
echo "::error::This checkout has no $f. The R test environment needs a ref that uses the rig project (releases before it was introduced are not supported)."
119+
exit 1
120+
fi
121+
done
122+
113123
# macOS runners boot with an unresolvable `.local` hostname, so any process
114124
# resolving its own hostname stalls ~35s (actions/runner-images#14568).
115125
- name: Set a resolvable hostname (macOS)
@@ -128,7 +138,7 @@ jobs:
128138
shell: bash
129139

130140
# Drops a slow azure.archive.ubuntu.com from the apt mirror list so the job uses
131-
# archive.ubuntu.com (actions/runner-images#14823): sampled here before setup-r,
141+
# archive.ubuntu.com (actions/runner-images#14823): sampled here before rig installs R,
132142
# and after a failed attempt in later apt steps run via $APT_WITH_FALLBACK.
133143
# Inline, not a local action, because release mode checks out older tags.
134144
- name: Configure apt mirror fallback
@@ -191,13 +201,8 @@ jobs:
191201
fi
192202
exit 0
193203
194-
- name: Set up R
195-
uses: r-lib/actions/setup-r@v2
196-
with:
197-
r-version: "4.6.1"
198-
use-public-rspm: true
199-
# required to avoid rtools bin in path
200-
windows-path-include-rtools: false
204+
- name: Set up rig
205+
uses: ./.github/actions/setup-rig
201206

202207
- name: Install node (for Playwright, MECA)
203208
uses: actions/setup-node@v6
@@ -292,29 +297,6 @@ jobs:
292297
if: ${{ runner.os != 'Windows' }}
293298
run: npm install -g meca --loglevel=error --no-audit
294299

295-
- name: Set RENV_PATHS_ROOT
296-
shell: bash
297-
run: |
298-
echo "RENV_PATHS_ROOT=${{ runner.temp }}/renv" >> $GITHUB_ENV
299-
300-
- name: Get R and OS version
301-
id: get-version
302-
run: |
303-
cat("os-version=", sessionInfo()$running, "\n", file = Sys.getenv("GITHUB_OUTPUT"), sep = "", append = TRUE)
304-
cat("r-version=", R.Version()$version.string, "\n", file = Sys.getenv("GITHUB_OUTPUT"), sep = "", append = TRUE)
305-
shell: Rscript {0}
306-
307-
- name: Restore Renv package cache
308-
id: cache-renv-packages-restore
309-
uses: actions/cache/restore@v5
310-
with:
311-
path: |
312-
${{ env.RENV_PATHS_ROOT }}
313-
renv/library
314-
key: ${{ steps.get-version.outputs.os-version }}-${{ steps.get-version.outputs.r-version }}-renv-2-${{ hashFiles('tests/renv.lock') }}
315-
restore-keys: |
316-
${{ steps.get-version.outputs.os-version }}-${{ steps.get-version.outputs.r-version }}-renv-2-
317-
318300
- name: Install missing system deps
319301
if: runner.os == 'Linux'
320302
run: |
@@ -340,56 +322,77 @@ jobs:
340322
brew install --cask xquartz
341323
brew install poppler librsvg
342324
343-
- name: Restore R packages
344-
id: restore-r-packages
325+
- name: Install R from rproj.lock
345326
working-directory: tests
327+
shell: bash
346328
run: |
347-
cat("::group::Installing renv if needed\n")
348-
if (!requireNamespace('renv', quietly = TRUE)) install.packages('renv')
349-
cat("::endgroup::\n")
350-
cat("::group::Restoring R packages from renv.lock\n")
351-
renv::restore()
352-
cat("::endgroup::\n")
353-
cat("::group::Verifying R packages are synchronized after restore\n")
354-
status <- renv::status()
355-
if (!isTRUE(status$synchronized)) {
356-
cat("::error::R packages are not synchronized after restore - some packages may have failed to install\n")
357-
quit(status = 1)
358-
}
359-
cat("::endgroup::\n")
360-
cat("::group::Installing dev versions of knitr and rmarkdown\n")
361-
# Install dev versions for our testing
362-
# Use r-universe to avoid github api calls
363-
try(install.packages('rmarkdown', repos = c('https://rstudio.r-universe.dev', getOption('repos'))))
364-
try(install.packages('knitr', repos = c('https://yihui.r-universe.dev', getOption('repos'))))
365-
cat("::endgroup::\n")
366-
# A failed dev install keeps the renv-restored version; flag it instead of failing setup
367-
for (pkg in c('rmarkdown', 'knitr')) {
329+
# A separate step because on Linux rig proj sync re-runs itself under sudo
330+
# to install R, which leaves the project library owned by root.
331+
r_version=$(sed -n 's/^r_version = "\(.*\)"/\1/p' rproj.lock | head -n 1 | tr -d '\r')
332+
rig add "$r_version"
333+
334+
- name: Sync R packages from rproj.lock
335+
working-directory: tests
336+
shell: bash
337+
run: |
338+
# Refs that predate the rig project are rejected by the preflight step after checkout.
339+
echo "::group::rig proj sync"
340+
rig proj sync --locked --no-install-r
341+
echo "::endgroup::"
342+
343+
- name: Install dev and extra R packages
344+
working-directory: tests
345+
shell: bash
346+
env:
347+
EXTRA_R_PACKAGES: ${{ inputs.extra-r-packages }}
348+
run: |
349+
# Installs on top of the lock must target the project library and the
350+
# exact R the sync used; rig's default is the default R's user library.
351+
r_version=$(sed -n 's/^r-version = //p' .rvenv/rvenv.cfg | tr -d '\r')
352+
r_lib="$(cd .rvenv/lib && { pwd -W 2>/dev/null || pwd; })"
353+
overlay() { rig pkg install --r-version "$r_version" --library "$r_lib" "$@"; }
354+
355+
echo "::group::Installing dev versions of knitr and rmarkdown"
356+
# Use r-universe to avoid GitHub API calls. A failed dev install keeps
357+
# the locked version; the check below flags it instead of failing setup.
358+
overlay --with-repos https://rstudio.r-universe.dev rmarkdown || true
359+
overlay --with-repos https://yihui.r-universe.dev knitr || true
360+
echo "::endgroup::"
361+
362+
if [ -n "$EXTRA_R_PACKAGES" ]; then
363+
echo "::notice::Running with the following extra R packages: $EXTRA_R_PACKAGES"
364+
echo "::group::Installing extra R packages"
365+
specs=()
366+
IFS=',' read -ra items <<< "$EXTRA_R_PACKAGES"
367+
for item in "${items[@]}"; do
368+
item="${item#"${item%%[![:space:]]*}"}"
369+
item="${item%"${item##*[![:space:]]}"}"
370+
# renv's pkg@1.2.3 is an exact version; rig reads it as a minimum.
371+
if [[ "$item" =~ ^[A-Za-z][A-Za-z0-9.]*@[0-9] ]]; then item="${item/@/@=}"; fi
372+
specs+=("$item")
373+
done
374+
overlay "${specs[@]}"
375+
echo "::endgroup::"
376+
fi
377+
378+
echo "::group::Installing sessioninfo"
379+
overlay sessioninfo
380+
echo "::endgroup::"
381+
382+
# Run through the wrapper so the check sees the library the tests load.
383+
cat > .rvenv/ci-r-check.R <<'EOF'
384+
for (pkg in c("rmarkdown", "knitr")) {
368385
repo <- packageDescription(pkg)$Repository
369-
if (is.null(repo) || !grepl('r-universe.dev', repo, fixed = TRUE)) {
386+
if (is.null(repo) || !grepl("r-universe.dev", repo, fixed = TRUE)) {
370387
cat(sprintf("::notice::Dev version of %s not installed; tests use %s from %s\n",
371-
pkg, packageVersion(pkg), if (is.null(repo)) "unknown source" else repo))
388+
pkg, format(packageVersion(pkg)), if (is.null(repo)) "unknown source" else repo))
372389
}
373390
}
374-
if ('${{ inputs.extra-r-packages }}' != '') {
375-
cat(sprintf("::notice::Running with the following extra R packages for renv: %s\n", "${{ inputs.extra-r-packages }}"))
376-
cat("::group::Installing extra R packages\n")
377-
renv::install(strsplit("${{ inputs.extra-r-packages }}", split = ",")[[1]])
378-
cat("::endgroup::\n")
379-
}
380-
shell: Rscript {0}
381-
env:
382-
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
383-
384-
- name: Show R session information
385-
working-directory: tests
386-
run: |
387-
# Session info
388391
cat("::group::Session info\n")
389-
renv::install("sessioninfo")
390392
sessioninfo::session_info(pkgs = "installed", include_base = TRUE)
391393
cat("::endgroup::\n")
392-
shell: Rscript {0}
394+
EOF
395+
.rvenv/bin/Rscript .rvenv/ci-r-check.R
393396
394397
- name: Install uv for Python
395398
uses: astral-sh/setup-uv@20cfd1bf945f4377ade1205e4dbc17946fc9a30d # v10.0.1
@@ -719,17 +722,6 @@ jobs:
719722
key: ${{ steps.cache-typst.outputs.cache-primary-key }}
720723
path: ${{ steps.cache-typst.outputs.cache-path }}
721724

722-
- name: Save Renv package cache
723-
# don't save cache if we have extra R packages, or if the cache restore or
724-
# renv::restore did not complete (partial library, see Typst cache above)
725-
if: ${{ !cancelled() && steps.restore-r-packages.outcome == 'success' && steps.cache-renv-packages-restore.outputs.cache-hit != 'true' && inputs.extra-r-packages == '' }}
726-
uses: actions/cache/save@v5
727-
with:
728-
path: |
729-
${{ env.RENV_PATHS_ROOT }}
730-
renv/library
731-
key: ${{ steps.cache-renv-packages-restore.outputs.cache-primary-key }}
732-
733725
- uses: actions/upload-artifact@v7
734726
# Include the OS because sibling jobs share the workflow run.
735727
if: ${{ !cancelled() && runner.os != 'Windows' && hashFiles('tests/integration/playwright/playwright-report/**/*') != '' }}

‎.luarc.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@
1919
"Lua.runtime.version": "Lua 5.3",
2020
"Lua.workspace.checkThirdParty": false,
2121
"Lua.workspace.library": ["src/resources/lua-types"],
22-
"Lua.workspace.ignoreDir": ["tests/renv", ".vscode", "**/node_modules/*"]
22+
"Lua.workspace.ignoreDir": ["tests/.rvenv", ".vscode", "**/node_modules/*"]
2323
}

‎.vscode/launch.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
"QUARTO_ROOT": "${workspaceFolder}",
5656
"QUARTO_BIN_PATH": "${workspaceFolder}/package/dist/bin",
5757
"QUARTO_SHARE_PATH": "${workspaceFolder}/src/resources",
58+
"QUARTO_R": "${workspaceFolder}/tests/.rvenv/bin",
5859
"QUARTO_DEBUG": "true"
5960
},
6061
"attachSimplePort": 9229,

‎dev-docs/configuring-test-deps.md‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,7 @@
6262

6363
## R
6464

65-
- Add the dependencies in `DESCRIPTION` file
66-
- Run `renv::install(<package>)` to install the dependencies
67-
- Run `renv::snapshot()` to lock the versions in `renv.lock`
65+
- Run `rig proj add <package>` from `tests/`: it adds the dependency to `rproj.toml`, locks it in `rproj.lock` and installs it
6866

6967
## Julia
7068

@@ -82,6 +80,5 @@
8280

8381
# Updating test dependencies
8482

85-
- When `main` updates the test environment (`tests/renv.lock`, `tests/uv.lock`, `tests/Manifest.toml`, or the R / Python / Julia versions in `.github/workflows/test-smokes.yml`), backport the update to the current stable branch (e.g. `v1.10`) while it still receives patch releases, as its own PR (see `checklist-backport-a-pr.md`).
83+
- When `main` updates the test environment (`tests/rproj.lock`, `tests/uv.lock`, `tests/Manifest.toml`, or the R / Python / Julia versions in `.github/workflows/test-smokes.yml`), backport the update to the current stable branch (e.g. `v1.10`) while it still receives patch releases, as its own PR (see `checklist-backport-a-pr.md`).
8684
- Patch releases are then tested against the same current R, Python, Julia and package versions users install.
87-
- CI caches are shared: the R cache key is built from the OS, the R version and the `tests/renv.lock` hash, and any branch can read caches saved on `main`. A stable branch with identical lock files gets cache hits; a diverged one does a slow cold restore on each PR.

0 commit comments

Comments
 (0)