Skip to content

Commit a7198d0

Browse files
authored
[backport] Replace renv with a rig project for the R test environment (#15318)
* 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 (cherry picked from commit ccc1cf6) * Install R before syncing in configure-test-env In rig's admin mode, rig proj sync installs a missing R by re-running the whole command elevated, so the project library under tests/.rvenv ends up owned by root (r-lib/rig#503, fixed in rig's development version but not in 0.11.1). Setting up the test environment on a machine without the locked R then leaves a library the later dev rmarkdown and knitr installs cannot write to, and they fall back to the locked versions. Install R with rig add first, which does nothing when that version is already installed, then run rig proj sync --no-install-r as the calling user. This is the sequence the CI workflow already uses. Both configure-test-env.sh and configure-test-env.ps1 get it, since rig elevates the same way on Windows. Verified the already-installed path on Windows with both scripts. The missing-R path was not exercised. (cherry picked from commit 9777eda)
1 parent a8b705a commit a7198d0

37 files changed

Lines changed: 11892 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
@@ -46,3 +46,6 @@ src/** text eol=lf
4646
*.otf binary
4747

4848

49+
# rig proj sync rewrites this file with LF line endings; a CRLF checkout
50+
# would then show it as modified after every sync.
51+
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: ""
@@ -105,6 +105,16 @@ jobs:
105105
# Empty keeps the standard checkout behavior.
106106
ref: ${{ inputs.ref }}
107107

108+
- name: Check the ref supports the rig test environment
109+
shell: bash
110+
run: |
111+
for f in tests/rproj.lock .github/actions/setup-rig/action.yml; do
112+
if [ ! -f "$f" ]; then
113+
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)."
114+
exit 1
115+
fi
116+
done
117+
108118
# macOS runners boot with an unresolvable `.local` hostname, so any process
109119
# resolving its own hostname stalls ~35s (actions/runner-images#14568).
110120
- name: Set a resolvable hostname (macOS)
@@ -123,7 +133,7 @@ jobs:
123133
shell: bash
124134

125135
# Drops a slow azure.archive.ubuntu.com from the apt mirror list so the job uses
126-
# archive.ubuntu.com (actions/runner-images#14823): sampled here before setup-r,
136+
# archive.ubuntu.com (actions/runner-images#14823): sampled here before rig installs R,
127137
# and after a failed attempt in later apt steps run via $APT_WITH_FALLBACK.
128138
# Inline, not a local action, because release mode checks out older tags.
129139
- name: Configure apt mirror fallback
@@ -186,13 +196,8 @@ jobs:
186196
fi
187197
exit 0
188198
189-
- name: Set up R
190-
uses: r-lib/actions/setup-r@v2
191-
with:
192-
r-version: "4.6.1"
193-
use-public-rspm: true
194-
# required to avoid rtools bin in path
195-
windows-path-include-rtools: false
199+
- name: Set up rig
200+
uses: ./.github/actions/setup-rig
196201

197202
- name: Install node (for Playwright, MECA)
198203
uses: actions/setup-node@v6
@@ -287,29 +292,6 @@ jobs:
287292
if: ${{ runner.os != 'Windows' }}
288293
run: npm install -g meca --loglevel=error --no-audit
289294

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

711-
- name: Save Renv package cache
712-
# don't save cache if we have extra R packages, or if the cache restore or
713-
# renv::restore did not complete (partial library, see Typst cache above)
714-
if: ${{ !cancelled() && steps.restore-r-packages.outcome == 'success' && steps.cache-renv-packages-restore.outputs.cache-hit != 'true' && inputs.extra-r-packages == '' }}
715-
uses: actions/cache/save@v5
716-
with:
717-
path: |
718-
${{ env.RENV_PATHS_ROOT }}
719-
renv/library
720-
key: ${{ steps.cache-renv-packages-restore.outputs.cache-primary-key }}
721-
722714
- uses: actions/upload-artifact@v7
723715
# Include the OS because sibling jobs share the workflow run.
724716
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)