diff --git a/config/metrics/counts_28d/20210216184559_ci_templates_total_unique_counts_monthly.yml b/config/metrics/counts_28d/20210216184559_ci_templates_total_unique_counts_monthly.yml index 1847eaf86a76cdd09383ee9cdcf7327549b94b41..35a727f09dc76f15d6d3866d348680c0582a19e2 100755 --- a/config/metrics/counts_28d/20210216184559_ci_templates_total_unique_counts_monthly.yml +++ b/config/metrics/counts_28d/20210216184559_ci_templates_total_unique_counts_monthly.yml @@ -181,6 +181,7 @@ options: - p_ci_templates_terraform_module_base - p_ci_templates_terraform_module - p_ci_templates_pages_zola + - p_ci_templates_diffblue_cover distribution: - ce - ee diff --git a/config/metrics/counts_28d/20231116002424_p_ci_templates_diffblue_cover_monthly.yml b/config/metrics/counts_28d/20231116002424_p_ci_templates_diffblue_cover_monthly.yml new file mode 100644 index 0000000000000000000000000000000000000000..521ae02f6c418d4b2b968c2c0adac5b26e852120 --- /dev/null +++ b/config/metrics/counts_28d/20231116002424_p_ci_templates_diffblue_cover_monthly.yml @@ -0,0 +1,24 @@ +--- +key_path: redis_hll_counters.ci_templates.p_ci_templates_diffblue_cover_monthly +description: Count of pipelines using the Diffblue Cover template +product_section: ci +product_stage: pipeline_authoring +product_group: pipeline_authoring +value_type: number +status: active +milestone: "16.7" +introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/137047 +time_frame: 28d +data_source: redis_hll +data_category: optional +instrumentation_class: RedisHLLMetric +distribution: +- ce +- ee +tier: +- free +- premium +- ultimate +options: + events: + - p_ci_templates_diffblue_cover diff --git a/config/metrics/counts_7d/20210216184557_ci_templates_total_unique_counts_weekly.yml b/config/metrics/counts_7d/20210216184557_ci_templates_total_unique_counts_weekly.yml index 3925f242efcede3ad0048aca0865bc742e208a4d..61fa197656bd048a57922248a2a57c0b323d107e 100755 --- a/config/metrics/counts_7d/20210216184557_ci_templates_total_unique_counts_weekly.yml +++ b/config/metrics/counts_7d/20210216184557_ci_templates_total_unique_counts_weekly.yml @@ -182,6 +182,7 @@ options: - p_ci_templates_terraform_module_base - p_ci_templates_terraform_module - p_ci_templates_pages_zola + - p_ci_templates_diffblue_cover distribution: - ce - ee diff --git a/config/metrics/counts_7d/20231116002421_p_ci_templates_diffblue_cover_weekly.yml b/config/metrics/counts_7d/20231116002421_p_ci_templates_diffblue_cover_weekly.yml new file mode 100644 index 0000000000000000000000000000000000000000..b9586f213a55ae01886c4ead892dc66930b9ee76 --- /dev/null +++ b/config/metrics/counts_7d/20231116002421_p_ci_templates_diffblue_cover_weekly.yml @@ -0,0 +1,24 @@ +--- +key_path: redis_hll_counters.ci_templates.p_ci_templates_diffblue_cover_weekly +description: Count of pipelines using the Diffblue Cover template +product_section: ci +product_stage: pipeline_authoring +product_group: pipeline_authoring +value_type: number +status: active +milestone: "16.7" +introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/137047 +time_frame: 7d +data_source: redis_hll +data_category: optional +instrumentation_class: RedisHLLMetric +distribution: +- ce +- ee +tier: +- free +- premium +- ultimate +options: + events: + - p_ci_templates_diffblue_cover diff --git a/lib/gitlab/ci/templates/Diffblue-Cover.gitlab-ci.yml b/lib/gitlab/ci/templates/Diffblue-Cover.gitlab-ci.yml new file mode 100644 index 0000000000000000000000000000000000000000..c8b3aa1d705310f9da0b2c1c2aee14c3fb4e196c --- /dev/null +++ b/lib/gitlab/ci/templates/Diffblue-Cover.gitlab-ci.yml @@ -0,0 +1,88 @@ +# This template is provided and maintained by Diffblue. +# You can copy and paste this template into a new `.gitlab-ci.yml` file. +# This template is designed to be used with the Cover Pipeline for GitLab integration from Diffblue. +# It will download the latest version of Diffblue Cover, build the associated project, and +# automatically write Java unit tests for the project. +# Note that additional config is required: +# https://docs.diffblue.com/features/cover-pipeline/cover-pipeline-for-gitlab +# You should not add this template to an existing `.gitlab-ci.yml` file by using the `include:` keyword. +# +# To contribute improvements to CI/CD templates, please follow the Development guide at: +# https://docs.gitlab.com/ee/development/cicd/templates.html +# This specific template is located at: +# https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Diffblue-Cover.gitlab-ci.yml + +variables: + # Configure the following via the Diffblue Cover integration config for your project, or by + # using CI/CD masked Variables. + # For details, see https://docs.diffblue.com/features/cover-pipeline/cover-pipeline-for-gitlab + + # Diffblue Cover license key: DIFFBLUE_LICENSE_KEY + # Refer to your welcome email or you can obtain a free trial key from + # https://www.diffblue.com/try-cover/gitlab + + # GitLab access token: DIFFBLUE_ACCESS_TOKEN, DIFFBLUE_ACCESS_TOKEN_NAME + # The access token should have a role of Developer or better and should have + # api and write_repository permissions. + + # Diffblue Cover requires a minimum of 4GB of memory. + JVM_ARGS: -Xmx4g + +stages: + - build + +diffblue-cover: + stage: build + + # Select the Cover CLI docker image to use with your CI tool. + # Tag variations are produced for each supported JDK version. + # Go to https://hub.docker.com/r/diffblue/cover-cli for details. + # Note: To use the latest version of Diffblue Cover, use one of the latest-jdk<nn> tags. + # To use a specific release version, use one of the yyyy.mm.dd-jdk<nn> tags. + image: diffblue/cover-cli:latest-jdk17 + + # Diffblue Cover currently only supports running on merge_request_events. + rules: + - if: $CI_PIPELINE_SOURCE == 'merge_request_event' + + # Diffblue Cover log files are saved to a .diffblue/ directory in the pipeline artifacts, + # and are available for download once the pipeline completes. + artifacts: + paths: + - "**/.diffblue/" + + script: + + # Diffblue Cover requires the project to be built before creating any tests. + # Either specify the build command here (one of the following), or provide + # prebuilt artifacts via a job dependency. + + # Maven project example (comment out the Gradle version if used): + - mvn test-compile --batch-mode --no-transfer-progress + + # Gradle project example (comment out the Maven version if used): + # - gradle testClasses + + # Diffblue Cover commands and options to run. + # dcover – the core Diffblue Cover command + # ci – enable the GitLab CI/CD integration via environment variables + # activate - activate the license key + # validate - remove non-compiling and failing tests + # create - create new tests for your project + # --maven – use the maven build tool + # For detailed information on Cover CLI commands and options, see + # https://docs.diffblue.com/features/cover-cli/commands-and-arguments + - dcover + ci + activate + validate --maven + create --maven + + # Diffblue Cover will also respond to specific project labels: + # Diffblue Cover: Baseline + # Used to mark a merge request as requiring a full suite of tests to be written. + # This overrides the default behaviour where Cover will only write tests related + # to the code changes already in the merge request. This is useful when running Diffblue + # Cover for the first time on a project and when new product enhancements are released. + # Diffblue Cover: Skip + # Used to mark a merge request as requiring no tests to be written. diff --git a/spec/lib/gitlab/ci/templates/Diffblue_Cover_spec.rb b/spec/lib/gitlab/ci/templates/Diffblue_Cover_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..c16356bfda752b701aea471e301fa0496e28c8fb --- /dev/null +++ b/spec/lib/gitlab/ci/templates/Diffblue_Cover_spec.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'Diffblue-Cover.gitlab-ci.yml', feature_category: :continuous_integration do + subject(:template) { Gitlab::Template::GitlabCiYmlTemplate.find('Diffblue-Cover') } + + describe 'the created pipeline' do + let(:pipeline_branch) { 'patch-1' } + let_it_be(:project) { create(:project, :repository, create_branch: 'patch-1') } + let(:user) { project.first_owner } + + let(:mr_service) { MergeRequests::CreatePipelineService.new(project: project, current_user: user) } + let(:merge_request) { create(:merge_request, :simple, source_project: project, source_branch: pipeline_branch) } + let(:mr_pipeline) { mr_service.execute(merge_request).payload } + let(:mr_build_names) { mr_pipeline.builds.pluck(:name) } + + before do + stub_ci_pipeline_yaml_file(template.content) + end + + it 'creates diffblue-cover jobs' do + expect(mr_build_names).to include('diffblue-cover') + end + end +end diff --git a/spec/lib/gitlab/ci/templates/templates_spec.rb b/spec/lib/gitlab/ci/templates/templates_spec.rb index 36c6e805bdf43c3803d806f33df9292b96504144..98f0d32960b3f447b6f0940a1cf237c088586331 100644 --- a/spec/lib/gitlab/ci/templates/templates_spec.rb +++ b/spec/lib/gitlab/ci/templates/templates_spec.rb @@ -20,6 +20,7 @@ context 'that support autodevops' do exceptions = [ + 'Diffblue-Cover.gitlab-ci.yml', # no auto-devops 'Security/DAST.gitlab-ci.yml', # DAST stage is defined inside AutoDevops yml 'Security/DAST-API.gitlab-ci.yml', # no auto-devops 'Security/API-Fuzzing.gitlab-ci.yml', # no auto-devops