.gitlab-ci.yml 11.8 KiB
Newer Older
Tommaso Tocci's avatar
Tommaso Tocci committed
stages:
Alberto Miranda's avatar
Alberto Miranda committed
  - lint
Tommaso Tocci's avatar
Tommaso Tocci committed
  - build
  - test
  - docs
  - report
  - deploy
Tommaso Tocci's avatar
Tommaso Tocci committed

variables:
Alberto Miranda's avatar
Alberto Miranda committed
  SCRIPTS_DIR:                  "${CI_PROJECT_DIR}/scripts"
  CI_SCRIPTS_DIR:               "${CI_PROJECT_DIR}/scripts/ci"
  BUILD_PATH:                   "${CI_PROJECT_DIR}/gkfs/build"
  INSTALL_PATH:                 "${CI_PROJECT_DIR}/gkfs/install"
  INTEGRATION_TESTS_BIN_PATH:   "${CI_PROJECT_DIR}/gkfs/install/share/gkfs/tests/integration"
  COVERAGE_PATH:                "${CI_PROJECT_DIR}/gkfs/build/coverage"
  PYTEST:                       "${CI_PROJECT_DIR}/gkfs/install/share/gkfs/tests/integration/pytest-venv/bin/py.test"
  BATS:                         "${CI_PROJECT_DIR}/tests/scripts/bats/bin/bats"
  LD_LIBRARY_PATH:              "${CI_PROJECT_DIR}/deps/install/lib:${CI_PROJECT_DIR}/deps/install/lib64"
Tommaso Tocci's avatar
Tommaso Tocci committed
  # Configuration variables
  GKFS_LOG_LEVEL:               "100"
  GKFS_DAEMON_LOG_PATH:         "${CI_PROJECT_DIR}/logs/daemon.log"
  LIBGKFS_LOG:                  "all"
  LIBGKFS_LOG_OUTPUT:           "${CI_PROJECT_DIR}/logs/gkfs_client.log"
  GIT_SUBMODULE_STRATEGY:       recursive
Tommaso Tocci's avatar
Tommaso Tocci committed

Alberto Miranda's avatar
Alberto Miranda committed
# base image
Ramon Nou's avatar
Ramon Nou committed
image: gekkofs/core:0.9.2
Tommaso Tocci's avatar
Tommaso Tocci committed

Alberto Miranda's avatar
Alberto Miranda committed
################################################################################
## Validating
################################################################################
Alberto Miranda's avatar
Alberto Miranda committed
  stage: lint
Ramon Nou's avatar
Ramon Nou committed
  image: gekkofs/linter:0.9.2
Alberto Miranda's avatar
Alberto Miranda committed
    - ${SCRIPTS_DIR}/check_format.sh
      -s "${CI_PROJECT_DIR}/src"
      -i "${CI_PROJECT_DIR}/include"
      -v
Alberto Miranda's avatar
Alberto Miranda committed

################################################################################
## Building
################################################################################
gkfs:
  stage: build
Ramon Nou's avatar
Ramon Nou committed
  image: gekkofs/deps:0.9.2
Alberto Miranda's avatar
Alberto Miranda committed
  interruptible: true
Tommaso Tocci's avatar
Tommaso Tocci committed
  script:
Ramon Nou's avatar
Ramon Nou committed
    # Change config.hpp with sed to enable extra features
Ramon Nou's avatar
Ramon Nou committed
    - sed -i 's/constexpr auto use_atime = false;/constexpr auto use_atime = true;/g' "${CI_PROJECT_DIR}/include/config.hpp"
    - sed -i 's/constexpr auto use_ctime = false;/constexpr auto use_ctime = true;/g' "${CI_PROJECT_DIR}/include/config.hpp"
    - sed -i 's/constexpr auto use_mtime = false;/constexpr auto use_mtime = true;/g' "${CI_PROJECT_DIR}/include/config.hpp"
    - sed -i 's/constexpr auto use_link_cnt = false;/constexpr auto use_link_cnt = true;/g' "${CI_PROJECT_DIR}/include/config.hpp"
    - sed -i 's/constexpr auto use_blocks = false;/constexpr auto use_blocks = true;/g' "${CI_PROJECT_DIR}/include/config.hpp"
    - cmake --preset ci-coverage -DCOVERAGE_OUTPUT_DIR=${COVERAGE_PATH}
    - cmake --build ${BUILD_PATH} -j $(nproc) --target install
Alberto Miranda's avatar
Alberto Miranda committed
    # reduce artifacts size
    - ${CI_SCRIPTS_DIR}/trim_build_artifacts.sh ${BUILD_PATH}
