image: rocker/verse:latest
stages:
    - build
    - check
    - test
    - deploy

before_script:
    - if [ -e .gitlab-ci/apt-script.cl ]; then ./.gitlab-ci/apt-script.cl; fi
    - if [ -e .gitlab-ci/gitlab-com.R ]; then R < .gitlab-ci/gitlab-com.R; fi
    - R --vanilla -e 'install.packages("remotes", repos = "https://cloud.r-project.org/")'
    - R --vanilla -e 'remotes::install_gitlab("fvafrcu/packager")'
    - R --vanilla -e 'packager::install_deps(path = ".", repos = "https://cloud.r-project.org/")'

build_and_check:
  stage: build
  script:
      # without --no-manual I get 
         # LaTeX errors when creating PDF version.
         # This typically indicates Rd problems.
         # LaTeX errors found:
         # ! Font TS1/cmr/m/n/10=tcrm1000 at 10.0pt not loadable: Metric (TFM) file not fo
         # und.
         # <to be read again> 
         #                    relax 
         # l.23 building and checking a package).}
      # so:
      - R CMD build --no-manual --no-build-vignettes . &&  R CMD check --no-build-vignettes --no-manual $(ls *.tar.gz)
      # The later needs the desc-package but is more robst as it constructs the
      # file to be checked from the file DESCRIPTION
      #- R --vanilla -e 'remotes::install_git("https://gitlab.com/fvafrCU/packager")' && R CMD build . &&  R --vanilla -e 'system(paste0("R CMD check ", desc::desc_get("Package"), "_", sub("'", "", desc::desc_get_version()), ".tar.gz"))'


packager:
  stage: check
  script:  
    - R --vanilla -e 'packager::rcmdcheck_and_log(".", build_args = c("--no-manual", "--no-build-vignettes"))'

      
coverage:
  stage: test
  script: 
    - R --vanilla -e 'install.packages("covr", repos = "https://cloud.r-project.org/"); covr::package_coverage()'
  coverage: '/^.*\s*Coverage:\s*\d+.\d+\%$/'

pages:
  stage: deploy
  script:
  - mkdir .public
  - cp -r * .public
  - mv .public public
  artifacts:
    paths:
    - public
  only:
  - master
