Skip to content

Commit

Permalink
Enable GH Actions CI/CD testing (#99)
Browse files Browse the repository at this point in the history
Merging to start use of tests during CD. No changes to `rgrass` itself were made.

This PR squashes several individual commits:

* Add initial testthat suite

* Setup test helper for mac and linux

* Add gisBase to initGRASS

* Use grassdb at /tmp

* Add read_VECT test

* Expand initGRASS tests to include gmeta

* Add test for getLocationProj

* Use GISBASE for MacOS helper

* Update CRAN badge

* Use ignore.stderr = TRUE in vector related tests

* Add test coverage

* Use r-lib/actions/setup-r@v2 in releasebranch

* Use RSPM but build terra from source due to conflict with version from ubuntugis PPA

* Expand matrix of grass docker images used in tests

* Separate read_VECT and write_VECT in tests

* Use SpatRaster instead of SGDF to test initGRASS

* Add basic tests for execGRASS

* Expanded initGRASS tests for locking

* Unlink .gislock at end of test

* Add tests for gmeta options

* Add test for legacyExecOption

* Add test for useInternOption

* Add test for stop_on_no_flags_parasOption

* Disable sp related tests until issue resolved in terms of sp::CRS on the GRASS GIS Docker release branch
  • Loading branch information
stevenpawley authored Jan 1, 2025
1 parent 0de0394 commit 4b86ba8
Show file tree
Hide file tree
Showing 18 changed files with 895 additions and 9 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ _pkgdown.yml
^.*\.Rproj$
^\.Rproj\.user$
^\.github$
^codecov\.yml$
52 changes: 52 additions & 0 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:

name: R-CMD-check

permissions: read-all

jobs:
R-CMD-check:
strategy:
matrix:
os: [ubuntu-22.04, ubuntu-24.04]

runs-on: ${{ matrix.os }}

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v4

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

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- name: Install common system dependencies
run: |
sudo apt-get update
sudo apt-get install -y grass-dev libgdal-dev libudunits2-dev libharfbuzz-dev libfribidi-dev
- name: Download test dataset
run: |
wget https://grass.osgeo.org/sampledata/north_carolina/nc_basic_spm_grass7.zip -O /tmp/nc_basic_spm_grass7.zip
unzip /tmp/nc_basic_spm_grass7.zip -d /tmp/grassdb
rm /tmp/nc_basic_spm_grass7.zip
- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck, any::terra
needs: check

- uses: r-lib/actions/check-r-package@v2
with:
upload-snapshots: true
build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")'
74 changes: 74 additions & 0 deletions .github/workflows/check-releasebranch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:

name: releasebranch_8_4-ubuntu

permissions: read-all

jobs:
R-CMD-check-releasebranch:
runs-on: ubuntu-latest
strategy:
matrix:
container: [
"osgeo/grass-gis:releasebranch_8_4-ubuntu",
"osgeo/grass-gis:main-ubuntu"
]

container:
image: ${{ matrix.container }}
options: --privileged

steps:
- uses: actions/checkout@v4

- name: Install system deps
run: |
apt-get update
apt-get install -y \
libudunits2-dev \
libharfbuzz-dev \
libfribidi-dev \
gdal-bin \
libmysqlclient-dev \
libfontconfig1-dev \
qpdf \
pandoc \
pandoc-citeproc
- name: Install R
run: |
wget -qO- https://cloud.r-project.org/bin/linux/ubuntu/marutter_pubkey.asc | tee -a /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc
echo "deb https://cloud.r-project.org/bin/linux/ubuntu jammy-cran40/" | tee -a /etc/apt/sources.list
apt-get update
apt-get install -y r-base-dev
- name: Configure RSPM in .Renviron
run: |
echo 'options(repos = c(CRAN = "https://packagemanager.posit.co/cran/__linux__/jammy/latest"))' >> ~/.Rprofile
echo 'options(HTTPUserAgent = sprintf("R/%s R (%s)", getRversion(), paste(getRversion(), R.version["platform"], R.version["arch"], R.version["os"])))' >> ~/.Rprofile
echo 'options(Ncpus=parallel::detectCores())' >> ~/.Rprofile
- name: Install R dependencies
run: |
R -e "install.packages(c('remotes', 'rcmdcheck'))"
R -e "remotes::install_deps(dependencies = TRUE)"
R -e "install.packages('terra', repos = 'https://cloud.r-project.org/', type = 'source')"
- name: Download test dataset
run: |
wget https://grass.osgeo.org/sampledata/north_carolina/nc_basic_spm_grass7.zip -O /tmp/nc_basic_spm_grass7.zip
unzip /tmp/nc_basic_spm_grass7.zip -d /tmp/grassdb
rm /tmp/nc_basic_spm_grass7.zip
# - name: Run R CMD check
# run: |
# R -e "rcmdcheck::rcmdcheck(args = c('--no-manual', '--no-build-vignettes'), error_on = 'error', check_dir = 'check')"

- uses: r-lib/actions/check-r-package@v2
with:
upload-snapshots: true
66 changes: 66 additions & 0 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:

name: test-coverage.yaml

permissions: read-all

jobs:
test-coverage:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- name: Install common system dependencies
run: |
sudo apt-get update
sudo apt-get install -y grass-dev libgdal-dev libudunits2-dev libharfbuzz-dev libfribidi-dev
- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::covr, any::xml2, any::terra
needs: coverage

- name: Test coverage
run: |
cov <- covr::package_coverage(
quiet = FALSE,
clean = FALSE,
install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package")
)
covr::to_cobertura(cov)
shell: Rscript {0}

- uses: codecov/codecov-action@v4
with:
# Fail if error if not on PR, or if on PR and token is given
fail_ci_if_error: ${{ github.event_name != 'pull_request' || secrets.CODECOV_TOKEN }}
file: ./cobertura.xml
plugin: noop
disable_search: true
token: ${{ secrets.CODECOV_TOKEN }}

- name: Show testthat output
if: always()
run: |
## --------------------------------------------------------------------
find '${{ runner.temp }}/package' -name 'testthat.Rout*' -exec cat '{}' \; || true
shell: bash

- name: Upload test results
if: failure()
uses: actions/upload-artifact@v4
with:
name: coverage-test-failures
path: ${{ runner.temp }}/package
12 changes: 11 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,16 @@ Authors@R: c(
Description: An interface between the 'GRASS' geographical information system ('GIS') and 'R', based on starting 'R' from within the 'GRASS' 'GIS' environment, or running a free-standing 'R' session in a temporary 'GRASS' location; the package provides facilities for using all 'GRASS' commands from the 'R' command line. The original interface package for 'GRASS 5' (2000-2010) is described in Bivand (2000) <doi:10.1016/S0098-3004(00)00057-1> and Bivand (2001) <https://www.r-project.org/conferences/DSC-2001/Proceedings/Bivand.pdf>. This was succeeded by 'spgrass6' for 'GRASS 6' (2006-2016) and 'rgrass7' for 'GRASS 7' (2015-present). The 'rgrass' package modernizes the interface for 'GRASS 8' while still permitting the use of 'GRASS 7'.
Depends: R (>= 3.5.0)
Imports: stats, utils, methods, xml2
Suggests: terra (>= 1.6-16), sp (>= 0.9), knitr, rmarkdown, sf, stars, raster (>= 3.6-3), codetools
Suggests:
terra (>= 1.6-16),
sp (>= 0.9),
knitr,
rmarkdown,
sf,
stars,
raster (>= 3.6-3),
codetools,
testthat (>= 3.0.0)
VignetteBuilder: knitr
SystemRequirements: GRASS (>= 7)
License: GPL (>= 2)
Expand All @@ -22,3 +31,4 @@ BugReports: https://github.com/osgeo/rgrass/issues/
RoxygenNote: 7.3.2
Roxygen: list(markdown = TRUE)
Encoding: UTF-8
Config/testthat/edition: 3
7 changes: 3 additions & 4 deletions R/gmeta.R
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,9 @@ getLocationProj <- function(ignore.stderr = FALSE, g.proj_WKT = NULL) {
if (!g.proj_WKT) WKT2 <- FALSE
}
if (WKT2 && !old_proj) {
res <- paste(execGRASS("g.proj",
flags = c("w"), intern = TRUE,
ignore.stderr = ignore.stderr
), collapse = "\n")
res <- execGRASS("g.proj", flags = c("w"), intern = TRUE, ignore.stderr = TRUE)
res <- paste(res, collapse = "\n")

if (substr(res, 1, 5) != "ERROR") {
if (nchar(res) == 0L) {
res <- paste(execGRASS("g.proj",
Expand Down
8 changes: 6 additions & 2 deletions R/vect_link.R
Original file line number Diff line number Diff line change
Expand Up @@ -171,24 +171,26 @@ vDataCount <- function(vname, layer, ignore.stderr = NULL) {
vect2neigh <- function(
vname, ID = NULL, ignore.stderr = NULL, remove = TRUE,
vname2 = NULL, units = "k") {

if (get.suppressEchoCmdInFuncOption()) {
inEchoCmd <- get.echoCmdOption()
tull <- set.echoCmdOption(FALSE)
}

if (is.null(ignore.stderr)) {
ignore.stderr <- get("ignore.stderr", envir = .GRASS_CACHE)
}
stopifnot(is.logical(ignore.stderr))

vinfo <- vInfo(vname)
types <- names(vinfo)[which(vinfo > 0)]

if (length(grep("areas", types)) == 0) {
stop("Vector object not of area type")
}

n <- vDataCount(vname, ignore.stderr = ignore.stderr)


if (!is.null(ID)) {
if (!is.character(ID)) stop("ID not character string")
# cmd <- paste(paste("v.info", .addexe(), sep=""),
Expand Down Expand Up @@ -222,9 +224,11 @@ vect2neigh <- function(
}
}
vname2_was_null <- FALSE

if (is.null(vname2)) {
pid <- as.integer(round(runif(1, 1, 1000)))
vname2 <- paste(vname, pid, sep = "")

tull <- execGRASS("g.remove",
type = "vector", name = vname2, flags = "f",
intern = TRUE, ignore.stderr = ignore.stderr
Expand Down Expand Up @@ -326,7 +330,7 @@ vect2neigh <- function(
if (remove) {
tull <- execGRASS("g.remove",
name = paste(vname2, vname2a, sep = ","), type = "vector",
intern = TRUE, ignore.stderr = ignore.stderr
intern = TRUE, ignore.stderr = ignore.stderr, flags = "f"
)
}

Expand Down
8 changes: 7 additions & 1 deletion R/vect_link_ng.R
Original file line number Diff line number Diff line change
Expand Up @@ -222,16 +222,21 @@ write_VECT <- function(x, vname, flags = "overwrite",
if (!(requireNamespace("terra", quietly = TRUE))) {
stop("terra required for SpatVector input")
}

stopifnot(is.logical(ignore.stderr), !is.na(ignore.stderr))

if (get.suppressEchoCmdInFuncOption()) {
inEchoCmd <- set.echoCmdOption(FALSE)
}

srcs <- getMethod("sources", "SpatVector")(x)

if (length(srcs) == 1L) {
tf <- srcs
} else {
tf <- ""
}

# exit when the source is a GRASS database layer already:
if (grepl("[/\\\\]head::[^/\\\\]+$", tf)) {
grass_layername <- regmatches(
Expand All @@ -254,7 +259,7 @@ write_VECT <- function(x, vname, flags = "overwrite",
if (!file.exists(tf)) {
tf <- tempfile(fileext = ".gpkg")
getMethod("writeVector", c("SpatVector", "character"))(x, filename = tf,
filetype = "GPKG", overwrite = TRUE)
filetype = "GPKG", options = NULL, overwrite = TRUE)
}

type <- NULL
Expand All @@ -267,6 +272,7 @@ write_VECT <- function(x, vname, flags = "overwrite",
flags = flags, input = tf, output = vname, type = type,
ignore.stderr = ignore.stderr
)

if (get.suppressEchoCmdInFuncOption()) {
tull <- set.echoCmdOption(inEchoCmd)
}
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# rgrass

[![CRAN](http://www.r-pkg.org/badges/version/rgrass)](https://cran.r-project.org/package=rgrass)
[![CRAN status](https://www.r-pkg.org/badges/version/rgrass)](https://CRAN.R-project.org/package=rgrass)
[![Codecov test coverage](https://codecov.io/gh/stevenpawley/rgrass/graph/badge.svg)](https://app.codecov.io/gh/stevenpawley/rgrass)

### Interface Between GRASS Geographical Information System and R

Expand Down
14 changes: 14 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
comment: false

coverage:
status:
project:
default:
target: auto
threshold: 1%
informational: true
patch:
default:
target: auto
threshold: 1%
informational: true
12 changes: 12 additions & 0 deletions tests/testthat.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This file is part of the standard setup for testthat.
# It is recommended that you do not modify it.
#
# Where should you do additional test configuration?
# Learn more about the roles of various files in:
# * https://r-pkgs.org/testing-design.html#sec-tests-files-overview
# * https://testthat.r-lib.org/articles/special-files.html

library(testthat)
library(rgrass)

test_check("rgrass")
Loading

0 comments on commit 4b86ba8

Please sign in to comment.