Tommaso Tocci's avatar
Tommaso Tocci committed
  artifacts:
    paths:
Alberto Miranda's avatar
Alberto Miranda committed
      - ${BUILD_PATH}
      - ${INSTALL_PATH}
    expire_in: 1 week
Tommaso Tocci's avatar
Tommaso Tocci committed

Alberto Miranda's avatar
Alberto Miranda committed
gkfwd:
Tommaso Tocci's avatar
Tommaso Tocci committed
  stage: build
Ramon Nou's avatar
Ramon Nou committed
  image: gekkofs/deps:0.9.2
Alberto Miranda's avatar
Alberto Miranda committed
  interruptible: true
  needs: []
Tommaso Tocci's avatar
Tommaso Tocci committed
  script:
    - cmake --preset ci-forwarding-coverage
    - cmake --build ${BUILD_PATH} -j $(nproc) --target install
Alberto Miranda's avatar
Alberto Miranda committed
    # reduce artifacts size
    - ${CI_SCRIPTS_DIR}/trim_build_artifacts.sh ${BUILD_PATH}
Tommaso Tocci's avatar
Tommaso Tocci committed
  artifacts:
    paths:
      - ${BUILD_PATH}
      - ${INSTALL_PATH}
    expire_in: 1 week
Alberto Miranda's avatar
Alberto Miranda committed
################################################################################
## Testing
################################################################################

## == tests for scripts ====================
scripts:
  stage: test
Ramon Nou's avatar
Ramon Nou committed
  image: gekkofs/testing:0.9.2
  needs: []
  script:
    - mkdir -p ${BUILD_PATH}/tests/scripts
    - cd ${BUILD_PATH}/tests/scripts
Ramon Nou's avatar
Ramon Nou committed
    - ${BATS} -r ${CI_PROJECT_DIR}/tests/scripts/dl_dep.sh --formatter junit
    - ${BATS} -r ${CI_PROJECT_DIR}/tests/scripts/compile_dep.sh --formatter junit
  artifacts:
    expire_in: 1 week
    reports:
      junit: ${BUILD_PATH}/tests/scripts/report.xml


Alberto Miranda's avatar
Alberto Miranda committed
## == integration tests for gkfs ===========
gkfs:integration:
  stage: test
Ramon Nou's avatar
Ramon Nou committed
  image: gekkofs/testing:0.9.2
Alberto Miranda's avatar
Alberto Miranda committed
  interruptible: true
  needs: ['gkfs']
  parallel:
    matrix:
Ramon Nou's avatar
Ramon Nou committed
      - SUBTEST: [ data, status, syscalls, directories, operations, position, shell, rename ]
  script:
    ## run tests
Ramon Nou's avatar
Ramon Nou committed
    - export PATH=${PATH}:/usr/local/bin
Alberto Miranda's avatar
Alberto Miranda committed
    - mkdir -p ${BUILD_PATH}/tests/run
    - cd ${BUILD_PATH}/tests/integration
Ramon Nou's avatar
Ramon Nou committed
    - ${PYTEST} -v -n $(nproc)
Alberto Miranda's avatar
Alberto Miranda committed
          ${INTEGRATION_TESTS_BIN_PATH}/${SUBTEST}
Alberto Miranda's avatar
Alberto Miranda committed
          --basetemp=${BUILD_PATH}/tests/run/${SUBTEST}
Alberto Miranda's avatar
Alberto Miranda committed
          --junit-xml=report.xml
    ## capture coverage information for this test and write it to
    ## $COVERAGE_PATH/$SUBTEST.info
    - cd ${CI_PROJECT_DIR}
    - cmake --preset ci-coverage
          -DCOVERAGE_OUTPUT_DIR=${COVERAGE_PATH}
          -DCOVERAGE_CAPTURE_TRACEFILE=${COVERAGE_PATH}/${SUBTEST}.info
    ## Since the pipeline recreates the source tree, the access times for .gcno
    ## files are newer than those of .gcda files. This makes gcov emit a
    ## warning for each file which slows it down. Updating the timestamps
    ## avoids this
    - find ${BUILD_PATH} -name "*.gcno" -exec touch {} \;
    - cmake --build ${BUILD_PATH} --target coverage-capture
Alberto Miranda's avatar
Alberto Miranda committed

  # fix relative paths so that GitLab can find the correct files
  after_script:
    - perl -i.orig
          -pe 's%file="(.*?)"%file="tests/integration/$1"%;'
          -pe 's%(../)+install/share/gkfs/%%g;'
          ${BUILD_PATH}/tests/integration/report.xml

  artifacts:
