Fix hook tests #617
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on: | |
pull_request: | |
branches: | |
- '*' | |
name: end-2-end | |
jobs: | |
end-2-end: | |
runs-on: macOS-latest | |
env: | |
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} | |
steps: | |
- uses: r-lib/actions/setup-pandoc@v2 | |
- uses: r-lib/actions/setup-r@v2 | |
- uses: actions/checkout@v4 | |
- name: Query dependencies | |
run: | | |
install.packages('remotes') | |
saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2) | |
writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version") | |
shell: Rscript {0} | |
- name: Cache R packages | |
uses: actions/cache@v4 | |
with: | |
path: ${{ env.R_LIBS_USER }} | |
key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }} | |
restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1- | |
- name: Install dependencies | |
run: | | |
remotes::install_deps(dependencies = TRUE) | |
remotes::install_cran('yaml') | |
shell: Rscript {0} | |
- name: Install package | |
run: R CMD INSTALL . | |
- name: Prepare pre-commit | |
run: | | |
config_name_test <- "pre-commit-config.yaml" | |
config_name <- paste0(".", config_name_test) | |
ref_config <- file.path("tests", "testthat", "reference-objects", config_name_test) | |
len_declared <- length(yaml::read_yaml(".pre-commit-hooks.yaml")) | |
len_testing <- length(yaml::read_yaml(ref_config)$repos[[1]]$hooks) | |
if (len_declared != len_testing) { | |
rlang::abort("You don't test all hooks. Add them to `test_path('reference-objects/pre-commit-config.yaml')`") | |
} | |
fs::file_delete(config_name) | |
fs::file_copy(ref_config, config_name) | |
shell: Rscript {0} | |
- name: Update Hook revision to current push | |
run: | | |
# hacky, maybe can use pre-commit try-repo? | |
# https://stackoverflow.com/questions/30871868/sed-replace-first-occurence-in-place-with-big-files | |
sed -i '' -e "1,/rev:.*/{s/rev:.*/rev: $GITHUB_SHA/;}" .pre-commit-config.yaml | |
- name: Run pre-commit | |
run: | | |
brew install pre-commit | |
pre-commit install --install-hooks | |
echo 'running R/test.R' | |
echo "#' some code\n#'\n#' @param here.\n#' @name somethings\nNULL" > R/test.R # overwrite if anything there | |
pre-commit run --files R/test.R | |
echo 'running DESCRIPTION' | |
cp tests/testthat/reference-objects/DESCRIPTION . | |
sleep 2 | |
echo 'one' >> codemeta.json | |
pre-commit run --files DESCRIPTION | |
echo 'running README' | |
echo 'one' > README.Rmd | |
sleep 1 | |
echo 'one' > README.md | |
git add README* | |
pre-commit run --files README.Rmd | |
echo 'running _pkgdown.yml' | |
cp tests/testthat/in/_pkgdown-index-articles.yml _pkgdown.yml | |
rm -rf man/ | |
mkdir man | |
cp tests/testthat/in/autoupdate.Rd man/autoudpate.Rd | |
rm -rf vignettes | |
mkdir vignettes | |
cp tests/testthat/in/pkgdown.Rmd vignettes/ | |
pre-commit run --files _pkgdown.yml | |
echo 'running man/autoupdate.Rd' | |
git reset HEAD --hard # restore initial state | |
git clean -f | |
rm -rf man/ | |
mkdir -p man | |
cp tests/testthat/in/autoupdate.Rd man/ | |
pre-commit run roxygenize --files man/autoupdate.Rd | |
git reset HEAD --hard # restore initial state | |
git clean -f | |
env: | |
SKIP: consistent-release-tag |