diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
commit | 6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch) | |
tree | 78be5963ec075d80116a932011d695dd33910b4e /spec/services/ci | |
parent | 1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff) |
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'spec/services/ci')
37 files changed, 685 insertions, 94 deletions
diff --git a/spec/services/ci/build_report_result_service_spec.rb b/spec/services/ci/build_report_result_service_spec.rb index 3c1ef5301fc..70bcf74ba43 100644 --- a/spec/services/ci/build_report_result_service_spec.rb +++ b/spec/services/ci/build_report_result_service_spec.rb @@ -19,16 +19,6 @@ RSpec.describe Ci::BuildReportResultService do expect(Ci::BuildReportResult.count).to eq(1) end - context 'when feature is disable' do - it 'does not persist the data' do - stub_feature_flags(build_report_summary: false) - - subject - - expect(Ci::BuildReportResult.count).to eq(0) - end - end - context 'when data has already been persisted' do it 'raises an error and do not persist the same data twice' do expect { 2.times { described_class.new.execute(build) } }.to raise_error(ActiveRecord::RecordNotUnique) diff --git a/spec/services/ci/change_variable_service_spec.rb b/spec/services/ci/change_variable_service_spec.rb new file mode 100644 index 00000000000..7acdd4e834f --- /dev/null +++ b/spec/services/ci/change_variable_service_spec.rb @@ -0,0 +1,68 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Ci::ChangeVariableService do + let(:service) { described_class.new(container: group, current_user: user, params: params) } + + let_it_be(:user) { create(:user) } + let(:group) { create(:group) } + + describe '#execute' do + subject(:execute) { service.execute } + + context 'when creating a variable' do + let(:params) { { variable_params: { key: 'new_variable', value: 'variable_value' }, action: :create } } + + it 'persists a variable' do + expect { execute }.to change(Ci::GroupVariable, :count).from(0).to(1) + end + end + + context 'when updating a variable' do + let!(:variable) { create(:ci_group_variable, value: 'old_value') } + let(:params) { { variable_params: { key: variable.key, value: 'new_value' }, action: :update } } + + before do + group.variables << variable + end + + it 'updates a variable' do + expect { execute }.to change { variable.reload.value }.from('old_value').to('new_value') + end + + context 'when the variable does not exist' do + before do + variable.destroy! + end + + it 'raises a record not found error' do + expect { execute }.to raise_error(::ActiveRecord::RecordNotFound) + end + end + end + + context 'when destroying a variable' do + let!(:variable) { create(:ci_group_variable) } + let(:params) { { variable_params: { key: variable.key }, action: :destroy } } + + before do + group.variables << variable + end + + it 'destroys a variable' do + expect { execute }.to change { Ci::GroupVariable.exists?(variable.id) }.from(true).to(false) + end + + context 'when the variable does not exist' do + before do + variable.destroy! + end + + it 'raises a record not found error' do + expect { execute }.to raise_error(::ActiveRecord::RecordNotFound) + end + end + end + end +end diff --git a/spec/services/ci/change_variables_service_spec.rb b/spec/services/ci/change_variables_service_spec.rb new file mode 100644 index 00000000000..5f1207eaf58 --- /dev/null +++ b/spec/services/ci/change_variables_service_spec.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Ci::ChangeVariablesService do + let(:service) { described_class.new(container: group, current_user: user, params: params) } + + let_it_be(:user) { create(:user) } + let(:group) { spy(:group, variables: []) } + let(:params) { { variables_attributes: [{ key: 'new_variable', value: 'variable_value' }] } } + + describe '#execute' do + subject(:execute) { service.execute } + + it 'delegates to ActiveRecord update' do + execute + + expect(group).to have_received(:update).with(params) + end + end +end diff --git a/spec/services/ci/create_job_artifacts_service_spec.rb b/spec/services/ci/create_job_artifacts_service_spec.rb index 3f5cf079025..72b0d220b11 100644 --- a/spec/services/ci/create_job_artifacts_service_spec.rb +++ b/spec/services/ci/create_job_artifacts_service_spec.rb @@ -73,7 +73,7 @@ RSpec.describe Ci::CreateJobArtifactsService do expect(metadata_artifact.expire_at).to be_within(1.minute).of(expected_expire_at) end - context 'when expire_in params is set' do + context 'when expire_in params is set to a specific value' do before do params.merge!('expire_in' => '2 hours') end @@ -89,6 +89,23 @@ RSpec.describe Ci::CreateJobArtifactsService do expect(metadata_artifact.expire_at).to be_within(1.minute).of(expected_expire_at) end end + + context 'when expire_in params is set to `never`' do + before do + params.merge!('expire_in' => 'never') + end + + it 'sets expiration date according to the parameter' do + expected_expire_at = nil + + expect(subject).to be_truthy + archive_artifact, metadata_artifact = job.job_artifacts.last(2) + + expect(job.artifacts_expire_at).to eq(expected_expire_at) + expect(archive_artifact.expire_at).to eq(expected_expire_at) + expect(metadata_artifact.expire_at).to eq(expected_expire_at) + end + end end end diff --git a/spec/services/ci/create_pipeline_service/creation_errors_and_warnings_spec.rb b/spec/services/ci/create_pipeline_service/creation_errors_and_warnings_spec.rb index 16205529f1c..3be5ac1f739 100644 --- a/spec/services/ci/create_pipeline_service/creation_errors_and_warnings_spec.rb +++ b/spec/services/ci/create_pipeline_service/creation_errors_and_warnings_spec.rb @@ -24,7 +24,7 @@ RSpec.describe Ci::CreatePipelineService do test: script: rspec rules: - - if: '$CI_COMMIT_BRANCH' + - when: always YAML end @@ -32,7 +32,7 @@ RSpec.describe Ci::CreatePipelineService do expect(pipeline.error_messages.map(&:content)).to be_empty expect(pipeline.warning_messages.map(&:content)).to contain_exactly( - 'jobs:test uses `rules` without defining `workflow:rules`' + /jobs:test may allow multiple pipelines to run/ ) end @@ -77,13 +77,13 @@ RSpec.describe Ci::CreatePipelineService do stage: test script: echo rules: - - if: '$CI_COMMIT_BRANCH' + - when: on_success YAML end it 'contains both errors and warnings' do error_message = 'build job: need test is not defined in prior stages' - warning_message = 'jobs:test uses `rules` without defining `workflow:rules`' + warning_message = /jobs:test may allow multiple pipelines to run/ expect(pipeline.yaml_errors).to eq(error_message) expect(pipeline.error_messages.map(&:content)).to contain_exactly(error_message) diff --git a/spec/services/ci/create_pipeline_service/dry_run_spec.rb b/spec/services/ci/create_pipeline_service/dry_run_spec.rb new file mode 100644 index 00000000000..93378df80f0 --- /dev/null +++ b/spec/services/ci/create_pipeline_service/dry_run_spec.rb @@ -0,0 +1,119 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Ci::CreatePipelineService do + let_it_be(:project) { create(:project, :repository) } + let_it_be(:user) { create(:admin) } + let(:ref) { 'refs/heads/master' } + let(:service) { described_class.new(project, user, { ref: ref }) } + + subject { service.execute(:push, dry_run: true) } + + before do + stub_ci_pipeline_yaml_file(config) + end + + describe 'dry run' do + shared_examples 'returns a non persisted pipeline' do + it 'does not persist the pipeline' do + expect(subject).not_to be_persisted + expect(subject.id).to be_nil + end + + it 'does not process the pipeline' do + expect(Ci::ProcessPipelineService).not_to receive(:new) + + subject + end + + it 'does not schedule merge request head pipeline update' do + expect(service).not_to receive(:schedule_head_pipeline_update) + + subject + end + end + + context 'when pipeline is valid' do + let(:config) { gitlab_ci_yaml } + + it_behaves_like 'returns a non persisted pipeline' + + it 'returns a valid pipeline' do + expect(subject.error_messages).to be_empty + expect(subject.yaml_errors).to be_nil + expect(subject.errors).to be_empty + end + end + + context 'when pipeline is not valid' do + context 'when there are syntax errors' do + let(:config) do + <<~YAML + rspec: + script: echo + something: wrong + YAML + end + + it_behaves_like 'returns a non persisted pipeline' + + it 'returns a pipeline with errors', :aggregate_failures do + error_message = 'jobs:rspec config contains unknown keys: something' + + expect(subject.error_messages.map(&:content)).to eq([error_message]) + expect(subject.errors).not_to be_empty + expect(subject.yaml_errors).to eq(error_message) + end + end + + context 'when there are logical errors' do + let(:config) do + <<~YAML + build: + script: echo + stage: build + needs: [test] + test: + script: echo + stage: test + YAML + end + + it_behaves_like 'returns a non persisted pipeline' + + it 'returns a pipeline with errors', :aggregate_failures do + error_message = 'build job: need test is not defined in prior stages' + + expect(subject.error_messages.map(&:content)).to eq([error_message]) + expect(subject.errors).not_to be_empty + end + end + + context 'when there are errors at the seeding stage' do + let(:config) do + <<~YAML + build: + stage: build + script: echo + rules: + - if: '$CI_MERGE_REQUEST_ID' + test: + stage: test + script: echo + needs: ['build'] + YAML + end + + it_behaves_like 'returns a non persisted pipeline' + + it 'returns a pipeline with errors', :aggregate_failures do + error_message = "test: needs 'build'" + + expect(subject.error_messages.map(&:content)).to eq([error_message]) + expect(subject.errors).not_to be_empty + end + end + end + end +end diff --git a/spec/services/ci/create_pipeline_service/parameter_content_spec.rb b/spec/services/ci/create_pipeline_service/parameter_content_spec.rb index 5157574ea04..f656ad52ac8 100644 --- a/spec/services/ci/create_pipeline_service/parameter_content_spec.rb +++ b/spec/services/ci/create_pipeline_service/parameter_content_spec.rb @@ -49,14 +49,5 @@ RSpec.describe Ci::CreatePipelineService do end end end - - context 'when source is not a dangling build' do - subject { service.execute(:web, content: content) } - - it 'raises an exception' do - klass = Gitlab::Ci::Pipeline::Chain::Config::Content::Parameter::UnsupportedSourceError - expect { subject }.to raise_error(klass) - end - end end end diff --git a/spec/services/ci/create_pipeline_service_spec.rb b/spec/services/ci/create_pipeline_service_spec.rb index 9dc518be996..db4c2f5a047 100644 --- a/spec/services/ci/create_pipeline_service_spec.rb +++ b/spec/services/ci/create_pipeline_service_spec.rb @@ -93,6 +93,7 @@ RSpec.describe Ci::CreatePipelineService do let(:merge_request_1) do create(:merge_request, source_branch: 'feature', target_branch: "master", source_project: project) end + let(:merge_request_2) do create(:merge_request, source_branch: 'feature', target_branch: "v1.1.0", source_project: project) end @@ -512,7 +513,7 @@ RSpec.describe Ci::CreatePipelineService do it 'pull it from Auto-DevOps' do pipeline = execute_service expect(pipeline).to be_auto_devops_source - expect(pipeline.builds.map(&:name)).to match_array(%w[build code_quality eslint-sast test]) + expect(pipeline.builds.map(&:name)).to match_array(%w[build code_quality eslint-sast secret_detection_default_branch secrets-sast test]) end end @@ -905,6 +906,7 @@ RSpec.describe Ci::CreatePipelineService do stub_ci_pipeline_yaml_file(YAML.dump({ rspec: { script: 'rspec', retry: retry_value } })) + rspec_job.update!(options: { retry: retry_value }) end context 'as an integer' do @@ -912,8 +914,6 @@ RSpec.describe Ci::CreatePipelineService do it 'correctly creates builds with auto-retry value configured' do expect(pipeline).to be_persisted - expect(rspec_job.options_retry_max).to eq 2 - expect(rspec_job.options_retry_when).to eq ['always'] end end @@ -922,8 +922,6 @@ RSpec.describe Ci::CreatePipelineService do it 'correctly creates builds with auto-retry value configured' do expect(pipeline).to be_persisted - expect(rspec_job.options_retry_max).to eq 2 - expect(rspec_job.options_retry_when).to eq ['runner_system_failure'] end end end @@ -985,7 +983,6 @@ RSpec.describe Ci::CreatePipelineService do context 'with release' do shared_examples_for 'a successful release pipeline' do before do - stub_feature_flags(ci_release_generation: true) stub_ci_pipeline_yaml_file(YAML.dump(config)) end @@ -1695,16 +1692,23 @@ RSpec.describe Ci::CreatePipelineService do context 'when pipeline on feature is created' do let(:ref_name) { 'refs/heads/feature' } + shared_examples 'has errors' do + it 'contains the expected errors' do + expect(pipeline.builds).to be_empty + expect(pipeline.yaml_errors).to eq("test_a: needs 'build_a'") + expect(pipeline.error_messages.map(&:content)).to contain_exactly("test_a: needs 'build_a'") + expect(pipeline.errors[:base]).to contain_exactly("test_a: needs 'build_a'") + end + end + context 'when save_on_errors is enabled' do let(:pipeline) { execute_service(save_on_errors: true) } it 'does create a pipeline as test_a depends on build_a' do expect(pipeline).to be_persisted - expect(pipeline.builds).to be_empty - expect(pipeline.yaml_errors).to eq("test_a: needs 'build_a'") - expect(pipeline.messages.pluck(:content)).to contain_exactly("test_a: needs 'build_a'") - expect(pipeline.errors[:base]).to contain_exactly("test_a: needs 'build_a'") end + + it_behaves_like 'has errors' end context 'when save_on_errors is disabled' do @@ -1712,11 +1716,9 @@ RSpec.describe Ci::CreatePipelineService do it 'does not create a pipeline as test_a depends on build_a' do expect(pipeline).not_to be_persisted - expect(pipeline.builds).to be_empty - expect(pipeline.yaml_errors).to be_nil - expect(pipeline.messages).not_to be_empty - expect(pipeline.errors[:base]).to contain_exactly("test_a: needs 'build_a'") end + + it_behaves_like 'has errors' end end diff --git a/spec/services/ci/daily_build_group_report_result_service_spec.rb b/spec/services/ci/daily_build_group_report_result_service_spec.rb index 7d181a5c2ba..f196afb05e8 100644 --- a/spec/services/ci/daily_build_group_report_result_service_spec.rb +++ b/spec/services/ci/daily_build_group_report_result_service_spec.rb @@ -65,6 +65,7 @@ RSpec.describe Ci::DailyBuildGroupReportResultService, '#execute' do created_at: '2020-02-06 00:02:20' ) end + let!(:new_rspec_job) { create(:ci_build, pipeline: new_pipeline, name: '4/4 rspec', coverage: 84) } let!(:new_karma_job) { create(:ci_build, pipeline: new_pipeline, name: '3/3 karma', coverage: 92) } @@ -104,6 +105,7 @@ RSpec.describe Ci::DailyBuildGroupReportResultService, '#execute' do created_at: '2020-02-06 00:02:20' ) end + let!(:new_rspec_job) { create(:ci_build, pipeline: new_pipeline, name: '4/4 rspec', coverage: 84) } let!(:new_karma_job) { create(:ci_build, pipeline: new_pipeline, name: '3/3 karma', coverage: 92) } @@ -149,6 +151,7 @@ RSpec.describe Ci::DailyBuildGroupReportResultService, '#execute' do created_at: '2020-02-06 00:02:20' ) end + let!(:some_job) { create(:ci_build, pipeline: new_pipeline, name: 'foo') } it 'does nothing' do diff --git a/spec/services/ci/pipeline_processing/atomic_processing_service_spec.rb b/spec/services/ci/pipeline_processing/atomic_processing_service_spec.rb index a10a333b462..bc8b6b2d113 100644 --- a/spec/services/ci/pipeline_processing/atomic_processing_service_spec.rb +++ b/spec/services/ci/pipeline_processing/atomic_processing_service_spec.rb @@ -5,20 +5,12 @@ require_relative 'shared_processing_service.rb' require_relative 'shared_processing_service_tests_with_yaml.rb' RSpec.describe Ci::PipelineProcessing::AtomicProcessingService do - before do - stub_feature_flags(ci_atomic_processing: true) - - # This feature flag is implicit - # Atomic Processing does not process statuses differently - stub_feature_flags(ci_composite_status: true) - end - it_behaves_like 'Pipeline Processing Service' it_behaves_like 'Pipeline Processing Service Tests With Yaml' private - def process_pipeline(initial_process: false) + def process_pipeline described_class.new(pipeline).execute end end diff --git a/spec/services/ci/pipeline_processing/legacy_processing_service_spec.rb b/spec/services/ci/pipeline_processing/legacy_processing_service_spec.rb deleted file mode 100644 index 569a6d62dc1..00000000000 --- a/spec/services/ci/pipeline_processing/legacy_processing_service_spec.rb +++ /dev/null @@ -1,35 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' -require_relative 'shared_processing_service.rb' -require_relative 'shared_processing_service_tests_with_yaml.rb' - -RSpec.describe Ci::PipelineProcessing::LegacyProcessingService do - before do - stub_feature_flags(ci_atomic_processing: false) - end - - context 'when ci_composite_status is enabled' do - before do - stub_feature_flags(ci_composite_status: true) - end - - it_behaves_like 'Pipeline Processing Service' - it_behaves_like 'Pipeline Processing Service Tests With Yaml' - end - - context 'when ci_composite_status is disabled' do - before do - stub_feature_flags(ci_composite_status: false) - end - - it_behaves_like 'Pipeline Processing Service' - it_behaves_like 'Pipeline Processing Service Tests With Yaml' - end - - private - - def process_pipeline(initial_process: false) - described_class.new(pipeline).execute(initial_process: initial_process) - end -end diff --git a/spec/services/ci/pipeline_processing/shared_processing_service.rb b/spec/services/ci/pipeline_processing/shared_processing_service.rb index 224066885b6..7de22b6a4cc 100644 --- a/spec/services/ci/pipeline_processing/shared_processing_service.rb +++ b/spec/services/ci/pipeline_processing/shared_processing_service.rb @@ -788,8 +788,7 @@ RSpec.shared_examples 'Pipeline Processing Service' do let!(:deploy_pages) { create_build('deploy_pages', stage: 'deploy', stage_idx: 2, scheduling_type: :dag) } it 'runs deploy_pages without waiting prior stages' do - # Ci::PipelineProcessing::LegacyProcessingService requires :initial_process parameter - expect(process_pipeline(initial_process: true)).to be_truthy + expect(process_pipeline).to be_truthy expect(stages).to eq(%w(pending created pending)) expect(builds.pending).to contain_exactly(linux_build, mac_build, deploy_pages) diff --git a/spec/services/ci/pipeline_processing/shared_processing_service_tests_with_yaml.rb b/spec/services/ci/pipeline_processing/shared_processing_service_tests_with_yaml.rb index 17d254ba48e..77645298bc7 100644 --- a/spec/services/ci/pipeline_processing/shared_processing_service_tests_with_yaml.rb +++ b/spec/services/ci/pipeline_processing/shared_processing_service_tests_with_yaml.rb @@ -42,7 +42,7 @@ RSpec.shared_context 'Pipeline Processing Service Tests With Yaml' do { pipeline: pipeline.status, - stages: pipeline.ordered_stages.pluck(:name, :status).to_h, + stages: pipeline.stages.pluck(:name, :status).to_h, jobs: pipeline.statuses.latest.pluck(:name, :status).to_h } end diff --git a/spec/services/ci/pipeline_processing/test_cases/dag_build_fails_other_build_succeeds.yml b/spec/services/ci/pipeline_processing/test_cases/dag_build_fails_other_build_succeeds_deploy_needs_one_build_and_test.yml index a133023b12d..a133023b12d 100644 --- a/spec/services/ci/pipeline_processing/test_cases/dag_build_fails_other_build_succeeds.yml +++ b/spec/services/ci/pipeline_processing/test_cases/dag_build_fails_other_build_succeeds_deploy_needs_one_build_and_test.yml diff --git a/spec/services/ci/pipeline_processing/test_cases/dag_build_fails_other_build_succeeds_deploy_always.yml b/spec/services/ci/pipeline_processing/test_cases/dag_build_fails_other_build_succeeds_deploy_needs_one_build_and_test_when_always.yml index 4c676761e5c..4c676761e5c 100644 --- a/spec/services/ci/pipeline_processing/test_cases/dag_build_fails_other_build_succeeds_deploy_always.yml +++ b/spec/services/ci/pipeline_processing/test_cases/dag_build_fails_other_build_succeeds_deploy_needs_one_build_and_test_when_always.yml diff --git a/spec/services/ci/pipeline_processing/test_cases/dag_build_fails_test_allow_failure.yml b/spec/services/ci/pipeline_processing/test_cases/dag_build_fails_test_fails_with_allow_failure.yml index ea7046262c3..ea7046262c3 100644 --- a/spec/services/ci/pipeline_processing/test_cases/dag_build_fails_test_allow_failure.yml +++ b/spec/services/ci/pipeline_processing/test_cases/dag_build_fails_test_fails_with_allow_failure.yml diff --git a/spec/services/ci/pipeline_processing/test_cases/dag_test_on_failure_with_failure.yml b/spec/services/ci/pipeline_processing/test_cases/dag_build_fails_test_on_failure_deploy_needs_test.yml index 5ace621e89c..5ace621e89c 100644 --- a/spec/services/ci/pipeline_processing/test_cases/dag_test_on_failure_with_failure.yml +++ b/spec/services/ci/pipeline_processing/test_cases/dag_build_fails_test_on_failure_deploy_needs_test.yml diff --git a/spec/services/ci/pipeline_processing/test_cases/dag_build_allow_failure_test_on_failure.yml b/spec/services/ci/pipeline_processing/test_cases/dag_build_fails_with_allow_failure_test_on_failure.yml index cfc456387ff..cfc456387ff 100644 --- a/spec/services/ci/pipeline_processing/test_cases/dag_build_allow_failure_test_on_failure.yml +++ b/spec/services/ci/pipeline_processing/test_cases/dag_build_fails_with_allow_failure_test_on_failure.yml diff --git a/spec/services/ci/pipeline_processing/test_cases/dag_build_succeds_test_manual_allow_failure_true_deploy_needs_both.yml b/spec/services/ci/pipeline_processing/test_cases/dag_build_succeds_test_manual_allow_failure_true_deploy_needs_both.yml new file mode 100644 index 00000000000..60f803bc3d0 --- /dev/null +++ b/spec/services/ci/pipeline_processing/test_cases/dag_build_succeds_test_manual_allow_failure_true_deploy_needs_both.yml @@ -0,0 +1,41 @@ +config: + build: + stage: build + script: exit 0 + + test: + stage: test + when: manual + allow_failure: true + script: exit 1 + + deploy: + stage: deploy + script: exit 0 + needs: [build, test] + +init: + expect: + pipeline: pending + stages: + build: pending + test: created + deploy: created + jobs: + build: pending + test: created + deploy: created + +transitions: + - event: success + jobs: [build] + expect: + pipeline: running + stages: + build: success + test: skipped + deploy: created + jobs: + build: success + test: manual + deploy: created diff --git a/spec/services/ci/pipeline_processing/test_cases/dag_build_succeds_test_manual_allow_failure_true_deploy_needs_test.yml b/spec/services/ci/pipeline_processing/test_cases/dag_build_succeds_test_manual_allow_failure_true_deploy_needs_test.yml new file mode 100644 index 00000000000..4e4b2f22224 --- /dev/null +++ b/spec/services/ci/pipeline_processing/test_cases/dag_build_succeds_test_manual_allow_failure_true_deploy_needs_test.yml @@ -0,0 +1,41 @@ +config: + build: + stage: build + script: exit 0 + + test: + stage: test + when: manual + allow_failure: true + script: exit 0 + + deploy: + stage: deploy + script: exit 0 + needs: [test] + +init: + expect: + pipeline: pending + stages: + build: pending + test: created + deploy: created + jobs: + build: pending + test: created + deploy: created + +transitions: + - event: success + jobs: [build] + expect: + pipeline: running + stages: + build: success + test: skipped + deploy: created + jobs: + build: success + test: manual + deploy: created diff --git a/spec/services/ci/pipeline_processing/test_cases/dag_test_on_failure_with_success.yml b/spec/services/ci/pipeline_processing/test_cases/dag_build_succeeds_test_on_failure_deploy_needs_test.yml index 19524cfd3e4..19524cfd3e4 100644 --- a/spec/services/ci/pipeline_processing/test_cases/dag_test_on_failure_with_success.yml +++ b/spec/services/ci/pipeline_processing/test_cases/dag_build_succeeds_test_on_failure_deploy_needs_test.yml diff --git a/spec/services/ci/pipeline_processing/test_cases/dag_build_test_manual_review_deploy.yml b/spec/services/ci/pipeline_processing/test_cases/dag_build_test_manual_review_deploy.yml new file mode 100644 index 00000000000..fef28dcfbbe --- /dev/null +++ b/spec/services/ci/pipeline_processing/test_cases/dag_build_test_manual_review_deploy.yml @@ -0,0 +1,82 @@ +config: + stages: [build, test, review, deploy] + + build: + stage: build + script: exit 0 + + test: + stage: test + script: exit 0 + + release_test: + stage: test + when: manual + allow_failure: true + script: exit 0 + + review: + stage: review + script: exit 0 + needs: [test, release_test] + + staging: + stage: deploy + script: exit 0 + needs: [test, release_test] + + production: + stage: deploy + script: exit 0 + needs: [review] + +init: + expect: + pipeline: pending + stages: + build: pending + test: created + review: created + deploy: created + jobs: + build: pending + test: created + release_test: created + review: created + staging: created + production: created + +transitions: + - event: success + jobs: [build] + expect: + pipeline: running + stages: + build: success + test: pending + review: created + deploy: created + jobs: + build: success + test: pending + release_test: manual + review: created + staging: created + production: created + + - event: success + jobs: [test] + expect: + pipeline: running + stages: + build: success + test: success + review: created + deploy: created + jobs: + build: success + test: success + release_test: manual + review: created + staging: created + production: created diff --git a/spec/services/ci/pipeline_processing/test_cases/dag_builds_succeed_test_on_failure.yml b/spec/services/ci/pipeline_processing/test_cases/dag_builds_succeed_test_on_failure_deploy_needs_one_build_and_test.yml index f324525bd56..f324525bd56 100644 --- a/spec/services/ci/pipeline_processing/test_cases/dag_builds_succeed_test_on_failure.yml +++ b/spec/services/ci/pipeline_processing/test_cases/dag_builds_succeed_test_on_failure_deploy_needs_one_build_and_test.yml diff --git a/spec/services/ci/pipeline_processing/test_cases/dag_builds_succeed_test_on_failure_deploy_always.yml b/spec/services/ci/pipeline_processing/test_cases/dag_builds_succeed_test_on_failure_deploy_needs_one_build_and_test_when_always.yml index 9986dbaa215..9986dbaa215 100644 --- a/spec/services/ci/pipeline_processing/test_cases/dag_builds_succeed_test_on_failure_deploy_always.yml +++ b/spec/services/ci/pipeline_processing/test_cases/dag_builds_succeed_test_on_failure_deploy_needs_one_build_and_test_when_always.yml diff --git a/spec/services/ci/pipeline_processing/test_cases/dag_deploy_needs_empty.yml b/spec/services/ci/pipeline_processing/test_cases/dag_deploy_needs_empty.yml new file mode 100644 index 00000000000..1783c0acb11 --- /dev/null +++ b/spec/services/ci/pipeline_processing/test_cases/dag_deploy_needs_empty.yml @@ -0,0 +1,27 @@ +config: + build: + stage: build + script: exit 0 + + test: + stage: test + script: exit 0 + + deploy: + stage: deploy + script: exit 0 + needs: [] + +init: + expect: + pipeline: pending + stages: + build: pending + test: created + deploy: pending + jobs: + build: pending + test: created + deploy: pending + +transitions: [] diff --git a/spec/services/ci/pipeline_processing/test_cases/dag_test_allow_failure_true.yml b/spec/services/ci/pipeline_processing/test_cases/dag_test_fails_with_allow_failure.yml index 8d4d9d403f1..8d4d9d403f1 100644 --- a/spec/services/ci/pipeline_processing/test_cases/dag_test_allow_failure_true.yml +++ b/spec/services/ci/pipeline_processing/test_cases/dag_test_fails_with_allow_failure.yml diff --git a/spec/services/ci/pipeline_processing/test_cases/dag_test_manual_allow_failure_false_deploy_always.yml b/spec/services/ci/pipeline_processing/test_cases/dag_test_manual_allow_failure_false_deploy_always.yml new file mode 100644 index 00000000000..bb8723aa303 --- /dev/null +++ b/spec/services/ci/pipeline_processing/test_cases/dag_test_manual_allow_failure_false_deploy_always.yml @@ -0,0 +1,45 @@ +config: + test: + stage: test + when: manual + allow_failure: false + script: exit 1 + + deploy: + stage: deploy + when: always + script: exit 0 + needs: [test] + +init: + expect: + pipeline: manual + stages: + test: manual + deploy: created + jobs: + test: manual + deploy: created + +transitions: + - event: enqueue + jobs: [test] + expect: + pipeline: pending + stages: + test: pending + deploy: created + jobs: + test: pending + deploy: created + + - event: drop + jobs: [test] + expect: + pipeline: running + stages: + test: failed + deploy: pending + jobs: + test: failed + deploy: pending diff --git a/spec/services/ci/pipeline_processing/test_cases/dag_test_manual_allow_failure_false_deploy_on_failure.yml b/spec/services/ci/pipeline_processing/test_cases/dag_test_manual_allow_failure_false_deploy_on_failure.yml new file mode 100644 index 00000000000..3099a94befb --- /dev/null +++ b/spec/services/ci/pipeline_processing/test_cases/dag_test_manual_allow_failure_false_deploy_on_failure.yml @@ -0,0 +1,45 @@ +config: + test: + stage: test + when: manual + allow_failure: false + script: exit 1 + + deploy: + stage: deploy + when: on_failure + script: exit 0 + needs: [test] + +init: + expect: + pipeline: manual + stages: + test: manual + deploy: created + jobs: + test: manual + deploy: created + +transitions: + - event: enqueue + jobs: [test] + expect: + pipeline: pending + stages: + test: pending + deploy: created + jobs: + test: pending + deploy: created + + - event: drop + jobs: [test] + expect: + pipeline: running + stages: + test: failed + deploy: pending + jobs: + test: failed + deploy: pending diff --git a/spec/services/ci/pipeline_processing/test_cases/dag_test_manual_allow_failure_false_other_test_succeeds_deploy_needs_both.yml b/spec/services/ci/pipeline_processing/test_cases/dag_test_manual_allow_failure_false_other_test_succeeds_deploy_needs_both.yml new file mode 100644 index 00000000000..7330a73b5a3 --- /dev/null +++ b/spec/services/ci/pipeline_processing/test_cases/dag_test_manual_allow_failure_false_other_test_succeeds_deploy_needs_both.yml @@ -0,0 +1,40 @@ +config: + test1: + stage: test + script: exit 0 + + test2: + stage: test + when: manual + allow_failure: false + script: exit 1 + + deploy: + stage: deploy + script: exit 0 + needs: [test1, test2] + +init: + expect: + pipeline: running + stages: + test: running + deploy: created + jobs: + test1: pending + test2: manual + deploy: created + +transitions: + - event: success + jobs: [test1] + expect: + pipeline: manual + stages: + test: manual + deploy: created + jobs: + test1: success + test2: manual + deploy: created + diff --git a/spec/services/ci/pipeline_processing/test_cases/dag_test_manual_allow_failure_true_other_test_succeeds.yml b/spec/services/ci/pipeline_processing/test_cases/dag_test_manual_allow_failure_true_other_test_succeeds_deploy_needs_both.yml index 34073b92ccc..34073b92ccc 100644 --- a/spec/services/ci/pipeline_processing/test_cases/dag_test_manual_allow_failure_true_other_test_succeeds.yml +++ b/spec/services/ci/pipeline_processing/test_cases/dag_test_manual_allow_failure_true_other_test_succeeds_deploy_needs_both.yml diff --git a/spec/services/ci/pipeline_processing/test_cases/stage_test_on_failure_with_failure.yml b/spec/services/ci/pipeline_processing/test_cases/stage_build_fails_test_on_failure.yml index 1751cbb2023..1751cbb2023 100644 --- a/spec/services/ci/pipeline_processing/test_cases/stage_test_on_failure_with_failure.yml +++ b/spec/services/ci/pipeline_processing/test_cases/stage_build_fails_test_on_failure.yml diff --git a/spec/services/ci/pipeline_processing/test_cases/stage_build_allow_failure_test_on_failure.yml b/spec/services/ci/pipeline_processing/test_cases/stage_build_fails_with_allow_failure_test_on_failure.yml index 3e081d4411b..3e081d4411b 100644 --- a/spec/services/ci/pipeline_processing/test_cases/stage_build_allow_failure_test_on_failure.yml +++ b/spec/services/ci/pipeline_processing/test_cases/stage_build_fails_with_allow_failure_test_on_failure.yml diff --git a/spec/services/ci/pipeline_processing/test_cases/stage_build_fails_test_allow_failure.yml b/spec/services/ci/pipeline_processing/test_cases/stage_build_succeeds_test_manual_allow_failure_true.yml index 362ac6e4239..2fd85b74d4d 100644 --- a/spec/services/ci/pipeline_processing/test_cases/stage_build_fails_test_allow_failure.yml +++ b/spec/services/ci/pipeline_processing/test_cases/stage_build_succeeds_test_manual_allow_failure_true.yml @@ -1,10 +1,11 @@ config: build: stage: build - script: exit 1 + script: exit 0 test: stage: test + when: manual allow_failure: true script: exit 1 @@ -25,15 +26,15 @@ init: deploy: created transitions: - - event: drop + - event: success jobs: [build] expect: - pipeline: failed + pipeline: running stages: - build: failed + build: success test: skipped - deploy: skipped + deploy: pending jobs: - build: failed - test: skipped - deploy: skipped + build: success + test: manual + deploy: pending diff --git a/spec/services/ci/pipeline_processing/test_cases/stage_test_on_failure_with_success.yml b/spec/services/ci/pipeline_processing/test_cases/stage_build_succeeds_test_on_failure.yml index 15afe1ce8e1..15afe1ce8e1 100644 --- a/spec/services/ci/pipeline_processing/test_cases/stage_test_on_failure_with_success.yml +++ b/spec/services/ci/pipeline_processing/test_cases/stage_build_succeeds_test_on_failure.yml diff --git a/spec/services/ci/pipeline_processing/test_cases/stage_build_test_manual_review_deploy.yml b/spec/services/ci/pipeline_processing/test_cases/stage_build_test_manual_review_deploy.yml new file mode 100644 index 00000000000..2829765fd95 --- /dev/null +++ b/spec/services/ci/pipeline_processing/test_cases/stage_build_test_manual_review_deploy.yml @@ -0,0 +1,79 @@ +config: + stages: [build, test, review, deploy] + + build: + stage: build + script: exit 0 + + test: + stage: test + script: exit 0 + + release_test: + stage: test + when: manual + allow_failure: true + script: exit 0 + + review: + stage: review + script: exit 0 + + staging: + stage: deploy + script: exit 0 + + production: + stage: deploy + script: exit 0 + +init: + expect: + pipeline: pending + stages: + build: pending + test: created + review: created + deploy: created + jobs: + build: pending + test: created + release_test: created + review: created + staging: created + production: created + +transitions: + - event: success + jobs: [build] + expect: + pipeline: running + stages: + build: success + test: pending + review: created + deploy: created + jobs: + build: success + test: pending + release_test: manual + review: created + staging: created + production: created + + - event: success + jobs: [test] + expect: + pipeline: running + stages: + build: success + test: success + review: pending + deploy: created + jobs: + build: success + test: success + release_test: manual + review: pending + staging: created + production: created diff --git a/spec/services/ci/pipeline_processing/test_cases/stage_test_manual_allow_failure_true_deploy_always.yml b/spec/services/ci/pipeline_processing/test_cases/stage_test_manual_allow_failure_true_deploy_always.yml new file mode 100644 index 00000000000..9181c8adf50 --- /dev/null +++ b/spec/services/ci/pipeline_processing/test_cases/stage_test_manual_allow_failure_true_deploy_always.yml @@ -0,0 +1,23 @@ +config: + test: + stage: test + when: manual + allow_failure: true + script: exit 1 + + deploy: + stage: deploy + when: always + script: exit 0 + +init: + expect: + pipeline: pending + stages: + test: skipped + deploy: pending + jobs: + test: manual + deploy: pending + +transitions: [] diff --git a/spec/services/ci/retry_pipeline_service_spec.rb b/spec/services/ci/retry_pipeline_service_spec.rb index fa46d6c4d1d..212c8f99865 100644 --- a/spec/services/ci/retry_pipeline_service_spec.rb +++ b/spec/services/ci/retry_pipeline_service_spec.rb @@ -364,7 +364,7 @@ RSpec.describe Ci::RetryPipelineService, '#execute' do stage: "stage_#{stage_num}", stage_idx: stage_num, pipeline: pipeline, **opts) do |build| - pipeline.update_legacy_status + ::Ci::ProcessPipelineService.new(pipeline).execute end end end |