Alberto Miranda's avatar
Alberto Miranda committed
    expire_in: 1 week
    when: always
      - ${BUILD_PATH}
Alberto Miranda's avatar
Alberto Miranda committed
    reports:
      junit: ${BUILD_PATH}/tests/integration/report.xml
Alberto Miranda's avatar
Alberto Miranda committed

## == integration tests for gkfwd ==========
gkfwd:integration:
  stage: test
Ramon Nou's avatar
Ramon Nou committed
  image: gekkofs/testing:0.9.2
Alberto Miranda's avatar
Alberto Miranda committed
  interruptible: true
  needs: ['gkfwd']
  parallel:
    matrix:
      - SUBTEST: [ forwarding ]
  rules:
    - when: never
Alberto Miranda's avatar
Alberto Miranda committed
    ## run tests
Alberto Miranda's avatar
Alberto Miranda committed
    - mkdir -p ${BUILD_PATH}/tests/run
Alberto Miranda's avatar
Alberto Miranda committed
    - cd ${BUILD_PATH}/tests/integration
    - ${PYTEST} -v -n $(nproc)
          ${INTEGRATION_TESTS_BIN_PATH}/${SUBTEST}
Alberto Miranda's avatar
Alberto Miranda committed
          --basetemp=${BUILD_PATH}/tests/run/${SUBTEST}
Alberto Miranda's avatar
Alberto Miranda committed
          --junit-xml=report.xml

    ## capture coverage information for this test and write it to
    ## $COVERAGE_PATH/$SUBTEST.info
    - cd ${CI_PROJECT_DIR}
    - cmake --preset ci-coverage
          -DCOVERAGE_OUTPUT_DIR=${COVERAGE_PATH}
          -DCOVERAGE_CAPTURE_TRACEFILE=${COVERAGE_PATH}/${SUBTEST}.info
    ## Since the pipeline recreates the source tree, the access times for .gcno
    ## files are newer than those of .gcda files. This makes gcov emit a
    ## warning for each file which slows it down. Updating the timestamps
    ## avoids this
    - find ${BUILD_PATH} -name "*.gcno" -exec touch {} \;
    - cmake --build ${BUILD_PATH} --target coverage-capture
Alberto Miranda's avatar
Alberto Miranda committed
  # fix relative paths so that GitLab can find the correct files
  after_script:
    - perl -i.orig
          -pe 's%file="(.*?)"%file="tests/integration/$1"%;'
          -pe 's%(../)+install/share/gkfs/%%g;'
          ${BUILD_PATH}/tests/integration/report.xml
Tommaso Tocci's avatar
Tommaso Tocci committed

  artifacts:
Alberto Miranda's avatar
Alberto Miranda committed
    expire_in: 1 week
    when: always
Tommaso Tocci's avatar
Tommaso Tocci committed
    paths:
Alberto Miranda's avatar
Alberto Miranda committed
      - ${BUILD_PATH}
    reports:
      junit: ${BUILD_PATH}/tests/integration/report.xml
Alberto Miranda's avatar
Alberto Miranda committed
## == unit tests for gkfs ==================
gkfs:unit:
  stage: test
Ramon Nou's avatar
Ramon Nou committed
  image: gekkofs/testing:0.9.2
Alberto Miranda's avatar
Alberto Miranda committed
  needs: ['gkfs']
Ramon Nou's avatar
Ramon Nou committed
    ## Add path to mkfs.kreon
    - export PATH=${PATH}:/usr/local/bin
Alberto Miranda's avatar
Alberto Miranda committed
    ## run actual tests
    - cd ${CI_PROJECT_DIR}
    - ctest --test-dir ${BUILD_PATH}
          -j $(nproc)
          -L unit::all
          --output-junit ${BUILD_PATH}/tests/unit/report.xml

    ## capture coverage information for this test and write it to
    ## $COVERAGE_PATH/unit.info
    - cd ${CI_PROJECT_DIR}
    - cmake --preset ci-coverage
          -DCOVERAGE_OUTPUT_DIR=${COVERAGE_PATH}
          -DCOVERAGE_CAPTURE_TRACEFILE=${COVERAGE_PATH}/unit.info
    ## Since the pipeline recreates the source tree, the access times for .gcno
    ## files are newer than those of .gcda files. This makes gcov emit a
    ## warning for each file which slows it down. Updating the timestamps
    ## avoids this
    - find ${BUILD_PATH} -name "*.gcno" -exec touch {} \;
    - cmake --build ${BUILD_PATH} --target coverage-capture

  artifacts:
