Skip to content
Snippets Groups Projects
.gitlab-ci.yml 4.69 KiB
Newer Older
#
# This file is a part of the CaosDB Project.
#
Daniel Hornung's avatar
Daniel Hornung committed
# Copyright (C) 2021-2022 Indiscale GmbH <info@indiscale.com>
# Copyright (C) 2021-2022 Daniel Hornung <d.hornung@indiscale.com>
Timm Fitschen's avatar
Timm Fitschen committed
# Copyright (C) 2021 Timm Fitschen <d.hornung@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:
Timm Fitschen's avatar
Timm Fitschen committed
  # this is the image where cpplib repo is present (artifact from pipeline in
  # caosdb-cpplib)
  CPPLIB_REGISTRY_IMAGE: $CI_REGISTRY/caosdb/src/caosdb-cpplib/testenv
  OCTAVELIB_REGISTRY_IMAGE: $CI_REGISTRY_IMAGE/testenv:$CI_COMMIT_REF_NAME
  CPPLIB_BRANCH: dev
Timm Fitschen's avatar
Timm Fitschen committed
  OCTAVEINTTEST_BRANCHES: https://gitlab.indiscale.com/api/v4/projects/121/repository/branches
  # For storing cross-job values
  DOTENV: custom.env

image: $OCTAVELIB_REGISTRY_IMAGE

stages:
  - setup
  - test
  - deploy

######## Setup ########

# Build a docker image in which tests for this repository can run
build-testenv:
  tags: [ cached-dind ]
  stage: setup
  image: docker:20.10
  script:
    - if [[ "$CI_COMMIT_REF_NAME" == "main" ]] ; then
         CPPLIB_BRANCH=main ;
      fi
Timm Fitschen's avatar
Timm Fitschen committed
    - DOCKER_BASE_IMAGE="${CPPLIB_REGISTRY_IMAGE}:${CPPLIB_BRANCH}"
    - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
    - docker pull "$OCTAVELIB_REGISTRY_IMAGE" || true
    - docker build
Timm Fitschen's avatar
Timm Fitschen committed
      --build-arg DOCKER_BASE_IMAGE=$DOCKER_BASE_IMAGE
Timm Fitschen's avatar
Timm Fitschen committed
      --file .docker/Dockerfile
      --cache-from "$OCTAVELIB_REGISTRY_IMAGE"
      --tag "$OCTAVELIB_REGISTRY_IMAGE" .
    - docker push "$OCTAVELIB_REGISTRY_IMAGE"


# Formatting with miss_hit
code_style_octave:
  tags: [ docker ]
  stage: test
  script:
    - mh_style -v
    - make style_octave
  allow_failure: true

code_style_cpp:
  tags: [ docker ]
  stage: test
  script:
    - make style_cpp
  allow_failure: true

unit_tests:
  tags: [ docker ]
  stage: test
  script:
    - octave -v
# Linting with miss_hit
linting_octave:
Timm Fitschen's avatar
Timm Fitschen committed
  tags: [ docker ]
  stage: test
  script:
    - make linting_octave
  allow_failure: true
Timm Fitschen's avatar
Timm Fitschen committed

# linting with clang-tidy and include-what-you-use
linting_cpp:
  tags: [ docker ]
  stage: test
  script:
    - make linting_cpp
  allow_failure: true
trigger_prepare:
  # Calculate the branch name
  tags: [ docker ]
  stage: deploy
  script:
    ## Determine the octaveinttest branch...
    # ... sync'ed f-branch (f-bar on octavelib requires f-bar on octaveinttest)...
    - if echo "$CI_COMMIT_REF_NAME" | grep -c "^f-" ; then
Timm Fitschen's avatar
Timm Fitschen committed
        if curl -o /dev/null -s -w "%{http_code}" $OCTAVEINTTEST_BRANCHES/$CI_COMMIT_REF_NAME | grep "404"; then
          OCTAVEINT_REF=dev ;
        else
          OCTAVEINT_REF=$CI_COMMIT_REF_NAME ;
        fi
      fi;
    # ... or use main if possible...
    - if [[ "$CI_COMMIT_REF_NAME" == "main" ]] ; then
        OCTAVEINT_REF=main ;
      fi
    # ... and fall-back to dev
    - OCTAVEINT_REF=${OCTAVEINT_REF:-dev}
    - F_BRANCH=$CI_COMMIT_REF_NAME

    # Write to dotenv
    - echo "OCTAVEINT_REF=${OCTAVEINT_REF}" >> "$DOTENV"
    - echo "F_BRANCH=${F_BRANCH}" >> "$DOTENV"
    - cat "$DOTENV"
  artifacts:
    reports:
      dotenv: "$DOTENV"
    expire_in: 1 day

# trigger the integration tests
trigger_inttest:
  stage: deploy
  needs: [ trigger_prepare ]
  inherit:
    variables:
      # List the variables that shall be inherited, which also means they will override any equally
      # named varibles in child pipelines.
      - TRIGGERED_BY_REPO
      - TRIGGERED_BY_REF
      - TRIGGERED_BY_HASH
      - OCTAVELIB_REGISTRY_IMAGE
  variables:
    # dotenv variables must be set again here.
    F_BRANCH: $F_BRANCH
  trigger:
    project: caosdb/src/caosdb-octaveinttest
    branch: $OCTAVEINT_REF
    strategy: depend
# 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
Timm Fitschen's avatar
Timm Fitschen committed
.pages_prepare: &pages_prepare
   tags: [ cached-dind ]
   stage: deploy
   script:
     - make doc
     - cp -r build/doc/html ./public

test_pages:
   <<: *pages_prepare
   except:
     refs:
       - main
   artifacts:
     paths:
       - public

pages:
   <<: *pages_prepare
   only:
     refs:
       - main
   artifacts:
     paths:
       - public