Skip to content

Commit

Permalink
Updated the GitHub workflows and/or the README file to the latest ver…
Browse files Browse the repository at this point in the history
…sions.
  • Loading branch information
krivit committed Nov 6, 2024
1 parent ec93685 commit 4cbcc71
Showing 1 changed file with 93 additions and 73 deletions.
166 changes: 93 additions & 73 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@
#
# ubsan: compile with -fsanitize=undefined and fail on any errors identified.
#
# debug: compile package with -DDEBUG and -UNDEBUG
#
# covr: run in covr mode may be used with 'full' but probably not with others.
#
#
# Typical public, private, and release configurations are provided in the variables below.

on: [push, pull_request]

Expand All @@ -35,19 +40,23 @@ name: R-CMD-check
env:
PUBLIC: ''
PRIVATE: ''
PUBLIC_CONFIG: '{"config":[
{"os":"windows-latest", "r":"release", "timeout":360, "flags":"binaries"},
{"os":"macOS-latest", "r":"release", "timeout":360, "flags":"binaries, ubsan"},
{"os":"ubuntu-latest", "r":"release", "timeout":360, "flags":"full, ubsan, debug"},
{"os":"ubuntu-latest", "r":"devel", "timeout":360, "flags":"vignettes, remote"},
{"os":"ubuntu-latest", "r":"release", "timeout":360, "flags":"full, covr"}]}'
RELEASE_CONFIG: '{"config":[
{"os":"windows-latest", "r":"release", "timeout":360, "flags":"binaries, vignettes, remote, strict"},
{"os":"macOS-latest", "r":"release", "timeout":360, "flags":"binaries, ubsan, vignettes, remote, strict"},
{"os":"ubuntu-latest", "r":"release", "timeout":360, "flags":"full, ubsan, debug, strict"},
{"os":"ubuntu-latest", "r":"devel", "timeout":360, "flags":"vignettes, remote, strict"},
{"os":"ubuntu-latest", "r":"release", "timeout":360, "flags":"full, covr, strict"}]}'
PRIVATE_CONFIG: '{"config":[
{"os":"ubuntu-latest", "r":"release", "timeout":10, "flags":"none"}
]}'

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:
Expand Down Expand Up @@ -85,24 +94,16 @@ jobs:
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"}]}'
config='${{ env.PUBLIC_CONFIG }}'
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"}
]}'
config='${{ env.PRIVATE_CONFIG }}'
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"
config="${config//$'\r'/' '}"
config="${config//$'\n'/' '}"
echo "matrix=$config" >> $GITHUB_OUTPUT
R-CMD-check:
needs: Set-Matrix-Private
Expand All @@ -118,8 +119,8 @@ jobs:
matrix: ${{fromJson(needs.Set-Matrix-Private.outputs.matrix)}}

env:
HOMEBREW_NO_INSTALL_CLEANUP: 1
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.
Expand All @@ -133,60 +134,42 @@ jobs:
fi
shell: bash

- uses: actions/checkout@v2
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-r@v1
- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true
r-version: ${{ matrix.config.r }}

- name: Install GhostScript (on Linux if running vignettes)
- name: Install tidy (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
/usr/bin/sudo DEBIAN_FRONTEND=noninteractive apt-get install -y tidy
shell: bash

- uses: r-lib/actions/setup-pandoc@v1
- uses: r-lib/actions/setup-pandoc@v2

- 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}
uses: r-lib/actions/setup-tinytex@v2

- name: Cache R packages
if: runner.os != 'Windows'
uses: actions/cache@v2
- uses: r-lib/actions/setup-r-dependencies@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}
extra-packages: |
any::rcmdcheck
any::covr
any::V8
any::xml2
needs: |
check
coverage
- name: Install tinytex (R)
if: contains(matrix.config.flags, 'vignettes')
run: |
remotes::install_cran("tinytex")
if(!requireNamespace("tinytex", quietly = TRUE)) pak::pkg_install("tinytex")
tinytex:::install_yihui_pkgs()
tinytex::tlmgr_install("makeindex")
shell: Rscript {0}

- name: Build
Expand All @@ -198,7 +181,7 @@ jobs:

- name: Upload build results
if: contains(matrix.config.flags, 'binaries') && !failure()
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: ${{ runner.os }}-r${{ matrix.config.r }}-binaries
path: binaries
Expand All @@ -212,12 +195,13 @@ jobs:
if: contains(matrix.config.flags, 'covr') == false
timeout-minutes: ${{ matrix.config.timeout }}
env:
_R_CHECK_CRAN_INCOMING_REMOTE_: false
_R_CHECK_CRAN_INCOMING_REMOTE_: ${{ contains(matrix.config.flags, 'remote') }}
_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') }}
SET_DEBUG: ${{ contains(matrix.config.flags, 'debug') }}
run: |
if(Sys.getenv("R_VIGNETTES") == "true"){
check_args <- c("--as-cran")
Expand All @@ -227,32 +211,51 @@ jobs:
build_args <- c("--no-manual", "--no-build-vignettes")
}
if(Sys.getenv("ENABLE_statnet_TESTS") == "true"){
check_args <- c(check_args, "--run-donttest")
}
error_on <- if(Sys.getenv("FAIL_ON_WARN") == "true") "warning" else "error"
extra_flags <- c()
if(Sys.getenv("USE_UBSAN") == "true"){
Sys.setenv(PKG_LIBS="-fsanitize=undefined",
PKG_CFLAGS="-fsanitize=undefined",
UBSAN_OPTIONS="print_stacktrace=1")
extra_flags <- c(extra_flags, "-fsanitize=undefined")
Sys.setenv(UBSAN_OPTIONS=paste(Sys.getenv("UBSAN_OPTIONS"), "print_stacktrace=1"))
}
if(Sys.getenv("SET_DEBUG") == "true") extra_flags <- c(extra_flags, "-UNDEBUG", "-DDEBUG")
# Before R 4.3.0, R itself was not compliant.
if(getRversion() >= "4.3") extra_flags <- c(extra_flags, "-Wstrict-prototypes")
Sys.setenv(PKG_LIBS=paste(c(Sys.getenv("PKG_LIBS"), extra_flags), collapse=" "),
PKG_CXXFLAGS=paste(c(Sys.getenv("PKG_CXXFLAGS"), extra_flags), collapse=" "),
PKG_CFLAGS=paste(c(Sys.getenv("PKG_CFLAGS"), extra_flags), collapse=" "))
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')
# NB: xargs -r only works in GNU, so not on MacOS.
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 ]
find check/ -name '*.Rout' -print0 > check/Rout.list
if [ -s check/Rout.list ]
then
echo "UBSAN errors:" >&2
cat check/ubsan.err >&2
exit 1
cat check/Rout.list | xargs -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
fi
shell: bash

- name: Upload check results
if: contains(matrix.config.flags, 'covr') == false && failure()
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
path: |
Expand All @@ -266,5 +269,22 @@ jobs:
_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"))
run: |
cov <- covr::package_coverage(
type=c("tests", "examples"),
quiet = FALSE,
clean = FALSE,
install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package")
)
covr::to_cobertura(cov)
shell: Rscript {0}

- name: Upload coverage results
if: contains(matrix.config.flags, 'covr')
uses: codecov/codecov-action@v4
with:
fail_ci_if_error: ${{ github.event_name != 'pull_request' && true || false }}
file: ./cobertura.xml
plugin: noop
disable_search: true
token: ${{ secrets.CODECOV_TOKEN }}

0 comments on commit 4cbcc71

Please sign in to comment.