Skip to content
Snippets Groups Projects
.gitlab-ci.yml 10.9 KiB
Newer Older
#####################################################################################
# (c) Copyright 1998-2020 CERN for the benefit of the LHCb and ATLAS collaborations #
#                                                                                   #
# This software is distributed under the terms of the Apache version 2 licence,     #
# copied verbatim in the file "LICENSE".                                            #
#                                                                                   #
# In applying this licence, CERN does not waive the privileges and immunities       #
# granted to it by virtue of its status as an Intergovernmental Organization        #
# or submit itself to any jurisdiction.                                             #
#####################################################################################
variables:
  LCG_VERSION: "101"
  CMAKE_GENERATOR: 'Ninja' # default build system
  NO_LBLOGIN: "1" # prevent lbdocker containers to start LbLogin/LbEnv
  TARGET_BRANCH: master

# All the configuration
default:
  image: gitlab-registry.cern.ch/lhcb-core/lbdocker/centos7-build
  before_script:
    # Add Ninja and CMake to the PATH
    - export PATH="/cvmfs/sft.cern.ch/lcg/contrib/CMake/3.18.3/Linux-x86_64/bin:/cvmfs/sft.cern.ch/lcg/contrib/ninja/1.10.0/Linux-x86_64:$PATH"
    - export CCACHE_DIR=$PWD/.ccache

# Job templates
.build: &template_build
    - git clone https://gitlab.cern.ch/lhcb-core/lcg-toolchains.git
    - cmake --version
    - cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=lcg-toolchains/LCG_${LCG_VERSION}/${CI_JOB_NAME}.cmake -DGAUDI_USE_INTELAMPLIFIER:BOOL=TRUE -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
    - ccache -z
    # pre-heat ccache cache for GaudiKernel
    - jobs=$(nproc)
    - while [[ $jobs -ge 1 ]] ; do
    -   cmake --build build -j $jobs --target GaudiKernel && break || true
    -   jobs=$(( $jobs / 2 ))
    - done
    # build from scratch
    - cmake --build build --target clean
    - cmake --build build 2>&1 | tee build/build.log
    - ccache -s
      - build
      - lcg-toolchains
  cache:
    key: "$CI_JOB_NAME-$CI_COMMIT_REF_SLUG"
    paths:
      - .ccache
Rosen Matev's avatar
Rosen Matev committed

.build-check: &template_build_check
  allow_failure: true

.test: &template_test
Marco Clemencic's avatar
Marco Clemencic committed
  script:
    - find build -type f -exec touch -d $(date +@%s) \{} \; # not to re-run cmake
    - cd build
    - if ctest -T test -j $(nproc) --repeat until-pass:3 --no-compress-output ; then result=success ; else result=failure ; fi
    - cp Testing/$(head -1 Testing/TAG)/Test.xml ..
    - cd ..
    - xsltproc ci-utils/CTest2JUnit.xslt Test.xml > results.xml
    - echo "Test results can be browsed at https://lhcb-nightlies.web.cern.ch/utils/test_report?url=${CI_PROJECT_URL}/-/jobs/${CI_JOB_ID}/artifacts/raw/Test.xml"
    - test "$result" = "success"
      - Test.xml
    reports:
      junit:
        - results.xml
.test_headers: &template_test_headers
  tags:
    - cvmfs
  script:
    - export CCACHE_DIR=$PWD/.ccache_headers
    - find build -type f -exec touch -d $(date +@%s) \{} \; # not to re-run cmake
    - ccache -z
    - cmake --build build --target test_public_headers_build 2>&1 | tee build/test_public_headers_build.log
    - ccache -s
  artifacts:
    paths:
      - build/test_public_headers_build.log
    when: always
    expire_in: 1 week
  cache:
    key: "$CI_JOB_NAME-$CI_COMMIT_REF_SLUG"
    paths:
      - .ccache_headers

x86_64-centos7-gcc11-opt:
  <<: *template_build
x86_64-centos7-gcc11-dbg:
  <<: *template_build

view-gcc8:
  <<: *template_build
