# This file is a template, and might need editing before it works on your project. # Official language image. Look for the different tagged releases at: # https://hub.docker.com/r/library/python/tags/ image: $CI_DOCKER_REGISTRY/python:3.9 #commands to run in the Docker container before starting each job. variables: DOCKER_TLS_CERTDIR: "" include: - template: Security/Secret-Detection.gitlab-ci.yml # different stages in the pipeline stages: - Formatter - test - AdditionalTests - Deploy formatter: stage: Formatter needs: [] script: - pip install black - black --check --diff --color --line-length=100 ./ pylint: stage: Formatter needs: [] before_script: - pip install pylint pylint-exit anybadge - pip install -e .[dev] script: - mkdir ./pylint - pylint ./bec_widgets --output-format=text --output=./pylint/pylint.log | 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 pylint-check: stage: Formatter needs: [] allow_failure: true before_script: - pip install pylint pylint-exit anybadge - apt-get update - apt-get install -y bc script: # Identify changed Python files - if [ "$CI_PIPELINE_SOURCE" == "merge_request_event" ]; then TARGET_BRANCH_COMMIT_SHA=$(git rev-parse $CI_MERGE_REQUEST_TARGET_BRANCH_NAME); CHANGED_FILES=$(git diff --name-only $SOURCE_BRANCH_COMMIT_SHA $TARGET_BRANCH_COMMIT_SHA | grep '\.py$' || true); else CHANGED_FILES=$(git diff --name-only $CI_COMMIT_BEFORE_SHA $CI_COMMIT_SHA | grep '\.py$' || true); fi - if [ -z "$CHANGED_FILES" ]; then echo "No Python files changed."; exit 0; fi # Run pylint only on changed files - mkdir ./pylint - pylint $CHANGED_FILES --output-format=text . | tee ./pylint/pylint_changed_files.log || pylint-exit $? - PYLINT_SCORE=$(sed -n 's/^Your code has been rated at \([-0-9.]*\)\/.*/\1/p' ./pylint/pylint_changed_files.log) - echo "Pylint score is $PYLINT_SCORE" # Fail the job if the pylint score is below 9 - if [ "$(echo "$PYLINT_SCORE < 9" | bc)" -eq 1 ]; then echo "Your pylint score is below the acceptable threshold (9)."; exit 1; fi artifacts: paths: - ./pylint/ expire_in: 1 week tests: stage: test needs: [] variables: QT_QPA_PLATFORM: "offscreen" script: - apt-get update - apt-get install -y libgl1-mesa-glx libegl1-mesa x11-utils libxkbcommon-x11-0 libdbus-1-3 - pip install .[dev] - coverage run --source=./bec_widgets -m pytest -v --junitxml=report.xml --random-order --full-trace ./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 #tests-3.9-pyqt5: #todo enable when we decide what qt distributions we want to support # extends: "tests" # stage: AdditionalTests # image: $CI_DOCKER_REGISTRY/python:3.9 # script: # - apt-get update # - apt-get install -y libgl1-mesa-glx libegl1-mesa x11-utils libxkbcommon-x11-0 libdbus-1-3 # - pip install .[dev,pyqt5] # - pytest -v --random-order ./tests tests-3.10: extends: "tests" stage: AdditionalTests image: $CI_DOCKER_REGISTRY/python:3.10 allow_failure: true tests-3.11: extends: "tests" stage: AdditionalTests image: $CI_DOCKER_REGISTRY/python:3.11 allow_failure: true tests-3.12: extends: "tests" stage: AdditionalTests image: $CI_DOCKER_REGISTRY/python:3.12 allow_failure: true semver: stage: Deploy needs: ["tests"] 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 - pip install python-semantic-release==7.* wheel - export GL_TOKEN=$CI_UPDATES - export REPOSITORY_USERNAME=__token__ - export REPOSITORY_PASSWORD=$CI_PYPI_TOKEN - > semantic-release publish -v DEBUG -D version_variable=./setup.py:__version__ -D hvcs=gitlab allow_failure: false rules: - if: '$CI_COMMIT_REF_NAME == "master"' pages: stage: Deploy needs: ["semver"] variables: TARGET_BRANCH: $CI_COMMIT_REF_NAME rules: - if: '$CI_COMMIT_TAG != null' variables: TARGET_BRANCH: $CI_COMMIT_TAG - if: '$CI_COMMIT_REF_NAME == "master"' script: - curl -X POST -d "branches=$CI_COMMIT_REF_NAME" -d "token=$RTD_TOKEN" https://readthedocs.org/api/v2/webhook/bec-widgets/253243/