0

In my .gitlab-ci.yml script, I have a metrics job that currently runs the radon tool (https://radon.readthedocs.io/en/latest/) to obtain metrics and stores them in a metrics.json file.

Although the script section is executed and I can download the artifact, the Gitlab UI consistently reports

  • Metrics report scanning detected no new changes

The GitLab-CI manual (https://docs.gitlab.com/ee/ci/testing/metrics_reports.html) states that it is necessary to convert the radon output to the Open Metrics format (https://github.com/OpenObservability/OpenMetrics/blob/main/specification/OpenMetrics.md) so that GitLab can display the content. I would like to know how to do this.

This is my current Gitlab-CI script section:

metrics-job:
  needs: []
  stage: test
  tags:
    - python3
  script:
    - echo "Getting code metrics ..."
    - echo "Subdirs for metrics - $SUBDIRS"
    - radon cc --json --min D $SUBDIRS > metrics.json
  artifacts:
    when: always
    reports:
      metrics: metrics.json

The radon output is in a JSON format. Here is an example of the output simplified by scanning only one folder instead of the whole project:

{"folder/file.py": 
 [{"type": "method", 
   "rank": "D", 
   "complexity": 26, 
   "classname": "MyClass", 
   "lineno": 159, 
   "col_offset": 4, 
   "name": "bad_metrics_method", 
   "endline": 242, 
   "closures": []}
 ]
}

I have tried configuring a .codeclimate.yml file to enable the radon engine and setting the threshold to 'B', but this did not resolve the issue.

Here is my .codeclimate.yml:

engines:
    radon:
        enabled: true
        config:
            threshold: 'B'
    pep8:
        enabled: true
ratings:
    paths:
    - "**.py"
exclude_paths:
 - "unittests/*"

I also tested, if the Metrics reports essentially works by entering the example code from https://docs.gitlab.com/ee/ci/testing/img/metrics_reports_v13_0.png in my .gitlab-ci.yml This is the result:

enter image description here

Therefore, it's really the format of the radon output which is not compatible with Gitlab. The Metrics essentially works.

0 Answers0