Added Rhub. #45
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
# NOTE: This script is a modification of the r-lib/actions standard cehcking script and the public-private sync script, on which it piggybacks to detect when it's in a private repo and can therefore skip some or even all tests. It also builds and uploads binaries for Windows and MacOS. | |
# For help debugging build failures open an issue on the RStudio community with the 'github-actions' tag. | |
# https://community.rstudio.com/new-topic?category=Package%20development&tags=github-actions | |
# Each entry in the config matrix must have the following keys: | |
# | |
# os: windows-latest, macOS-latest, ubuntu-20.04, etc. (as of this writing) | |
# | |
# r: devel or release | |
# | |
# rspm: Linux only, just leave it alone. | |
# | |
# timeout: in minutes | |
# | |
# flags: a comma (or some other aesthetically pleasing and | |
# non-forbidden symbol) separated list of flags. Currently | |
# supported: | |
# | |
# binaries: build and upload as an artefact a binary version (particularly for MacOS and Windows). | |
# | |
# full: run with ENABLE_statnet_TESTS. | |
# | |
# vignettes: build vignettes and manuals; otherwise ignore. | |
# | |
# ubsan: compile with -fsanitize=undefined and fail on any errors identified. | |
# | |
# covr: run in covr mode may be used with 'full' but probably not with others. | |
on: [push, pull_request] | |
name: R-CMD-check | |
# Set public and private repositories (i.e., USER/PKG). Leave blank to autodetect. | |
env: | |
PUBLIC: '' | |
PRIVATE: '' | |
jobs: | |
## Remove-Old-Artifacts: | |
## runs-on: ubuntu-latest | |
## timeout-minutes: 10 | |
## | |
## steps: | |
## - name: Remove old artifacts | |
## uses: c-hive/[email protected] | |
## with: | |
## age: '1 month' | |
## skip-recent: 8 | |
Set-Matrix-Private: | |
runs-on: ubuntu-latest | |
outputs: | |
matrix: ${{ steps.set-matrix.outputs.matrix }} | |
steps: | |
- name: check-config # Make sure either neither or both are set; abort if not. | |
if: (env.PUBLIC == '') != (env.PRIVATE == '') | |
run: | | |
echo "Configuration problem: only one of the repositories is set." | |
exit 1 | |
- name: detect-repos | |
if: env.PUBLIC == '' && env.PRIVATE == '' # Autodetect always. | |
run: | | |
if [[ "${{ github.repository }}" == *-private ]] | |
then # Current repo is private. | |
IAM="private" | |
PRIVATE="${{ github.repository }}" | |
PUBLIC="${PRIVATE%-private}" | |
else # Current repo is public. | |
IAM="public" | |
PUBLIC="${{ github.repository }}" | |
PRIVATE="$PUBLIC-private" | |
fi | |
echo "IAM=$IAM" >> $GITHUB_ENV | |
echo "PRIVATE=$PRIVATE" >> $GITHUB_ENV | |
echo "PUBLIC=$PUBLIC" >> $GITHUB_ENV | |
- name: public-check # Check if the branch/tag exists in the public repository. | |
if: env.IAM == 'private' # Only check if from private repo. | |
run: | | |
set +e | |
git ls-remote --exit-code https://github.com/${{ env.PUBLIC }} ${{ github.ref }} | |
echo "FOUND_PUBLIC=$?" >> $GITHUB_ENV | |
- name: set-matrix | |
id: set-matrix | |
run: | | |
if [[ "${{ env.IAM }}" == 'public' ]] # Public: full set. | |
then | |
config='{"config":[ | |
{"os":"windows-latest", "r":"release", "timeout":360, "flags":"binaries"}, | |
{"os":"macOS-latest", "r":"release", "timeout":360, "flags":"binaries"}, | |
{"os":"ubuntu-20.04", "r":"release", "rspm":"https://packagemanager.rstudio.com/cran/__linux__/focal/latest", "timeout":360, "flags":"full, ubsan"}, | |
{"os":"ubuntu-20.04", "r":"devel", "rspm":"https://packagemanager.rstudio.com/cran/__linux__/focal/latest", "timeout":360, "flags":"vignettes"}, | |
{"os":"ubuntu-20.04", "r":"release", "rspm":"https://packagemanager.rstudio.com/cran/__linux__/focal/latest", "timeout":360, "flags":"full, covr"}]}' | |
elif [[ "${{ env.FOUND_PUBLIC }}" != '0' ]] # Private with no public analogue: reduced set. | |
then | |
config='{"config":[ | |
{"os":"ubuntu-20.04", "r":"release", "rspm":"https://packagemanager.rstudio.com/cran/__linux__/focal/latest", "timeout":10, "flags":"none"} | |
]}' | |
else # Private with public analogue: no checking. | |
config='' | |
fi | |
config="${config//'%'/'%25'}" | |
config="${config//$'\n'/'%0A'}" | |
config="${config//$'\r'/'%0D'}" | |
echo "::set-output name=matrix::$config" | |
R-CMD-check: | |
needs: Set-Matrix-Private | |
if: needs.Set-Matrix-Private.outputs.matrix != '' | |
runs-on: ${{ matrix.config.os }} | |
name: ${{ matrix.config.os }} (r ${{ matrix.config.r }}, flags ${{ matrix.config.flags }}) | |
strategy: | |
fail-fast: false | |
matrix: ${{fromJson(needs.Set-Matrix-Private.outputs.matrix)}} | |
env: | |
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true | |
RSPM: ${{ matrix.config.rspm }} | |
steps: | |
- name: If available, use the Janitor's key rather than the repository-specific key. | |
id: set-pat | |
run: | | |
if [[ -n "${{ secrets.JANITORS_GITHUB_PAT }}" ]] | |
then | |
echo "GITHUB_PAT=${{ secrets.JANITORS_GITHUB_PAT }}" >> $GITHUB_ENV | |
else | |
echo "GITHUB_PAT=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_ENV | |
fi | |
shell: bash | |
- uses: actions/checkout@v2 | |
- uses: r-lib/actions/setup-r@v1 | |
with: | |
r-version: ${{ matrix.config.r }} | |
- name: Install GhostScript (on Linux if running vignettes) | |
if: runner.os == 'Linux' && contains(matrix.config.flags, 'vignettes') | |
run: | | |
/usr/bin/sudo DEBIAN_FRONTEND=noninteractive apt-get install -y ghostscript | |
shell: bash | |
- uses: r-lib/actions/setup-pandoc@v1 | |
- name: Install tinytex (system) | |
if: contains(matrix.config.flags, 'vignettes') | |
uses: r-lib/actions/setup-tinytex@v1 | |
- 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 | |
if: runner.os != 'Windows' | |
uses: actions/cache@v2 | |
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 system dependencies | |
if: runner.os == 'Linux' | |
run: | | |
while read -r cmd | |
do | |
eval sudo $cmd | |
done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "20.04"))') | |
- name: Install dependencies | |
run: | | |
remotes::install_deps(dependencies = TRUE) | |
remotes::install_cran("pkgbuild") | |
remotes::install_cran("rcmdcheck") | |
remotes::install_cran("covr") | |
shell: Rscript {0} | |
- name: Install tinytex (R) | |
if: contains(matrix.config.flags, 'vignettes') | |
run: | | |
remotes::install_cran("tinytex") | |
tinytex:::install_yihui_pkgs() | |
shell: Rscript {0} | |
- name: Build | |
if: contains(matrix.config.flags, 'binaries') | |
run: | | |
dir.create("binaries", FALSE) | |
pkgbuild::build(binary=TRUE, vignettes=FALSE, dest_path = "binaries") | |
shell: Rscript {0} | |
- name: Upload build results | |
if: contains(matrix.config.flags, 'binaries') && !failure() | |
uses: actions/upload-artifact@v2 | |
with: | |
name: ${{ runner.os }}-r${{ matrix.config.r }}-binaries | |
path: binaries | |
- name: Clean up build results | |
if: contains(matrix.config.flags, 'binaries') | |
run: rm -rf binaries | |
shell: bash | |
- name: Check | |
if: contains(matrix.config.flags, 'covr') == false | |
timeout-minutes: ${{ matrix.config.timeout }} | |
env: | |
_R_CHECK_CRAN_INCOMING_REMOTE_: false | |
_R_CHECK_FORCE_SUGGESTS_: false | |
ENABLE_statnet_TESTS: ${{ contains(matrix.config.flags, 'full') }} | |
R_VIGNETTES: ${{ contains(matrix.config.flags, 'vignettes') }} | |
FAIL_ON_WARN: ${{ contains(matrix.config.flags, 'strict') }} | |
USE_UBSAN: ${{ contains(matrix.config.flags, 'ubsan') }} | |
run: | | |
if(Sys.getenv("R_VIGNETTES") == "true"){ | |
check_args <- c("--as-cran") | |
build_args <- c("--compact-vignettes=gs+qpdf") | |
}else{ | |
check_args <- c("--no-manual", "--as-cran", "--ignore-vignettes") | |
build_args <- c("--no-manual", "--no-build-vignettes") | |
} | |
error_on <- if(Sys.getenv("FAIL_ON_WARN") == "true") "warning" else "error" | |
if(Sys.getenv("USE_UBSAN") == "true"){ | |
Sys.setenv(PKG_LIBS="-fsanitize=undefined", | |
PKG_CFLAGS="-fsanitize=undefined", | |
UBSAN_OPTIONS="print_stacktrace=1") | |
} | |
rcmdcheck::rcmdcheck(args = check_args, build_args = build_args, error_on = error_on, check_dir = "check") | |
shell: Rscript {0} | |
- name: Check UBSAN output | |
if: contains(matrix.config.flags, 'ubsan') | |
run: | | |
find check/ -name '*.Rout' -print0 | xargs -r -0 grep -E '\.[hc]:[0-9]+:[0-9]+: +runtime error:' > check/ubsan.err || true | |
if [ -s check/ubsan.err ] | |
then | |
echo "UBSAN errors:" >&2 | |
cat check/ubsan.err >&2 | |
exit 1 | |
fi | |
shell: bash | |
- name: Upload check results | |
if: contains(matrix.config.flags, 'covr') == false && failure() | |
uses: actions/upload-artifact@v2 | |
with: | |
name: ${{ runner.os }}-r${{ matrix.config.r }}-results | |
path: | | |
check | |
!check/*/00_pkg_src | |
- name: Test coverage | |
if: contains(matrix.config.flags, 'covr') | |
timeout-minutes: ${{ matrix.config.timeout }} | |
env: | |
_R_CHECK_CRAN_INCOMING_REMOTE_: false | |
_R_CHECK_FORCE_SUGGESTS_: ${{ runner.os != 'macOS' }} # Rmpi is not available on macOS. | |
ENABLE_statnet_TESTS: ${{ contains(matrix.config.flags, 'full') }} | |
run: covr::codecov(type=c("tests","examples")) | |
shell: Rscript {0} |