diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..673a6a7 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,105 @@ +# 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_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX/python:3.10 + +workflow: + rules: + - if: $CI_PIPELINE_SOURCE == "schedule" + - if: $CI_PIPELINE_SOURCE == "web" + - if: $CI_PIPELINE_SOURCE == "merge_request_event" + - if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS + when: never + - if: $CI_COMMIT_BRANCH + +include: + - template: Security/Secret-Detection.gitlab-ci.yml + + +#commands to run in the Docker container before starting each job. +before_script: + - pip install -e .[dev] + +# different stages in the pipeline +stages: + - Formatter + - test # must be called test for security/secret-detection to work + - AdditionalTests + - Deploy + +pylint: + stage: Formatter + script: + - pip install pylint pylint-exit anybadge + - pip install -e .[dev] + - mkdir ./pylint + - pylint ./csaxs_bec --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 + +secret_detection: + before_script: + - '' + +config_test: + stage: test + script: + - ophyd_test --config ./csaxs_bec/device_configs/ --output ./config_tests + artifacts: + paths: + - ./config_tests + when: on_failure + expire_in: "30 days" + allow_failure: true + + +pytest: + stage: test + script: + - pip install coverage + - coverage run --source=./csaxs_bec -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 diff --git a/csaxs_bec/device_configs/bec_device_config_sastt.yaml b/csaxs_bec/device_configs/bec_device_config_sastt.yaml index 0eba5bc..4bf3464 100755 --- a/csaxs_bec/device_configs/bec_device_config_sastt.yaml +++ b/csaxs_bec/device_configs/bec_device_config_sastt.yaml @@ -29,7 +29,7 @@ mokev: softwareTrigger: false mcs: description: Mcs scalar card for transmission readout - deviceClass: csaxs_bec.devices.epics.devices.MCSCsaxs + deviceClass: csaxs_bec.devices.epics.devices.MCScSAXS deviceConfig: prefix: 'X12SA-MCS:' mcs_config: @@ -43,7 +43,7 @@ mcs: softwareTrigger: false eiger9m: description: Eiger9m HPC area detector 9M - deviceClass: csaxs_bec.devices.epics.devices.Eiger9MCsaxs + deviceClass: csaxs_bec.devices.epics.devices.Eiger9McSAXS deviceConfig: prefix: 'X12SA-ES-EIGER9M:' deviceTags: @@ -138,7 +138,7 @@ ddg_fsh: softwareTrigger: false falcon: description: Falcon detector x-ray fluoresence - deviceClass: csaxs_bec.devices.epics.devices.FalconCSAXS + deviceClass: csaxs_bec.devices.epics.devices.FalconcSAXS deviceConfig: prefix: 'X12SA-SITORO:' deviceTags: @@ -150,7 +150,7 @@ falcon: softwareTrigger: false pilatus_2: description: Pilatus2 HPC area detector 300k - deviceClass: csaxs_bec.devices.epics.devices.PilatusCSAXS + deviceClass: csaxs_bec.devices.epics.devices.PilatuscSAXS deviceConfig: prefix: 'X12SA-ES-PILATUS300K:' deviceTags: