stages:
  - checks
  - deploy

default:
  tags: [docker]

image: rocker/geospatial:latest

variables:
  CACHE_CI: "$CI_PROJECT_DIR/ci"
  R_LIBS_USER: "$CACHE_CI/lib"

cache:
  paths:
    - $CACHE_CI

before_script:
  - mkdir -p $R_LIBS_USER
  - echo "R_LIBS='$R_LIBS_USER'" > .Renviron
  - R -q -e 'if (!require(remotes)) install.packages(c("remotes", "testthat"))'
  - R -q -e 'devtools::install(dependencies = TRUE)'

test_all:
  stage: checks
  script:
  - R -q -e 'testthat::test_local()'

check:
  variables:
    NOT_CRAN: "true"
  stage: checks
  script:
    - R -q -e 'remotes::update_packages("rcmdcheck")'
    - R -q -e 'rcmdcheck::rcmdcheck(args = "--no-manual", error_on = "error")'

pages:
  stage: deploy
  rules:
    - if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH
  script:
    - R -q -e 'fairify::build_site()'
  artifacts:
    paths:
      - public
