debian-mirror-gitlab/spec/factories/ci/pipelines.rb

271 lines
7.7 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
FactoryBot.define do
2019-12-26 22:10:19 +05:30
# TODO: we can remove this factory in favour of :ci_pipeline
2020-03-13 15:44:24 +05:30
factory :ci_empty_pipeline, class: 'Ci::Pipeline' do
2019-12-21 20:55:43 +05:30
source { :push }
ref { 'master' }
2020-04-22 19:07:51 +05:30
sha { 'b83d6e391c22777fca1ed3012fce84f633d7fed0' }
2019-12-21 20:55:43 +05:30
status { 'pending' }
add_attribute(:protected) { false }
2015-10-24 18:46:33 +05:30
2017-09-10 17:25:29 +05:30
project
2015-09-25 12:07:36 +05:30
2017-09-10 17:25:29 +05:30
# Persist merge request head_pipeline_id
# on pipeline factories to avoid circular references
2019-12-21 20:55:43 +05:30
transient { head_pipeline_of { nil } }
2017-09-10 17:25:29 +05:30
2021-01-03 14:25:43 +05:30
transient { child_of { nil } }
2021-02-22 17:27:13 +05:30
transient { upstream_of { nil } }
2021-01-03 14:25:43 +05:30
after(:build) do |pipeline, evaluator|
if evaluator.child_of
pipeline.project = evaluator.child_of.project
pipeline.source = :parent_pipeline
end
2022-01-26 12:08:38 +05:30
pipeline.ensure_project_iid!
2021-01-03 14:25:43 +05:30
end
2017-09-10 17:25:29 +05:30
after(:create) do |pipeline, evaluator|
merge_request = evaluator.head_pipeline_of
2020-10-24 23:57:45 +05:30
merge_request&.update!(head_pipeline: pipeline)
2021-01-03 14:25:43 +05:30
if evaluator.child_of
bridge = create(:ci_bridge, pipeline: evaluator.child_of)
2021-02-22 17:27:13 +05:30
create(:ci_sources_pipeline, source_job: bridge, pipeline: pipeline)
end
if evaluator.upstream_of
bridge = create(:ci_bridge, pipeline: pipeline)
create(:ci_sources_pipeline, source_job: bridge, pipeline: evaluator.upstream_of)
2021-01-03 14:25:43 +05:30
end
2017-09-10 17:25:29 +05:30
end
2021-04-17 20:07:23 +05:30
trait :created do
status { :created }
end
2017-08-17 22:00:37 +05:30
factory :ci_pipeline do
2020-06-23 00:09:42 +05:30
transient { ci_ref_presence { true } }
2021-01-03 14:25:43 +05:30
before(:create) do |pipeline, evaluator|
2020-06-23 00:09:42 +05:30
pipeline.ensure_ci_ref! if evaluator.ci_ref_presence && pipeline.ci_ref_id.nil?
end
2017-08-17 22:00:37 +05:30
trait :invalid do
2020-04-08 14:13:33 +05:30
status { :failed }
2019-12-26 22:10:19 +05:30
yaml_errors { 'invalid YAML' }
2019-12-21 20:55:43 +05:30
failure_reason { :config_error }
2017-08-17 22:00:37 +05:30
end
2019-07-07 11:18:12 +05:30
trait :preparing do
2019-12-21 20:55:43 +05:30
status { :preparing }
2019-07-07 11:18:12 +05:30
end
2017-08-17 22:00:37 +05:30
trait :blocked do
2019-12-21 20:55:43 +05:30
status { :manual }
2017-08-17 22:00:37 +05:30
end
2018-12-05 23:21:45 +05:30
trait :scheduled do
2019-12-21 20:55:43 +05:30
status { :scheduled }
2018-12-05 23:21:45 +05:30
end
2017-08-17 22:00:37 +05:30
trait :success do
2019-12-21 20:55:43 +05:30
status { :success }
2017-08-17 22:00:37 +05:30
end
2018-11-18 11:00:15 +05:30
trait :running do
2019-12-21 20:55:43 +05:30
status { :running }
2018-11-18 11:00:15 +05:30
end
2017-08-17 22:00:37 +05:30
trait :failed do
2019-12-21 20:55:43 +05:30
status { :failed }
2015-09-25 12:07:36 +05:30
end
2018-03-17 18:26:18 +05:30
2021-06-08 01:23:25 +05:30
trait :unlocked do
locked { Ci::Pipeline.lockeds[:unlocked] }
end
2022-03-02 08:16:31 +05:30
trait :artifacts_locked do
locked { Ci::Pipeline.lockeds[:artifacts_locked] }
end
2018-03-17 18:26:18 +05:30
trait :protected do
2019-12-21 20:55:43 +05:30
add_attribute(:protected) { true }
2018-03-17 18:26:18 +05:30
end
2018-11-18 11:00:15 +05:30
2020-07-28 23:09:34 +05:30
trait :with_report_results do
status { :success }
after(:build) do |pipeline, evaluator|
pipeline.builds << build(:ci_build, :report_results, pipeline: pipeline, project: pipeline.project)
end
end
trait :with_codequality_report do
status { :success }
after(:build) do |pipeline, evaluator|
pipeline.builds << build(:ci_build, :codequality_report, pipeline: pipeline, project: pipeline.project)
end
end
2021-03-11 19:13:27 +05:30
trait :with_sast_report do
status { :success }
after(:build) do |pipeline, evaluator|
pipeline.builds << build(:ci_build, :sast_report, pipeline: pipeline, project: pipeline.project)
end
end
trait :with_secret_detection_report do
status { :success }
after(:build) do |pipeline, evaluator|
pipeline.builds << build(:ci_build, :secret_detection_report, pipeline: pipeline, project: pipeline.project)
end
end
2018-11-18 11:00:15 +05:30
trait :with_test_reports do
2019-12-21 20:55:43 +05:30
status { :success }
2018-11-18 11:00:15 +05:30
after(:build) do |pipeline, evaluator|
pipeline.builds << build(:ci_build, :test_reports, pipeline: pipeline, project: pipeline.project)
end
end
2018-11-20 20:47:30 +05:30
2020-04-22 19:07:51 +05:30
trait :with_test_reports_attachment do
status { :success }
after(:build) do |pipeline, evaluator|
pipeline.builds << build(:ci_build, :test_reports_with_attachment, pipeline: pipeline, project: pipeline.project)
end
end
2020-05-24 23:13:21 +05:30
trait :with_broken_test_reports do
status { :success }
after(:build) do |pipeline, _evaluator|
pipeline.builds << build(:ci_build, :broken_test_reports, pipeline: pipeline, project: pipeline.project)
end
end
2021-01-29 00:20:46 +05:30
trait :with_test_reports_with_three_failures do
2021-02-22 17:27:13 +05:30
status { :failed }
2021-01-29 00:20:46 +05:30
after(:build) do |pipeline, _evaluator|
2021-02-22 17:27:13 +05:30
pipeline.builds << build(:ci_build, :failed, :test_reports_with_three_failures, pipeline: pipeline, project: pipeline.project)
2021-01-29 00:20:46 +05:30
end
end
2020-05-24 23:13:21 +05:30
trait :with_accessibility_reports do
status { :success }
after(:build) do |pipeline, evaluator|
pipeline.builds << build(:ci_build, :accessibility_reports, pipeline: pipeline, project: pipeline.project)
end
end
2020-04-08 14:13:33 +05:30
trait :with_coverage_reports do
status { :success }
after(:build) do |pipeline, evaluator|
pipeline.builds << build(:ci_build, :coverage_reports, pipeline: pipeline, project: pipeline.project)
end
end
2021-02-22 17:27:13 +05:30
trait :with_codequality_reports do
status { :success }
after(:build) do |pipeline, evaluator|
pipeline.builds << build(:ci_build, :codequality_reports, pipeline: pipeline, project: pipeline.project)
end
end
2020-11-24 15:15:51 +05:30
trait :with_coverage_report_artifact do
after(:build) do |pipeline, evaluator|
2021-03-11 19:13:27 +05:30
pipeline.pipeline_artifacts << build(:ci_pipeline_artifact, :with_coverage_report, pipeline: pipeline, project: pipeline.project)
end
end
trait :with_codequality_mr_diff_report do
after(:build) do |pipeline, evaluator|
pipeline.pipeline_artifacts << build(:ci_pipeline_artifact, :with_codequality_mr_diff_report, pipeline: pipeline, project: pipeline.project)
2020-11-24 15:15:51 +05:30
end
end
2020-05-24 23:13:21 +05:30
trait :with_terraform_reports do
status { :success }
after(:build) do |pipeline, evaluator|
pipeline.builds << build(:ci_build, :terraform_reports, pipeline: pipeline, project: pipeline.project)
2020-06-23 00:09:42 +05:30
pipeline.builds << build(:ci_build, :terraform_reports, pipeline: pipeline, project: pipeline.project)
2020-05-24 23:13:21 +05:30
end
end
2019-12-26 22:10:19 +05:30
trait :with_exposed_artifacts do
status { :success }
after(:build) do |pipeline, evaluator|
pipeline.builds << build(:ci_build, :artifacts,
pipeline: pipeline,
project: pipeline.project,
options: { artifacts: { expose_as: 'the artifact', paths: ['ci_artifacts.txt'] } })
end
end
2021-12-11 22:18:48 +05:30
trait :with_persisted_artifacts do
status { :success }
after(:create) do |pipeline, evaluator|
pipeline.builds << create(:ci_build, :artifacts, pipeline: pipeline, project: pipeline.project)
end
end
2019-05-03 19:53:19 +05:30
trait :with_job do
after(:build) do |pipeline, evaluator|
pipeline.builds << build(:ci_build, pipeline: pipeline, project: pipeline.project)
end
end
2018-11-20 20:47:30 +05:30
trait :auto_devops_source do
config_source { Ci::Pipeline.config_sources[:auto_devops_source] }
end
trait :repository_source do
config_source { Ci::Pipeline.config_sources[:repository_source] }
end
2020-04-22 19:07:51 +05:30
trait :detached_merge_request_pipeline do
merge_request
source { :merge_request_event }
project { merge_request.source_project }
sha { merge_request.source_branch_sha }
ref { merge_request.ref_path }
end
trait :legacy_detached_merge_request_pipeline do
detached_merge_request_pipeline
ref { merge_request.source_branch }
end
trait :merged_result_pipeline do
detached_merge_request_pipeline
2021-06-08 01:23:25 +05:30
sha { 'mergeSha' }
2020-04-22 19:07:51 +05:30
ref { merge_request.merge_ref_path }
source_sha { merge_request.source_branch_sha }
target_sha { merge_request.target_branch_sha }
end
2020-06-23 00:09:42 +05:30
trait :webide do
source { :webide }
config_source { :webide_source }
end
2015-09-25 12:07:36 +05:30
end
end
end