image: rocker/geospatial:latest

variables:
  R_LIBS_USER: "ci/lib"

cache:
  key: global-cache
  paths:
      - ci/lib/

stages:
  - build
  - test
  - pkgdown
  - pkgdown-move
  - deploy

building:
  stage: build
  script:
    - mkdir -p -m777 $R_LIBS_USER
    - Rscript -e '.libPaths(c(Sys.getenv("R_LIBS_USER"), .libPaths()));remotes::install_deps(dependencies = TRUE, upgrade = "always")'
    - Rscript -e '.libPaths(c(Sys.getenv("R_LIBS_USER"), .libPaths()));remotes::install_cran(c("pkgdown"), upgrade = "always")'
    - Rscript -e '.libPaths(c(Sys.getenv("R_LIBS_USER"), .libPaths()));devtools::check()'

# To have the coverage percentage appear as a gitlab badge follow these
# instructions:
# https://docs.gitlab.com/ee/user/project/pipelines/settings.html#test-coverage-parsing
# The coverage parsing string is
# Coverage: \d+\.\d+

coverage:
    stage: test
    allow_failure: true
    when: on_success
    only:
        - master
        - dev
        - test-ci
    script:
        - Rscript -e '.libPaths(c(Sys.getenv("R_LIBS_USER"), .libPaths()));covr::gitlab(quiet = FALSE);'
    artifacts:
        paths:
            - public
        expire_in: 30 days


# To produce a code coverage report as a GitLab page see
# https://about.gitlab.com/2016/11/03/publish-code-coverage-report-with-gitlab-pages/



integration:
    stage: pkgdown
    allow_failure: true
    when: on_success
    only:
        - master
        - dev
        - test-ci
    script:
        - Rscript -e '.libPaths(c(Sys.getenv("R_LIBS_USER"), .libPaths()));remotes::install_local();pkgdown::build_site()'
    artifacts:
        paths:
            - docs
        expire_in: 30 days


integration-dev:
    stage: pkgdown-move
    dependencies:
        - integration
    only:
        - dev
    script:
        - mkdir -p public/dev
        - cp -r docs/* public/dev
    artifacts:
        paths:
            - public
        expire_in: 30 days

integration-master:
    stage: pkgdown-move
    dependencies:
        - integration
    only:
        - master
    script:
        - mkdir -p public
        - cp -r docs/* public
    artifacts:
        paths:
            - public
        expire_in: 30 days

pages:
    stage: deploy
    script:
        - echo "deployment with cache ?"
    artifacts:
        paths:
            - public
    only:
        - master
        - dev
        - test-ci