Skip to content

Test legacy hook scripts #264

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

Merged
merged 11 commits into from
May 21, 2021
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
110 changes: 110 additions & 0 deletions .github/workflows/hook-tests-legacy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
on:
push:
branches:
- master
pull_request:
branches:
- master

name: Legacy hook tests
jobs:
hook-test:
runs-on: ${{ matrix.config.os }}

name: ${{ matrix.config.os }} (${{ matrix.config.r }})

strategy:
fail-fast: false
matrix:
config:
- {os: macOS-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: ubuntu-18.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/bionic/latest", http-user-agent: "R/4.0.0 (ubuntu-18.04) R (4.0.0 x86_64-pc-linux-gnu x86_64 linux-gnu) on GitHub Actions" }
env:
RSPM: ${{ matrix.config.rspm }}
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v2
- uses: r-lib/actions/setup-r@master
with:
r-version: ${{ matrix.config.r }}
http-user-agent: ${{ matrix.config.http-user-agent }}
- name: checkout old hook scripts
run: |
git fetch origin refs/tags/v0.1.3:refs/tags/v0.1.3
git checkout v0.1.3 -- inst/bin
git checkout v0.1.3 -- tests/testthat/test-all.R
- name: Query dependencies
run: |
writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version")
shell: Rscript {0}
- name: Cache R packages (macOs)
if: startsWith(runner.os, 'macOS')
uses: actions/cache@v2
with:
path: ~/Library/Application Support/renv
key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('renv.lock') }}
restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-
- name: Cache R packages (Linux)
if: startsWith(runner.os, 'Linux')
uses: actions/cache@v2
with:
path: ~/.local/share/renv
key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('renv.lock') }}
restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-
- name: Cache R packages (Windows)
if: startsWith(runner.os, 'Windows')
uses: actions/cache@v2
with:
path: ~\AppData\Local\renv
key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('renv.lock') }}
restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-

- name: Install system dependencies (Linux)
if: runner.os == 'Linux'
run: |
Rscript -e "install.packages('remotes', repos = Sys.getenv('RSPM'))"
while read -r cmd
do
eval sudo $cmd
done < <(Rscript -e 'cat(remotes::system_requirements("ubuntu", "18.04"), sep = "\n")')
- name: Perpare testing environment
run: |
# testing dependencies (incl. {precommit}) live in global R library,
# hook dependencies in renv, which is only activated when child R
# process is invoked, e.g. as in run_test()
if (!requireNamespace("renv", quietly = TRUE)) {
install.packages("renv", repos = c(CRAN = "https://cloud.r-project.org"))
}
renv::install(c('testthat', 'devtools', 'desc'))
renv::install(desc::desc_get_deps()$package) # install all deps
renv::install(getwd())
shell: Rscript {0}
- name: Session info (testing environment)
run: |
renv::install('sessioninfo', repos = 'cloud.r-project.org')
options(width = 100)
pkgs <- installed.packages()[, "Package"]
sessioninfo::session_info(pkgs, include_base = TRUE)
shell: Rscript {0}
- name: Test
run: |
devtools::load_all()
testthat::test_file(
"tests/testthat/test-all.R",
reporter = testthat::MultiReporter$new(list(
testthat::CheckReporter$new(), testthat::FailReporter$new()
))
)
shell: Rscript {0}
- name: Show testthat output
if: always()
run: find check -name 'testthat.Rout*' -exec cat '{}' \; || true
shell: bash
- name: Upload check results
if: failure()
uses: actions/upload-artifact@main
with:
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
path: check
2 changes: 1 addition & 1 deletion .github/workflows/hook-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ jobs:
}
renv::install(c('testthat', 'devtools'))
# some testing infrastructure we need is in R/testing.R
renv::install(getwd(), dependencies = TRUE)
renv::install(getwd())
shell: Rscript {0}
- name: Session info (testing environment)
run: |
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
`language: script` from the [pre-commit framework](https://pre-commit.com).
This requires `pre-commit >= 2.11.1`. All hooks and dependencies are now
contained in a virtual environment with [`{renv}`](https://rstudio.github.io/renv/)
(#233, #250, #260). Thanks to {renv}'s excellent
(#233, #250, #260, #264). Thanks to {renv}'s excellent
[caching](https://rstudio.github.io/renv/articles/renv.html#cache-1), this
does not consume much space and is fast. This makes output
of hooks more consistent across different local setups, make manual dependency
Expand Down
2 changes: 1 addition & 1 deletion renv.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"Repositories": [
{
"Name": "CRAN",
"URL": "https://packagemanager.rstudio.com/all/latest"
"URL": "https://cran.rstudio.com"
}
]
},
Expand Down
16 changes: 14 additions & 2 deletions vignettes/testing.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pre-commit >= 2.11.0 supports R as a language and each hook repo has its own
virtual environment with package versions locked. For that reason, we should
also test with exactly these versions.

This package has three testing worfklows:
This package has four testing workflows:

* hook testing. Tests the hooks (as well as hook script helpers?) in the renv in
which they'll be shipped. No R CMD Check or pre-commit executable needed.
Expand All @@ -30,9 +30,21 @@ This package has three testing worfklows:
from `run_test()`, the only way to do this is to set an env variable when
running `run_test()` and check in the user R profile if it is set, and then
activate the renv. This is done with `R_PRECOMMIT_HOOK_ENV`.

* Legacy hook testing: It is possible that someone updates the R package
{precommit}, but not the hook revision (e.g. with `precommit::autoupdate()`)
or vice versa. If the hook revision is updated to `>= 0.2.0`, all hook scripts
and {precommit} functions called from the hook script are from the same
version of {precommit}, so we don't need to test hook compatibility. If the R
package is updated but not the hook revision, old hook scripts are called with
while the {precommit} functions in them are from a new package version. Hence,
we need compatibility between new packages and old hook scripts, which is
exactly what is tested with this workflow. Until there are breaking changes in
the *hook script helpers* family of exported functions, there should not be
a problem.

* complete testing: Tests hooks as well as usethis like access functionality
with latest CRAN packges, on all platforms, with all installation methods.
with latest CRAN packages, on all platforms, with all installation methods.

* CRAN testing. On CRAN, complete testing is ran, tests that check pre-commit
executable access are disabled.