Alberto Miranda's avatar
Alberto Miranda committed
    expire_in: 1 week
Alberto Miranda's avatar
Alberto Miranda committed
      - ${BUILD_PATH}
    reports:
      junit: ${BUILD_PATH}/tests/unit/report.xml
################################################################################
## Generation of documentation
################################################################################
documentation:
  stage: docs
Ramon Nou's avatar
Ramon Nou committed
  image: gekkofs/docs:0.9.2
  needs: []
  rules:
    # we only build the documentation automatically if we are on the
    # `master` branch, but since we also would like to test the documentation
    # against our CI, we allow developers to also build it manually
    - if: '$CI_MERGE_REQUEST_EVENT_TYPE == "detached"'
      when: never
    - if: '$CI_MERGE_REQUEST_ID != ""'
      when: manual
      allow_failure: true
    - if: '$CI_COMMIT_REF_SLUG == "master"'
      when: always

  script:
    - cmake --preset ci-docs
    - cmake --build ${BUILD_PATH} --target docs
  artifacts:
    paths:
      - ${BUILD_PATH}/docs
    expire_in: 2 weeks


################################################################################
## Generation of code coverage reports
################################################################################
Alberto Miranda's avatar
Alberto Miranda committed

## == coverage baseline ====================
coverage:baseline:
  stage: report
  image: gekkofs/testing:0.9.2
  interruptible: true
  needs: ['gkfs', 'gkfwd']

  script:
    ## capture initial coverage information to establish a baseline
    ## and write it to $COVERAGE_PATH/zerocount.info
    - cd ${CI_PROJECT_DIR}
    - cmake --preset ci-coverage
      -DCOVERAGE_OUTPUT_DIR=${COVERAGE_PATH}
      -DCOVERAGE_ZEROCOUNT_TRACEFILE=${COVERAGE_PATH}/zerocount.info
    ## Since the pipeline recreates the source tree, the access times for .gcno
    ## files are newer than those of .gcda files. This makes gcov emit a
    ## warning for each file which slows it down. Updating the timestamps
    ## avoids this
    - find ${BUILD_PATH} -name "*.gcno" -exec touch {} \;
    - cmake --build ${BUILD_PATH} --target coverage-zerocount

  artifacts:
    expire_in: 1 week
    when: always
    paths:
      - ${COVERAGE_PATH}/zerocount.info

coverage:
  stage: report
  image: gekkofs/testing:0.9.2
#  needs: [ 'coverage:baseline', 'gkfs:integration', 'gkfwd:integration',
#           'gkfs:unit' ]
  needs: [ 'coverage:baseline', 'gkfs:integration', 'gkfs:unit' ]
    - cd ${CI_PROJECT_DIR}
    - cmake
          --preset ci-coverage
          -DCOVERAGE_OUTPUT_DIR=${COVERAGE_PATH}
          -DCOVERAGE_UNIFIED_TRACEFILE=${COVERAGE_PATH}/coverage.info
          -DCOVERAGE_HTML_REPORT_DIRECTORY=${COVERAGE_PATH}/coverage_html
          -DCOVERAGE_XML_REPORT=${COVERAGE_PATH}/coverage-cobertura.xml
    - cmake
          --build ${BUILD_PATH}
          --target coverage-html
          --target coverage-cobertura
          --target coverage-summary
  coverage: '/lines[\.]+\: (\d+\.\d+)\%/'
  artifacts:
    reports:
      coverage_report:
        coverage_format: cobertura
        path: ${COVERAGE_PATH}/coverage-cobertura.xml
      - ${COVERAGE_PATH}
    expire_in: 2 weeks


################################################################################
## Deployment of documentation and reports
################################################################################
#
## for the deploy stage to work as expected, we need to run rsync with the
## appropriate credentials provided by sysadmins. For that, the specific values
## for DEPLOY_KEY_FILE, DEPLOY_USERNAME, DEPLOY_GROUP, DEPLOY_SERVER and
## DEPLOY_PATH must be defined as protected variables.
deploy:
  image: bscstorage/deployer
  stage: deploy
  needs: [ 'documentation' ]
  only:
    - master
  script:
    - chmod 400 ${DEPLOY_KEY_FILE}
    - rsync -e "ssh -i ${DEPLOY_KEY_FILE}"
        -avzr
        --delete
        --chown=${DEPLOY_USERNAME}:${DEPLOY_GROUP}
        ${BUILD_PATH}/docs/sphinx/sphinx_docs/
        ${DEPLOY_USERNAME}@${DEPLOY_SERVER}:${DEPLOY_PATH}