Rosen Matev's avatar
Rosen Matev committed
  script:
    - . /cvmfs/sft.cern.ch/lcg/views/LCG_${LCG_VERSION}/x86_64-centos7-gcc8-opt/setup.sh
    - cmake --version
    - cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
    # pre-heat ccache cache for GaudiKernel
    - jobs=$(nproc)
    - while [[ $jobs -ge 1 ]] ; do
    -   cmake --build build -j $jobs --target GaudiKernel && break || true
    -   jobs=$(( $jobs / 2 ))
    - done
    # build from scratch
    - cmake --build build --target clean
    - cmake --build build 2>&1 | tee build/build.log
    - ccache -s
  <<: *template_build
  variables:
    BINARY_TAG: x86_64_v2-centos7-gcc11-opt
    - . /cvmfs/lhcb.cern.ch/lib/LbEnv
    - cmake --version
    - lb-project-init --overwrite
    - ccache -z
    - mkdir build.${BINARY_TAG}
    # pre-heat ccache cache for GaudiKernel
    - jobs=$(nproc)
    - while [[ $jobs -ge 1 ]] ; do
    -   make BUILDFLAGS=-j$jobs GaudiKernel && break || true
    -   jobs=$(( $jobs / 2 ))
    - done
    # build from scratch
    - make clean
    - make 2>&1 | tee build.${BINARY_TAG}/build.log
    - ccache -s
  artifacts:
      - build.${BINARY_TAG}
x86_64-centos7-gcc11-opt:test:
  <<: *template_test
  needs:
    - job: "x86_64-centos7-gcc11-opt"
      artifacts: true
x86_64-centos7-gcc11-opt:test_headers:
  <<: *template_test_headers
  needs:
    - job: "x86_64-centos7-gcc11-opt"
      artifacts: true

x86_64-centos7-gcc11-dbg:test:
  <<: *template_test
    - job: "x86_64-centos7-gcc11-dbg"
      artifacts: true
x86_64-centos7-gcc11-dbg:test_headers:
  <<: *template_test_headers
  needs:
    - job: "x86_64-centos7-gcc11-dbg"
      artifacts: true

view-gcc8:test:
  <<: *template_test
  needs:
    - job: "view-gcc8"
      artifacts: true
    - . /cvmfs/sft.cern.ch/lcg/views/LCG_${LCG_VERSION}/x86_64-centos7-gcc8-opt/setup.sh
  <<: *template_test
    - job: "lhcb-gcc11"
      artifacts: true
    BINARY_TAG: x86_64_v2-centos7-gcc11-opt
    - . /cvmfs/lhcb.cern.ch/lib/LbEnv
    - lb-project-init --overwrite
    - find build.${BINARY_TAG} -type f -exec touch -d $(date +@%s) \{} \; # not to re-run cmake
    - if make test ARGS="-j $(nproc) --repeat until-pass:3 --no-compress-output" ; then result=success ; else result=failure ; fi
    - cp build.${BINARY_TAG}/Testing/$(head -1 build.${BINARY_TAG}/Testing/TAG)/Test.xml .
    - mv build.${BINARY_TAG}/html .
    - xsltproc ci-utils/CTest2JUnit.xslt Test.xml > results.xml
    - echo "Test results can be browsed at https://lhcb-nightlies.web.cern.ch/utils/test_report?url=${CI_PROJECT_URL}/-/jobs/${CI_JOB_ID}/artifacts/raw/Test.xml"
    - test "$result" = "success"
  artifacts:
    paths:
      - Test.xml
      - html
    reports:
      junit:
        - results.xml
    when: always
    expire_in: 1 day

### Check build outputs
x86_64-centos7-gcc11-opt:build-check:
  <<: *template_build_check
  needs:
    - job: "x86_64-centos7-gcc11-opt"
      artifacts: true
x86_64-centos7-gcc11-dbg:build-check:
  <<: *template_build_check
    - job: "x86_64-centos7-gcc11-dbg"
      artifacts: true
x86_64-centos7-gcc11-opt:build-headers-check:
  <<: *template_build_check
  variables:
    LOG: build/test_public_headers_build.log
  needs:
    - job: "x86_64-centos7-gcc11-opt:test_headers"
      artifacts: true

x86_64-centos7-gcc11-dbg:build-headers-check:
  <<: *template_build_check
  variables:
    LOG: build/test_public_headers_build.log
  needs:
    - job: "x86_64-centos7-gcc11-dbg:test_headers"
      artifacts: true

