Skip to content
Snippets Groups Projects
.gitlab-ci.yml 3.51 KiB
Newer Older
Robert Rosca's avatar
Robert Rosca committed
stages:
  - check
Karim Ahmed's avatar
Karim Ahmed committed
  - test
Karim Ahmed's avatar
Karim Ahmed committed
  - automated_test
Robert Rosca's avatar
Robert Rosca committed

  before_script:
    - eval $(ssh-agent -s)
    - echo "$SSH_PRIVATE_KEY_GITLAB" | tr -d '\r' | ssh-add -
    #  Our self-hosted runners have persistent home directories, so here we store
    #  the known_hosts file in the temporary project dir and tell git to use a ssh
    #  command that uses this hosts file during operations
    - export GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=$CI_PROJECT_DIR/.ssh/known_hosts"
    - mkdir -p $CI_PROJECT_DIR/.ssh
    - chmod 700 $CI_PROJECT_DIR/.ssh
    - ssh-keyscan -p 10022 git.xfel.eu > $CI_PROJECT_DIR/.ssh/known_hosts
    - ls  $CI_PROJECT_DIR/.ssh
    - echo $GIT_SSH_COMMAND
    - export PYENV_VERSION="3.11"
Robert Rosca's avatar
Robert Rosca committed
    - python3 -m venv .venv
    - python3 -m pip install --upgrade pip setuptools wheel
    - source /etc/profile.d/modules.sh
    - export MODULEPATH=/usr/share/Modules/modulefiles:/etc/modulefiles:/usr/share/modulefiles
    - module avail
Karim Ahmed's avatar
Karim Ahmed committed

Robert Rosca's avatar
Robert Rosca committed
checks:
  stage: check
  only: [merge_requests]
  allow_failure: true
Cyril Danilevski's avatar
Cyril Danilevski committed
  script:
Robert Rosca's avatar
Robert Rosca committed
    - export PATH=/home/gitlab-runner/.local/bin:$PATH
    #  We'd like to run the pre-commit hooks only on files that are being
    #  modified by this merge request, however
    #  `CI_MERGE_REQUEST_TARGET_BRANCH_SHA` is a 'premium' feature according to
    #  GitLab... so this is a workaround for extracting the hash
Robert Rosca's avatar
Robert Rosca committed
    - export CI_MERGE_REQUEST_TARGET_BRANCH_SHA=$(git ls-remote origin $CI_MERGE_REQUEST_TARGET_BRANCH_NAME | cut -d$'\t' -f1)
    - export FILES=$(git diff $CI_COMMIT_SHA $CI_MERGE_REQUEST_TARGET_BRANCH_SHA --name-only | tr '\n' ' ')
    - python3 -m pip install pre-commit
    - echo "Running pre-commit on diff from $CI_COMMIT_SHA to $CI_MERGE_REQUEST_TARGET_BRANCH_SHA ($CI_MERGE_REQUEST_TARGET_BRANCH_NAME)"
Robert Rosca's avatar
Robert Rosca committed
    #  Pass list of modified files to pre-commit so that it only checks them
    - echo $FILES | xargs pre-commit run --color=always --files
Cyril Danilevski's avatar
Cyril Danilevski committed

Karim Ahmed's avatar
Karim Ahmed committed
pytest:
  stage: test
  only: [merge_requests]
  script:
    - export LANG=C  # Hopefully detect anything relying on locale
Karim Ahmed's avatar
Karim Ahmed committed
    - python3 -m pip install ".[test]"
    - python3 -m pytest --color yes --verbose --cov=cal_tools --cov=xfel_calibrate
  #  Nope... https://docs.gitlab.com/12.10/ee/user/project/merge_requests/test_coverage_visualization.html#enabling-the-feature
  #    - coverage xml
  #  artifacts:
  #    reports:
  #      cobertura: coverage.xml
Karim Ahmed's avatar
Karim Ahmed committed

automated_test:
    OUTPUT: $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME
Karim Ahmed's avatar
Karim Ahmed committed
    DETECTORS: all
    PYENV_VERSION: "3.8"
    CAL_CAL_TOOLS_CALCAT: "{base-api-url='http://exflcalproxy:8080/api', use-oauth2=false}"
Karim Ahmed's avatar
Karim Ahmed committed
  stage: automated_test
Karim Ahmed's avatar
Karim Ahmed committed
  only: [merge_requests]
Karim Ahmed's avatar
Karim Ahmed committed
  when: manual
  allow_failure: false
Karim Ahmed's avatar
Karim Ahmed committed
  script:
    - export LANG=C  # Hopefully detect anything relying on locale
    - python3 -m pip install ".[test]"
Karim Ahmed's avatar
Karim Ahmed committed
    - echo "Running automated test. This can take sometime to finish depending on the test data."
    - echo "Given variables are REFERENCE=$REFERENCE, OUTPUT=$OUTPUT, DETECTORS=$DETECTORS, CALIBRATION=$CALIBRATION"
    - python3 -m pytest -x ./tests/test_reference_runs --color yes --verbose --release-test --reference-folder /gpfs/exfel/d/cal_tst/reference_folder --out-folder /gpfs/exfel/data/scratch/xcaltst/test/$OUTPUT  --detectors $DETECTORS --calibration $CALIBRATION
  timeout: 24 hours
  resource_group: automated_test
Karim Ahmed's avatar
Karim Ahmed committed
cython-editable-install-test:
  stage: test
  only: [merge_requests]
  script:
    - python3 -m pip install -e ".[test]"
    - python3 -m pytest --color yes --verbose ./tests/test_cythonalgs.py