stages:
  - test
  - docs
  - deploy

before_script:
  # workaround for https://github.com/JuliaDocs/Documenter.jl/issues/686
  - apt-get -qq update; apt-get -y install git
  - mkdir -p /root/.ssh && ssh-keyscan -H -t rsa git.km3net.de >> /root/.ssh/known_hosts

.script:
  script:
    - |
      julia -e '
        using Pkg
        Pkg.update()
        Pkg.Registry.add(RegistrySpec(url = "https://git.km3net.de/common/julia-registry"))'
      julia --project=@. -e '
        using Pkg
        Pkg.build()
        Pkg.test(coverage=true)'

.coverage:
  coverage: /Test coverage (\d+\.\d+%)/
  after_script:
    - |
      julia -e '
        using Pkg
        Pkg.update()
        Pkg.Registry.add(RegistrySpec(url = "https://git.km3net.de/common/julia-registry"))
        Pkg.add("Coverage")
        using Coverage
        c, t = get_summary(process_folder())
        using Printf
        @printf "Test coverage %.2f%%\n" 100c / t'

Julia 1.6:
  image: docker.km3net.de/base/julia:1.6
  stage: test
  extends:
    - .script
    - .coverage

Julia 1.8:
  image: docker.km3net.de/base/julia:1.8
  stage: test
  extends:
    - .script
    - .coverage

Julia 1.9:
  image: docker.km3net.de/base/julia:1.9
  stage: test
  extends:
    - .script
    - .coverage


docs:
  image: docker.km3net.de/base/julia:1.9-tex
  stage: docs
  script:
    - |
      julia -e '
        using Pkg
        Pkg.update()
        Pkg.Registry.add(RegistrySpec(url = "https://git.km3net.de/common/julia-registry"))'
    - |
      julia --project=docs -e '
        using Pkg
        Pkg.update()
        Pkg.develop(PackageSpec(path=pwd()))
        Pkg.instantiate()
        using Documenter: doctest
        using KM3io
        doctest(KM3io)
        include("docs/make.jl")'
#  only:
#    - main
#    - tags

#register:
#  image: docker.km3net.de/base/julia:1.8
#  stage: deploy
#  script:
#    - |
#      julia --project=. -e '
#        using Pkg
#        Pkg.update()
#        Pkg.Registry.add(RegistrySpec(url = "https://git.km3net.de/common/julia-registry"))
#        Pkg.add("LocalRegistry")
#        using LocalRegistry
#        register(KM3io; registry="KM3NeT", create_gitlab_mr=true)
#        '
#  only:
#    variables:
#      - $CI_COMMIT_TAG =~ /^v\d+.\d+.\d+-?.*$/