view-gcc8:build-check:
  <<: *template_build_check
  needs:
    - job: "view-gcc8"
      artifacts: true

lhcb-gcc11:build-check:
  <<: *template_build_check
  needs:
    - job: "lhcb-gcc11"
      artifacts: true
  variables:
    BINARY_TAG: x86_64_v2-centos7-gcc11-opt
  script:
    - ci-utils/build-check build.${BINARY_TAG}/build.log

### Misc checks
x86_64-centos7-gcc11-opt:check-unused:
    - job: "x86_64-centos7-gcc11-opt"
      artifacts: true
  script:
    - ci-utils/check-sources build/build.ninja
  allow_failure: true

pre-commit-checks:
  image: registry.cern.ch/docker.io/library/python:3.8
  variables:
    PRE_COMMIT_HOME: ${CI_PROJECT_DIR}/.cache/pre-commit
  cache:
    paths:
      - ${PRE_COMMIT_HOME}
  before_script:
    - |
      python -m venv ${CI_PROJECT_DIR}/.cache/pre-commit-venv
      . ${CI_PROJECT_DIR}/.cache/pre-commit-venv/bin/activate
      pip install pre-commit
      git fetch origin $TARGET_BRANCH
      git config user.name "Gitlab CI"
      git config user.email "noreply@cern.ch"
    - |
      if ! pre-commit run --show-diff-on-failure --from-ref FETCH_HEAD --to-ref HEAD ; then
        echo ""
        echo "Generating patch file..."
        git commit -a -m "pre-commit fixes
        
      patch generated by ${CI_JOB_URL}" > /dev/null
        git format-patch HEAD~
        cat <<EOF
      =======================================
       You can apply these changes with:

          curl ${CI_JOB_URL}/artifacts/raw/0001-pre-commit-fixes.patch | git am

      =======================================
      EOF
        exit 1
      fi
  artifacts:
    paths:
      - 0001-pre-commit-fixes.patch
    when: on_failure

check-copyright:
  image: gitlab-registry.cern.ch/ci-tools/ci-worker:cc7
  script:
    - curl -o lb-check-copyright "https://gitlab.cern.ch/lhcb-core/LbDevTools/-/raw/master/LbDevTools/SourceTools.py?inline=false"
    - python lb-check-copyright --exclude lhcbproject.yml origin/${TARGET_BRANCH}

website:
  image: python
  script:
    - rm -rf public
    - mkdir -p public
    - cd docs
    - pip install -r source/requirements.txt
    - make html
    - cp -a build/html/. ../public/.
  artifacts:
    paths:
      - public
    expire_in: 1 day

doxygen:
  tags:
    - cvmfs
  needs:
    - job: "view-gcc8"
      artifacts: true
  script:
    - . /cvmfs/sft.cern.ch/lcg/views/LCG_${LCG_VERSION}/x86_64-centos7-gcc8-opt/setup.sh
    - find build -type f -exec touch -d $(date +@%s) \{} \; # not to re-run cmake
    - cmake --build build --target doc
    - rm -rf public
    - mkdir -p public/doxygen
    - cp -r GaudiRelease/web_helpers/. public/doxygen/.
    - mv build/doxygen/html ${CI_COMMIT_REF_SLUG}
    - zip -r -q public/doxygen/${CI_COMMIT_REF_SLUG}.zip ${CI_COMMIT_REF_SLUG}

  artifacts:
    paths:
      - public
    expire_in: 1 day


# see https://gitlab.cern.ch/gitlabci-examples/deploy_eos for the details
# of the configuration
deploy-website:
  needs:
    - job: "website"
      artifacts: true
    - job: "doxygen"
      artifacts: true
  rules:
    - if: $CI_COMMIT_BRANCH == "master"
    - if: $CI_COMMIT_TAG
  image: gitlab-registry.cern.ch/ci-tools/ci-web-deployer:latest
  script:
    - test -z "$EOS_ACCOUNT_USERNAME" -o -z "$EOS_ACCOUNT_PASSWORD" -o -z "$EOS_PATH" && exit 0 || true
    # Script that performs the deploy to EOS. Makes use of the variables defined in the project
    # It will copy the generated content to the folder in EOS
    - export CI_OUTPUT_DIR=public/
    - deploy-eos
  # do not run any globally defined before_script or after_script for this step
  before_script: []
  after_script: []