From dfdd9fc75750f9bdb98334ef96a06d7c208c31ed Mon Sep 17 00:00:00 2001 From: Alexander Fisher <alex@linfratech.co.uk> Date: Thu, 2 Mar 2023 11:57:07 +0000 Subject: [PATCH] Add support for GitLab Code Quality reports This commit adds support for enabling [GitLab Code Quality](https://docs.gitlab.com/ee/ci/testing/code_quality.html) reports. I've not enabled it by default (in `config_defaults.yml`), but this is something that perhaps we could do at a later date following any user feedback. Meanwhile, the following module `.sync.yml` content can be used to turn it on. ```yaml .gitlab-ci.yml: custom: ruby_versions: '2.7.2': code_quality: true ``` --- README.md | 2 +- moduleroot/.gitlab-ci.yml.erb | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 03e7b4a..4c57c65 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,7 @@ Gitlab CI uses a .gitlab-ci.yml file in the root of your repository tell Gitlab | cache | If this setting exists, it expects a single sub-key called `paths`. `paths` is an array of paths that will be cached for each subsequent job. Defaults to `['vendor/bundle']`| | tags | If this setting exists, it expects an array of tags that will be added to each job. Not set by default.| | bundler\_args |Define any arguments you want to pass through to bundler. The default is `--without system_tests --path vendor/bundle --jobs $(nproc)` which avoids installing unnecessary gems while installing them to the `vendor/bundler.| -| ruby_versions |Define a list of ruby_versions to test against. Each version can have a series of sub-keys that are options. `checks` is the rake command(s) to run during the job. `puppet_version` sets the PUPPET_GEM_VERSION environment variable. `allow_failure` is an array of `checks` where you want to allow failures. `tags` is an array of Gitlab CI Runner tags. | +| ruby_versions |Define a list of ruby_versions to test against. Each version can have a series of sub-keys that are options. `checks` is the rake command(s) to run during the job. `puppet_version` sets the PUPPET_GEM_VERSION environment variable. `allow_failure` is an array of `checks` where you want to allow failures. `tags` is an array of Gitlab CI Runner tags. `code_quality` is a boolean that when enabled adds [Code Quality](https://docs.gitlab.com/ee/ci/testing/code_quality.html) reports to jobs that run puppet-lint (version [3.2.0](https://github.com/puppetlabs/puppet-lint/blob/main/CHANGELOG.md#v320---2023-02-28) onwards). | | ruby_versions\\{job}\\**except/only**|Basic `except`/`only` is an hash of `checks` with array of references of conditions for the `checks`:<br><br><pre>ruby_versions:<br> 2.4.9:<br> except:<br> unit:<br> - tags<br> - main</pre><br><br>Advanced `except`/`only` is an hash of `checks` with hash using 4 keywords `'variables', 'refs', 'changes', 'kubernetes'` each with it's own array of references or conditions for the `checks`:<br><br><pre>ruby_versions:<br> 2.4.9:<br> except:<br> unit:<br> refs:<br> - tags<br> - main<br> variables:<br> - $CI_COMMIT_MESSAGE =~ /\[skip[ _-]tests?\]/i</pre> https://docs.gitlab.com/ce/ci/yaml/README.html#onlyexcept-advanced | | custom_jobs |Define custom Gitlab CI jobs that will be executed. It is recommended that you use this option if you need customized Gitlab CI jobs. Please see the [.gitlab-ci.yml](https://docs.gitlab.com/ce/ci/yaml/README.html) docs for specifics.| | rubygems_mirror | Use a custom rubygems mirror url | diff --git a/moduleroot/.gitlab-ci.yml.erb b/moduleroot/.gitlab-ci.yml.erb index 3151bc5..b16aecc 100644 --- a/moduleroot/.gitlab-ci.yml.erb +++ b/moduleroot/.gitlab-ci.yml.erb @@ -112,11 +112,20 @@ default: <% if options['rubygems_version'] -%> RUBYGEMS_VERSION: '<%= options['rubygems_version'] -%>' <% end -%> +<% if options['code_quality'] and check =~ %r{\blint\b}-%> + CODECLIMATE_REPORT_FILE: 'gl-code-quality-report.json' +<% end -%> <% if configs.has_key?('global_variables') -%> <% configs['global_variables'].each do |key, value| -%> <%= key %>: '<%= value %>' <% end -%> <% end -%> +<% if options['code_quality'] and check =~ %r{\blint\b}-%> + artifacts: + reports: + codequality: gl-code-quality-report.json + expire_in: 1 week +<% end -%> <% if options['allow_failure'] -%> <% if options['allow_failure'].include?(check) -%> allow_failure: true -- GitLab