Commit fc3b4d5b authored by David Hallas's avatar David Hallas Committed by Gaëtan Montury
Browse files

feat: Add ty jobs

parent 90c88a02
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -444,6 +444,21 @@ In addition to a textual report in the console, this job produces the following
| -------------- | ---------------------------------------------------------------------------- | ----------------- |
| `$PYTHON_PROJECT_DIR/reports/py-basedpyright.codeclimate.json` | [Code Climate](https://github.com/codeclimate/platform/blob/master/spec/analyzers/SPEC.md#data-types) | [GitLab integration](https://docs.gitlab.com/ci/yaml/artifacts_reports/#artifactsreportscodequality) |

### `py-ty` job

This job **disabled by default** and runs [ty](https://docs.astral.sh/ty/) on the repo. It is bound to the build stage.

| Input / Variable | Description                                                             | Default value     |
| ---------------- | ----------------------------------------------------------------------- | ----------------- |
| `ty-enabled` / `TY_ENABLED` | Set to `true` to enable ty job                  | _none_ (disabled) |
| `ty-args` / `TY_ARGS` | Additional [ty Checker CLI options](https://docs.astral.sh/ty/reference/cli/#ty)     | _none_           |

In addition to logs in the console, this job produces the following reports, kept for one week:

| Report         | Format                                                                       | Usage             |
| -------------- | ---------------------------------------------------------------------------- | ----------------- |
| `$PYTHON_PROJECT_DIR/reports/py-ty.gitlab.json` | [GitLab](https://docs.astral.sh/ruff/settings/#output-format) | [GitLab integration](https://docs.gitlab.com/ci/yaml/artifacts_reports/#artifactsreportscodequality) |

### SonarQube analysis

If you're using the SonarQube template to analyse your Python code, here is a sample `sonar-project.properties` file:
+13 −0
Original line number Diff line number Diff line
@@ -356,6 +356,19 @@
          "default": "error"
        }
      ]
    },
    {
      "id": "ty",
      "name": "ty check",
      "description": "Enable type checking with ty. [ty](https://docs.astral.sh/ty/)",
      "enable_with": "TY_ENABLED",
      "variables": [
        {
          "name": "TY_ARGS",
          "description": "Additional [ty Checker CLI options](https://docs.astral.sh/ty/reference/cli/#ty)",
          "advanced": true
        }
      ]
    }
  ],
  "variants": [
+30 −0
Original line number Diff line number Diff line
@@ -223,6 +223,13 @@ spec:
      - error
      - warning
      default: error
    ty-enabled:
      description: Enable ty. Type checking [ty](https://docs.astral.sh/ty/)
      type: boolean
      default: false
    ty-args:
      description: Additional [ty CLI options](https://docs.astral.sh/ty/reference/cli/#ty-check)
      default: ""
---
# default workflow rules: Merge Request pipelines
.tbc-workflow-rules:
@@ -373,6 +380,8 @@ variables:
  PYRIGHT_ENABLED: $[[ inputs.pyright-enabled ]]
  PYRIGHT_ARGS: $[[ inputs.pyright-args ]]
  PYRIGHT_LEVEL: $[[ inputs.pyright-level ]]
  TY_ENABLED: $[[ inputs.ty-enabled ]]
  TY_ARGS: $[[ inputs.ty-args ]]


.python-scripts: &python-scripts |
@@ -1587,6 +1596,27 @@ py-basedpyright:
      when: never
    - !reference [.test-policy, rules]

py-ty:
  extends: .python-base
  stage: build
  script:
    - mkdir -p -m 777 reports
    # ty is self dependent tool (written in Rust), it can be installed without project dependencies (_pip and _run don't look required here)
    - pip install ${PIP_OPTS} ty
    - ty check ${TRACE+--verbose} --output-format gitlab ${TY_ARGS} > reports/py-ty.gitlab.json || ty check --output-format full ${TY_ARGS}
  artifacts:
    name: "$CI_JOB_NAME artifacts from $CI_PROJECT_NAME on $CI_COMMIT_REF_SLUG"
    expire_in: 1 day
    when: always
    reports:
      codequality: $PYTHON_PROJECT_DIR/reports/py-ty.gitlab.json
    paths:
      - "$PYTHON_PROJECT_DIR/reports/py-ty.*"
  rules:
    # exclude if $TY_ENABLED not set
    - if: '$TY_ENABLED != "true"'
      when: never
    - !reference [.test-policy, rules]

###############################################################################################
#                                      test stage                                             #