#
# This file is a part of the CaosDB Project.
#
# Copyright (C) 2019-2021 Indiscale GmbH <info@indiscale.com>
# Copyright (C) 2019 Henrik tom Wörden <h.tomwoerden@indiscale.com>
# Copyright (C) 2020 Daniel Hornung <d.hornung@indiscale.com>
# Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#

variables:
  CI_REGISTRY_IMAGE: $CI_REGISTRY/caosdb/src/caosdb-clib/testenv:latest

image: $CI_REGISTRY_IMAGE

stages:
  - setup
  - test
  - deploy

# Build a docker image in which tests for this repository can run
build-testenv:
  tags: [ cached-dind ]
  image: docker:20.10
  stage: setup
  script:
    - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
      # use here general latest or specific branch latest...
    - docker pull $CI_REGISTRY_IMAGE|| true
    - docker build 
      -f .docker/Dockerfile
      --pull
      --cache-from $CI_REGISTRY_IMAGE
      -t $CI_REGISTRY_IMAGE .
    - docker push $CI_REGISTRY_IMAGE

# formatting with clang-format
code_style:
  tags: [ docker ]
  stage: test
  script:
    - clang-format-11 --dry-run --verbose **/*.cpp **/*.h **/*.h.in
  allow_failure: true

# cmocka tests
test:
  tags: [ docker ]
  stage: test
  script:
    - mkdir build
    - cd build
    - cmake -DCMAKE_BUILD_TYPE=Debug ..
    - cmake --build . --target unit_test_coverage

# Build the sphinx documentation and make it ready for deployment by Gitlab Pages
# Special job for serving a static website. See https://docs.gitlab.com/ee/ci/yaml/README.html#pages
pages:
  tags: [ docker ]
  stage: deploy
  only:
    refs:
      - /^release-.*$/i
      - master
  script:
    - mkdir -p build
    - cd build
    - cmake ..
    - cmake --build . --target doc-sphinx
    - cp -r doc/sphinx_out ../public
  artifacts:
    paths:
      - public