From 96ac2f1636f80a943f8a4fd6f2e93f870ff27ebb Mon Sep 17 00:00:00 2001 From: James Lamb Date: Sat, 28 Nov 2020 03:10:27 +0000 Subject: [PATCH] [ci] Move CI to GitHub Actions (fixes #286) (#287) * [ci] Move CI to GitHub Actions (fixes #286) * fixing OS * shell env vars * missing quotes * comments * pandoc * pdflatex * fix NOTEs about unrecognized files * weird linux stuff I h8 the tidyverse * better mirror * use test.sh * unnecessary installs * better path * Update .github/workflows/ci.yml * misc changes * errors are bad * add pkgdown * poppin * I h8 LaTeX * revert tinytex * stuff * more stuff * explicit exit * fix return codes * fix pandoc stuff * fix masking * remove commented-out stuff * NOT_CRAN * just test on r-release * just test oon r-release * more cleanup * simpler config * Update CONTRIBUTING.md * remove some installs --- .Rbuildignore | 4 +- .github/setup.sh | 22 +++++++++ .github/workflows/ci.yml | 47 +++++++++++++++++++ .travis.yml | 24 ---------- CONTRIBUTING.md | 2 +- DESCRIPTION | 1 + README.md | 2 +- test.sh | 42 ++++++++++++++--- tests/testthat.R | 8 ++-- tests/testthat/setup-setTestEnv.R | 2 +- tests/testthat/test-AbstractPackageReporter.R | 4 +- tests/testthat/test-CreatePackageVignette.R | 3 +- tests/testthat/test-PackageReport.R | 2 +- tests/testthat/test-cran-true.R | 2 +- 14 files changed, 123 insertions(+), 42 deletions(-) create mode 100755 .github/setup.sh create mode 100644 .github/workflows/ci.yml delete mode 100644 .travis.yml diff --git a/.Rbuildignore b/.Rbuildignore index 198de91b..f556c3a8 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1,7 +1,10 @@ # Files currently checked into the repo +^.*\.ci +^.*\.github ^docs$ ^_pkgdown\.yml$ ^pkgdown$ +^smoke_tests ^cran-comments\.md$ ^CODE_OF_CONDUCT\.md$ ^LICENSE\.MD$ @@ -64,4 +67,3 @@ vignettes/*\.pdf # Stuff .Rbuildignore .*\.gitkeep - diff --git a/.github/setup.sh b/.github/setup.sh new file mode 100755 index 00000000..96a92163 --- /dev/null +++ b/.github/setup.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +set -e + +if [[ "${OS_NAME}" == "ubuntu-latest" ]]; then + sudo apt-get update + sudo apt-get install \ + --no-install-recommends \ + -y \ + --allow-downgrades \ + libcurl4-openssl-dev \ + libfribidi-dev \ + libharfbuzz-dev \ + curl \ + || exit -1 +fi + +Rscript -e " + options(install.packages.check.source = 'no'); + install.packages('remotes', repos = 'https://cran.r-project.org') + remotes::install_deps(dependencies = TRUE) +" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..831eb506 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,47 @@ +name: Tests + +on: [push] + +jobs: + test: + name: ${{ matrix.os }} (R ${{ matrix.r-version }}) + runs-on: ${{ matrix.os }} + timeout-minutes: 60 + strategy: + fail-fast: false + matrix: + include: + - os: ubuntu-latest + r-version: 'release' + - os: macos-latest + r-version: 'release' + steps: + - name: checkout repository + uses: actions/checkout@v2.3.4 + with: + fetch-depth: 1 + - name: set up R + uses: r-lib/actions/setup-r@v1 + with: + r-version: ${{ matrix.r-version }} + - uses: r-lib/actions/setup-pandoc@v1 + - uses: r-lib/actions/setup-tinytex@v1 + - name: set up dependencies + shell: bash + env: + OS_NAME: ${{ matrix.os }} + run: $GITHUB_WORKSPACE/.github/setup.sh + - name: run tests + shell: bash + run: $GITHUB_WORKSPACE/test.sh + - name: upload coverage + if: ${{ matrix.os == 'macos-latest' && matrix.r-version == 'release' }} + shell: Rscript {0} + run: covr::codecov() + # https://github.community/t/is-it-possible-to-require-all-github-actions-tasks-to-pass-without-enumerating-them/117957/4?u=graingert + all-successful: + runs-on: ubuntu-latest + needs: [test] + steps: + - name: Note that all tests succeeded + run: echo "🎉" diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 67b93526..00000000 --- a/.travis.yml +++ /dev/null @@ -1,24 +0,0 @@ -language: R -cache: packages -warnings_are_errors: true - -os: - - linux - - osx - -before_install: | - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then - brew install llvm && - export PATH="/usr/local/opt/llvm/bin:$PATH" && - export LDFLAGS="-L/usr/local/opt/llvm/lib" && - export CFLAGS="-I/usr/local/opt/llvm/include"; - fi - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then - Rscript -e "options(install.packages.check.source = 'no'); install.packages('roxygen2', type = 'binary', repos = 'http://cran.rstudio.org')" - else - Rscript -e "install.packages('roxygen2', repos = 'http://cran.rstudio.org')" - fi - -after_success: - - cat "${RCHECK_DIR}/tests/testthat.Rout" - - Rscript -e 'install.packages("covr"); covr::codecov()' diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 038bf4cf..5a2be0bd 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -244,7 +244,7 @@ All comments should be above code, not beside it. *** ## Running Tests Locally -We use Travis CI to automatically run unit tests and a serious of other automated checks on every PR commit and merge to `main`. Every `pkgnet` release also goes through a battery of automated tests run on CRAN before becoming officially available through CRAN. +We use GitHub Actions to automatically run unit tests and a series of other automated checks on every PR commit and merge to `main`. Every `pkgnet` release also goes through a battery of automated tests run on CRAN before becoming officially available through CRAN. However, these options can lengthen your testing cycle and make the process of contributing tedious. If you wish to run tests locally on whatever machine you are developing `pkgnet` code on, run the following from the repo root: diff --git a/DESCRIPTION b/DESCRIPTION index 657b47fe..8d947a08 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -31,6 +31,7 @@ Imports: visNetwork Suggests: ggplot2, + pkgdown, testthat, webshot, withr diff --git a/README.md b/README.md index 149b84d5..82c42023 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # pkgnet -[![CRAN\_Status\_Badge](https://www.r-pkg.org/badges/version-last-release/pkgnet)](https://cran.r-project.org/package=pkgnet) [![CRAN\_Download\_Badge](https://cranlogs.r-pkg.org/badges/grand-total/pkgnet)](https://cran.r-project.org/package=pkgnet) [![Build Status](https://img.shields.io/travis/uptake/pkgnet.svg?label=build&logo=travis&branch=main)](https://travis-ci.org/uptake/pkgnet) +[![CRAN\_Status\_Badge](https://www.r-pkg.org/badges/version-last-release/pkgnet)](https://cran.r-project.org/package=pkgnet) [![CRAN\_Download\_Badge](https://cranlogs.r-pkg.org/badges/grand-total/pkgnet)](https://cran.r-project.org/package=pkgnet) [![GitHub Actions Build Status](https://github.com/uptake/pkgnet/workflows/Tests/badge.svg?branch=main)](https://github.com/uptake/pkgnet/actions?query=workflow%3ATests+branch%3Amain) [![Appveyor Build status](https://ci.appveyor.com/api/projects/status/github/uptake/pkgnet?branch=main&svg=true)](https://ci.appveyor.com/project/jameslamb/pkgnet) [![codecov](https://codecov.io/gh/uptake/pkgnet/branch/main/graph/badge.svg)](https://codecov.io/gh/uptake/pkgnet) [![Lifecycle badge](https://img.shields.io/badge/lifecycle-maturing-blue.svg)](https://www.tidyverse.org/lifecycle/) diff --git a/test.sh b/test.sh index 72a743ac..2ab58ed5 100755 --- a/test.sh +++ b/test.sh @@ -1,15 +1,45 @@ #!/bin/bash -rm *.tar.gz -rm ~/thing.txt -R CMD BUILD . +set -e pipefail + +rm -f *.tar.gz +R CMD build . # Work outside of the source directory to avoid false # positives (i.e. test the tarball in isolation) mkdir -p ~/pkgnet_test_dir cp *.tar.gz ~/pkgnet_test_dir +export _R_CHECK_CRAN_INCOMING_=false pushd ~/pkgnet_test_dir - R CMD CHECK *.tar.gz --as-cran - cat ~/thing.txt -popd + R CMD check *.tar.gz --as-cran || exit 1 + + LOG_FILE_NAME="pkgnet.Rcheck/00check.log" + + echo "" + echo "----- R CMD check logs -----" + echo "" + cat pkgnet.Rcheck/00check.log + + echo "" + echo "----- test outputs -----" + echo "" + cat pkgnet.Rcheck/tests/testthat.Rout + + if grep -q -R "WARNING" "$LOG_FILE_NAME"; then + echo "WARNINGS have been found by R CMD check!" + exit 1 + fi + + ALLOWED_CHECK_NOTES=0 + NUM_CHECK_NOTES=$( + cat ${LOG_FILE_NAME} \ + | grep -e '^Status: .* NOTE.*' \ + | sed 's/[^0-9]*//g' + ) + if [[ ${NUM_CHECK_NOTES} -gt ${ALLOWED_CHECK_NOTES} ]]; then + echo "Found ${NUM_CHECK_NOTES} NOTEs from R CMD check. Only ${ALLOWED_CHECK_NOTES} are allowed" + exit 1 + fi + +popd || exit 0 diff --git a/tests/testthat.R b/tests/testthat.R index 62c3c37c..d94e86eb 100644 --- a/tests/testthat.R +++ b/tests/testthat.R @@ -9,13 +9,13 @@ Sys.setenv("R_TESTS" = "") ####### TESTING ON vs. OFF CRAN ############# -# Due to complications on CRAN with handling of temporary packages during testing, TRAVIS +# Due to complications on CRAN with handling of temporary packages during testing, continuous integration (CI) # and local testing will remain the main test processes for pkgnet. # See https://github.com/uptake/pkgnet/issues/160 for details on this decision. cat("testthat.R | NOT_CRAN =", Sys.getenv("NOT_CRAN"), "\n") if(identical(Sys.getenv("NOT_CRAN"), "true")){ - ######## TRAVIS and LOCAL TEST PROCEDURE ############# + ######## CI and LOCAL TEST PROCEDURE ############# # Check if setup and helper funs have been run. # If in R CMD CHECK, they may not have been run yet. @@ -26,7 +26,7 @@ if(identical(Sys.getenv("NOT_CRAN"), "true")){ library(pkgnet) ## ****************************************************************************************** ## THIS IS THIS SAME CONTENT as setup_setTestEnv.R but neccessary to paste here due to - ## travis checks. + ## CI checks. ## ****************************************************************************************** # [DEBUG] write("PKGNET_REBUILD triggered", file = "~/thing.txt", append = TRUE) @@ -70,7 +70,7 @@ if(identical(Sys.getenv("NOT_CRAN"), "true")){ ## ****************************************************************************************** ## THIS IS THIS SAME CONTENT as teardown_setTestEnv.R but neccessary to paste here due to - ## travis checks. + ## CI checks. ## ****************************************************************************************** # [DEBUG] write("PKGNET_REBUILD tear-down triggered", file = "~/thing.txt", append = TRUE) diff --git a/tests/testthat/setup-setTestEnv.R b/tests/testthat/setup-setTestEnv.R index e8ac88ef..18696acd 100644 --- a/tests/testthat/setup-setTestEnv.R +++ b/tests/testthat/setup-setTestEnv.R @@ -4,7 +4,7 @@ cat("setup-setTestEnv.R | NOT_CRAN =", Sys.getenv("NOT_CRAN"), "\n") if(identical(Sys.getenv("NOT_CRAN"), "true")){ - ######## TRAVIS and LOCAL TEST PROCEDURE ############# + ######## CI and LOCAL TEST PROCEDURE ############# # record original libpaths in order to reset later. # This should be unnecessary since tests are conducted within a seperate enviornment. diff --git a/tests/testthat/test-AbstractPackageReporter.R b/tests/testthat/test-AbstractPackageReporter.R index 1790d784..5e1267c1 100644 --- a/tests/testthat/test-AbstractPackageReporter.R +++ b/tests/testthat/test-AbstractPackageReporter.R @@ -67,7 +67,9 @@ test_that(".is.PackageReporter correctly identifies package reporters", { expect_true(pkgnet:::.is.PackageReporter(DependencyReporter$new())) expect_true(pkgnet:::.is.PackageReporter(FunctionReporter$new())) expect_true(pkgnet:::.is.PackageReporter(InheritanceReporter$new())) - expect_true(pkgnet:::.is.PackageReporter(SummaryReporter$new())) + + # using :: to avoid masking by testthat::SummaryReporter + expect_true(pkgnet:::.is.PackageReporter(pkgnet::SummaryReporter$new())) DependencyTabloid <- R6::R6Class( classname = "DependencyTabloid" diff --git a/tests/testthat/test-CreatePackageVignette.R b/tests/testthat/test-CreatePackageVignette.R index 246a744a..cf58cc7d 100644 --- a/tests/testthat/test-CreatePackageVignette.R +++ b/tests/testthat/test-CreatePackageVignette.R @@ -100,10 +100,11 @@ test_that("Test that CreatePackageVignette runs end-to-end with non-default repo ) outputPath <- tempfile(pattern = "vignette", fileext = ".html") + # using :: to avoid masking by testthat::SummaryReporter expect_true({ CreatePackageVignette(pkg = pkgPath , pkg_reporters = list( - SummaryReporter$new() + pkgnet::SummaryReporter$new() , DependencyReporter$new() ) , vignette_path = vignettePath diff --git a/tests/testthat/test-PackageReport.R b/tests/testthat/test-PackageReport.R index 3245daad..a26ebeee 100644 --- a/tests/testthat/test-PackageReport.R +++ b/tests/testthat/test-PackageReport.R @@ -87,7 +87,7 @@ test_that('PackageReport works with pkg_path', { ) reporterObj$DependencyReporter <- DependencyReporter$new() expect_true(reporterObj$pkg_path == MILNE_PKG_PATH) - # The below test fails on macOS Travis for some mysterious reason. + # The below test fails on macOS CI for some mysterious reason. #expect_true(reporterObj$DependencyReporter$.__enclos_env__$private$pkg_path == MILNE_PKG_PATH) }) diff --git a/tests/testthat/test-cran-true.R b/tests/testthat/test-cran-true.R index 40d10333..feb35546 100644 --- a/tests/testthat/test-cran-true.R +++ b/tests/testthat/test-cran-true.R @@ -1,5 +1,5 @@ context("always true for cran") -# Due to complications on CRAN with handling of temporary packages during testing, TRAVIS +# Due to complications on CRAN with handling of temporary packages during testing, CI # and local testing will remain the main test processes for pkgnet. # See https://github.com/uptake/pkgnet/issues/160 for details on this decision.