image: $CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX/python:3.11 variables: SCYLLA_HOST: scylla SCYLLA_PORT: 9042 SCYLLA_KEYSPACE: bec_atlas REDIS_HOST: redis REDIS_PORT: 6380 DOCKER_TLS_CERTDIR: "" CHILD_PIPELINE_BRANCH: $CI_DEFAULT_BRANCH BEC_CORE_BRANCH: description: "BEC branch to use for testing" value: main DEPLOY_DEV_SERVER: description: "Update the bec-atlas-dev server" options: - "true" - "false" value: "false" workflow: rules: - if: '$CI_PIPELINE_SOURCE == "schedule"' - if: '$CI_PIPELINE_SOURCE == "web"' - if: '$CI_PIPELINE_SOURCE == "pipeline"' - if: '$CI_PIPELINE_SOURCE == "parent_pipeline"' - if: '$CI_PIPELINE_SOURCE == "merge_request_event"' - if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS when: never - if: $CI_COMMIT_BRANCH auto_cancel: on_new_commit: interruptible stages: - Formatter - test - Deploy include: - template: Security/Secret-Detection.gitlab-ci.yml before_script: - if [[ "$CI_PROJECT_PATH" != "bec/bec_atlas" ]]; then echo -e "\033[35;1m Using branch $CHILD_PIPELINE_BRANCH of BEC Atlas \033[0;m"; test -d bec_atlas || git clone --branch $CHILD_PIPELINE_BRANCH https://gitlab.psi.ch/bec/bec_atlas.git; cd bec_atlas; fi - pip install ./backend[dev] - git clone --branch $BEC_CORE_BRANCH https://gitlab.psi.ch/bec/bec.git - pip install ./bec/bec_lib[dev] # Remove the following line once there is a new release of fakeredis-py - pip install git+https://github.com/cunla/fakeredis-py.git formatter: stage: Formatter needs: [] script: - pip install black isort - isort --check --diff --line-length=100 --profile=black --multi-line=3 --trailing-comma ./backend/bec_atlas - black --check --diff --color --line-length=100 --skip-magic-trailing-comma ./backend/bec_atlas rules: - if: '$CI_PIPELINE_SOURCE == "schedule"' - if: '$CI_PIPELINE_SOURCE == "web"' - if: '$CI_PIPELINE_SOURCE == "pipeline"' - if: '$CI_PIPELINE_SOURCE == "merge_request_event"' - if: '$CI_PIPELINE_SOURCE == "parent_pipeline"' when: never - if: $CI_COMMIT_BRANCH interruptible: true pylint: stage: Formatter needs: [] script: - pip install pylint pylint-exit anybadge - mkdir ./pylint - pylint ./backend/bec_atlas --output-format=text | tee ./pylint/pylint.log || pylint-exit $? - PYLINT_SCORE=$(sed -n 's/^Your code has been rated at \([-0-9.]*\)\/.*/\1/p' ./pylint/pylint.log) - anybadge --label=Pylint --file=pylint/pylint.svg --value=$PYLINT_SCORE 2=red 4=orange 8=yellow 10=green - echo "Pylint score is $PYLINT_SCORE" artifacts: paths: - ./pylint/ expire_in: 1 week rules: - if: '$CI_PIPELINE_SOURCE == "schedule"' - if: '$CI_PIPELINE_SOURCE == "web"' - if: '$CI_PIPELINE_SOURCE == "pipeline"' - if: '$CI_PIPELINE_SOURCE == "merge_request_event"' - if: '$CI_PIPELINE_SOURCE == "parent_pipeline"' when: never - if: $CI_COMMIT_BRANCH interruptible: true backend_pytest: stage: test image: $CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX/python:3.11 needs: [] script: - pip install coverage - coverage run --source=./backend --omit=*/backend/tests/* -m pytest -v --junitxml=report.xml --random-order --full-trace ./backend/tests - coverage report - coverage xml coverage: '/(?i)total.*? (100(?:\.0+)?\%|[1-9]?\d(?:\.\d+)?\%)$/' artifacts: reports: junit: report.xml coverage_report: coverage_format: cobertura path: coverage.xml interruptible: true frontend_test: stage: test image: $CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX/cypress/browsers:22.13.1 needs: [] before_script: - cd frontend/bec_atlas script: - npm install - npx ng test --no-watch --no-progress --browsers=ChromeHeadlessCI --code-coverage - cp ./coverage/cobertura-coverage.xml ../../cobertura-coverage.xml - cp ./coverage/junit-report.xml ../../junit-report.xml coverage: '/^Statements\s*:\s*([^%]+)/' artifacts: reports: junit: junit-report.xml coverage_report: coverage_format: cobertura path: cobertura-coverage.xml interruptible: true # semver: # stage: Deploy # needs: ["backend_pytest"] # script: # - git config --global user.name "ci_update_bot" # - git config --global user.email "ci_update_bot@bec.ch" # - git checkout "$CI_COMMIT_REF_NAME" # - git reset --hard origin/"$CI_COMMIT_REF_NAME" # # delete all local tags # - git tag -l | xargs git tag -d # - git fetch --tags # - git tag # # build and publish package # - pip install python-semantic-release==9.* wheel build twine # - export GL_TOKEN=$CI_UPDATES # - semantic-release -vv version # # check if any artifacts were created # - if [ ! -d dist ]; then echo No release will be made; exit 0; fi # # - twine upload dist/* -u __token__ -p $CI_PYPI_TOKEN --skip-existing # - semantic-release publish # allow_failure: false # rules: # - if: '$CI_COMMIT_REF_NAME == "main" && $CI_PROJECT_PATH == "bec/bec_atlas"' # interruptible: true deploy-dev: stage: Deploy tags: - bec-atlas-deploy needs: ["backend_pytest"] before_script: [] script: - cd ../; if [ ! -d ansible_bec ]; then git clone https://gitlab-runner:$CI_RO_TOKEN@gitlab.psi.ch/bec/ansible_bec.git; fi; - cd ansible_bec && git pull origin main - ansible-playbook --private-key=/home/gitlab-runner/deploy_bec deploy_bec_atlas.yaml -l bec-atlas-dev.psi.ch -u root --vault-pass-file $ANSIBLE_VAULT_PASS -e "bec_atlas_version=$CI_COMMIT_REF_NAME" rules: - if: '$CI_PIPELINE_SOURCE == "web"' - if: '$DEPLOY_DEV_SERVER == "false"' when: never interruptible: true deploy-qa: stage: Deploy tags: - bec-atlas-deploy needs: ["backend_pytest"] before_script: [] script: - cd ../; if [ ! -d ansible_bec ]; then git clone https://gitlab-runner:$CI_RO_TOKEN@gitlab.psi.ch/bec/ansible_bec.git; fi; - cd ansible_bec && git pull origin main - ansible-playbook --private-key=/home/gitlab-runner/deploy_bec deploy_bec_atlas.yaml -l bec-atlas-qa.psi.ch -u root --vault-pass-file $ANSIBLE_VAULT_PASS rules: - if: '$CI_COMMIT_BRANCH == "main" && $CI_PROJECT_PATH == "bec/bec_atlas"' interruptible: true