diff --git a/app/assets/javascripts/editor/schema/ci.json b/app/assets/javascripts/editor/schema/ci.json index 21c50acbf5d934ed0275deb0a9194c6c63ae565e..f67519712ccb93520c7d517353c2936a66738770 100644 --- a/app/assets/javascripts/editor/schema/ci.json +++ b/app/assets/javascripts/editor/schema/ci.json @@ -758,7 +758,17 @@ "type": "object", "properties": { "value": { - "type": "string" + "type": "string", + "markdownDescription": "Default value of the variable. If used with `options`, `value` must be included in the array. [Learn More](https://docs.gitlab.com/ee/ci/pipelines/index.html#prefill-variables-in-manual-pipelines)" + }, + "options": { + "type": "array", + "items": { + "type": "string" + }, + "minItems": 1, + "uniqueItems": true, + "markdownDescription": "A list of predefined values that users can select from in the **Run pipeline** page when running a pipeline manually. [Learn More](https://docs.gitlab.com/ee/ci/pipelines/index.html#configure-a-list-of-selectable-values-for-a-prefilled-variable)" }, "description": { "type": "string", @@ -1922,4 +1932,4 @@ "additionalProperties": false } } -} +} \ No newline at end of file diff --git a/app/assets/javascripts/pipeline_new/components/legacy_pipeline_new_form.vue b/app/assets/javascripts/pipeline_new/components/legacy_pipeline_new_form.vue deleted file mode 100644 index c3d46d1954a019bb05ea80e93c212f955a8b1a19..0000000000000000000000000000000000000000 --- a/app/assets/javascripts/pipeline_new/components/legacy_pipeline_new_form.vue +++ /dev/null @@ -1,490 +0,0 @@ - - - diff --git a/app/assets/javascripts/pipeline_new/index.js b/app/assets/javascripts/pipeline_new/index.js index 60b4c93d1d50da780e6adfd7ad6e678edbe307f9..71c76aeab36941510ff9ce267ac0cbb5b722d2e6 100644 --- a/app/assets/javascripts/pipeline_new/index.js +++ b/app/assets/javascripts/pipeline_new/index.js @@ -1,53 +1,9 @@ import Vue from 'vue'; import VueApollo from 'vue-apollo'; import createDefaultClient from '~/lib/graphql'; -import LegacyPipelineNewForm from './components/legacy_pipeline_new_form.vue'; import PipelineNewForm from './components/pipeline_new_form.vue'; import { resolvers } from './graphql/resolvers'; -const mountLegacyPipelineNewForm = (el) => { - const { - // provide/inject - projectRefsEndpoint, - - // props - configVariablesPath, - defaultBranch, - fileParam, - maxWarnings, - pipelinesPath, - projectId, - refParam, - settingsLink, - varParam, - } = el.dataset; - - const variableParams = JSON.parse(varParam); - const fileParams = JSON.parse(fileParam); - - return new Vue({ - el, - provide: { - projectRefsEndpoint, - }, - render(createElement) { - return createElement(LegacyPipelineNewForm, { - props: { - configVariablesPath, - defaultBranch, - fileParams, - maxWarnings: Number(maxWarnings), - pipelinesPath, - projectId, - refParam, - settingsLink, - variableParams, - }, - }); - }, - }); -}; - const mountPipelineNewForm = (el) => { const { // provide/inject @@ -101,9 +57,5 @@ const mountPipelineNewForm = (el) => { export default () => { const el = document.getElementById('js-new-pipeline'); - if (gon.features?.runPipelineGraphql) { - mountPipelineNewForm(el); - } else { - mountLegacyPipelineNewForm(el); - } + mountPipelineNewForm(el); }; diff --git a/app/controllers/projects/pipelines_controller.rb b/app/controllers/projects/pipelines_controller.rb index 7d1a75ae449e63f5d2c309f5f2dcdd124a3cce36..ea8c556dc493bc970a24b38156bc79201a49fbe0 100644 --- a/app/controllers/projects/pipelines_controller.rb +++ b/app/controllers/projects/pipelines_controller.rb @@ -26,7 +26,6 @@ class Projects::PipelinesController < Projects::ApplicationController before_action do push_frontend_feature_flag(:pipeline_tabs_vue, @project) - push_frontend_feature_flag(:run_pipeline_graphql, @project) end # Will be removed with https://gitlab.com/gitlab-org/gitlab/-/issues/225596 diff --git a/config/feature_flags/development/run_pipeline_graphql.yml b/config/feature_flags/development/run_pipeline_graphql.yml deleted file mode 100644 index 78d8afbbee5114fbd0768ec542446627b033adc0..0000000000000000000000000000000000000000 --- a/config/feature_flags/development/run_pipeline_graphql.yml +++ /dev/null @@ -1,8 +0,0 @@ ---- -name: run_pipeline_graphql -introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/96633 -rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/372310 -milestone: '15.4' -type: development -group: group::pipeline authoring -default_enabled: false diff --git a/doc/ci/pipelines/index.md b/doc/ci/pipelines/index.md index 2126997e25fb7600696ea491d8197c47a04aacd3..e013f9475d81b3e96583dd0f66a08d56cc4b203f 100644 --- a/doc/ci/pipelines/index.md +++ b/doc/ci/pipelines/index.md @@ -192,11 +192,7 @@ In this example: > - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/363660) in GitLab 15.5 [with a flag](../../administration/feature_flags.md) named `run_pipeline_graphql`. Disabled by default. > - The `options` keyword was [introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/105502) in GitLab 15.7. - -FLAG: -On self-managed GitLab, by default this feature is not available. To make it available, -ask an administrator to [enable the feature flag](../../administration/feature_flags.md) named `run_pipeline_graphql`. -The feature is not ready for production use. +> - [Generally available](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/106038) in GitLab 15.7. Feature flag `run_pipeline_graphql` removed. You can define an array of CI/CD variable values the user can select from when running a pipeline manually. These values are in a dropdown list in the **Run pipeline** page. Add the list of diff --git a/qa/qa/page/project/pipeline/new.rb b/qa/qa/page/project/pipeline/new.rb index f56f69fc077796156d2627185e0a7a764c126431..1d85d072e34c2322bba74ee96af196273647e96b 100644 --- a/qa/qa/page/project/pipeline/new.rb +++ b/qa/qa/page/project/pipeline/new.rb @@ -5,15 +5,6 @@ module Page module Project module Pipeline class New < QA::Page::Base - # TODO: Replace legacy form with the new form when run_pipeline_graphql is enabled by default - # Issue https://gitlab.com/gitlab-org/gitlab/-/issues/372310 - view 'app/assets/javascripts/pipeline_new/components/legacy_pipeline_new_form.vue' do - element :run_pipeline_button, required: true - element :ci_variable_row_container - element :ci_variable_key_field - element :ci_variable_value_field - end - view 'app/assets/javascripts/pipeline_new/components/pipeline_new_form.vue' do element :run_pipeline_button, required: true element :ci_variable_row_container diff --git a/qa/qa/specs/features/browser_ui/4_verify/ci_variable/custom_variable_spec.rb b/qa/qa/specs/features/browser_ui/4_verify/ci_variable/custom_variable_spec.rb index 4a0a8be3659e79ae01cf2344fb8fc0ee5979110b..5dda8b04805be34cee9af2ae2cde0bbcf42fcef5 100644 --- a/qa/qa/specs/features/browser_ui/4_verify/ci_variable/custom_variable_spec.rb +++ b/qa/qa/specs/features/browser_ui/4_verify/ci_variable/custom_variable_spec.rb @@ -2,10 +2,7 @@ module QA RSpec.describe 'Verify', :runner do - describe 'Pipeline with customizable variable', feature_flag: { - name: :run_pipeline_graphql, - scope: :project - } do + describe 'Pipeline with customizable variable' do let(:executor) { "qa-runner-#{Time.now.to_i}" } let(:pipeline_job_name) { 'customizable-variable' } let(:variable_custom_value) { 'Custom Foo' } @@ -48,74 +45,45 @@ module QA end end - shared_examples 'pipeline with custom variable' do - before do - Flow::Login.sign_in + before do + Flow::Login.sign_in - project.visit! - Page::Project::Menu.perform(&:click_ci_cd_pipelines) - Page::Project::Pipeline::Index.perform(&:click_run_pipeline_button) + project.visit! + Page::Project::Menu.perform(&:click_ci_cd_pipelines) + Page::Project::Pipeline::Index.perform(&:click_run_pipeline_button) - # Sometimes the variables will not be prefilled because of reactive cache so we revisit the page again. - # TODO: Investigate alternatives to deal with cache implementation - # Issue https://gitlab.com/gitlab-org/gitlab/-/issues/381233 - page.refresh - end - - after do - runner&.remove_via_api! - end - - it 'manually creates a pipeline and uses the defined custom variable value' do - Page::Project::Pipeline::New.perform do |new| - new.configure_variable(value: variable_custom_value) - new.click_run_pipeline_button - end - - Page::Project::Pipeline::Show.perform do |show| - Support::Waiter.wait_until { show.passed? } - end - - job = Resource::Job.fabricate_via_api! do |job| - job.id = project.job_by_name(pipeline_job_name)[:id] - job.name = pipeline_job_name - job.project = project - end - - job.visit! + # Sometimes the variables will not be prefilled because of reactive cache so we revisit the page again. + # TODO: Investigate alternatives to deal with cache implementation + # Issue https://gitlab.com/gitlab-org/gitlab/-/issues/381233 + page.refresh + end - Page::Project::Job::Show.perform do |show| - expect(show.output).to have_content(variable_custom_value) - end - end + after do + runner&.remove_via_api! end - # TODO: Clean up tests when run_pipeline_graphql is enabled - # Issue https://gitlab.com/gitlab-org/gitlab/-/issues/372310 - context( - 'with feature flag disabled', - testcase: 'https://gitlab.com/gitlab-org/gitlab/-/quality/test_cases/361814' - ) do - before do - Runtime::Feature.disable(:run_pipeline_graphql, project: project) + it 'manually creates a pipeline and uses the defined custom variable value', + testcase: 'https://gitlab.com/gitlab-org/gitlab/-/quality/test_cases/378975' do + Page::Project::Pipeline::New.perform do |new| + new.configure_variable(value: variable_custom_value) + new.click_run_pipeline_button end - it_behaves_like 'pipeline with custom variable' - end - - context( - 'with feature flag enabled', - testcase: 'https://gitlab.com/gitlab-org/gitlab/-/quality/test_cases/378975' - ) do - before do - Runtime::Feature.enable(:run_pipeline_graphql, project: project) + Page::Project::Pipeline::Show.perform do |show| + Support::Waiter.wait_until { show.passed? } end - after do - Runtime::Feature.disable(:run_pipeline_graphql, project: project) + job = Resource::Job.fabricate_via_api! do |job| + job.id = project.job_by_name(pipeline_job_name)[:id] + job.name = pipeline_job_name + job.project = project end - it_behaves_like 'pipeline with custom variable' + job.visit! + + Page::Project::Job::Show.perform do |show| + expect(show.output).to have_content(variable_custom_value) + end end end end diff --git a/qa/qa/specs/features/browser_ui/4_verify/ci_variable/prefill_variables_spec.rb b/qa/qa/specs/features/browser_ui/4_verify/ci_variable/prefill_variables_spec.rb index c5112ebedc68d651ce6822f441d5a2fda76b8827..1878292015e57883daf910f42c868fae5aa94d18 100644 --- a/qa/qa/specs/features/browser_ui/4_verify/ci_variable/prefill_variables_spec.rb +++ b/qa/qa/specs/features/browser_ui/4_verify/ci_variable/prefill_variables_spec.rb @@ -2,10 +2,7 @@ module QA RSpec.describe 'Verify' do - describe 'Pipeline with prefill variables', feature_flag: { - name: :run_pipeline_graphql, - scope: :global - } do + describe 'Pipeline with prefill variables' do let(:prefill_variable_description1) { Faker::Lorem.sentence } let(:prefill_variable_value1) { Faker::Lorem.word } let(:prefill_variable_value5) { Faker::Lorem.word } @@ -50,93 +47,51 @@ module QA end end - shared_examples 'pre-filled variables form' do |testcase| - it 'shows only variables with description as prefill variables on the run pipeline page', testcase: testcase do - Page::Project::Pipeline::New.perform do |new| - aggregate_failures do - expect(new).to have_field('Input variable key', with: 'TEST1') - expect(new).to have_field('Input variable value', with: prefill_variable_value1) - expect(new).to have_content(prefill_variable_description1) + before do + Flow::Login.sign_in + project.visit! - expect(new).to have_field('Input variable key', with: 'TEST2') - expect(new).to have_field('Input variable value', with: '') - expect(new).to have_content(prefill_variable_description2) + # Navigate to Run Pipeline page + Page::Project::Menu.perform(&:click_ci_cd_pipelines) + Page::Project::Pipeline::Index.perform(&:click_run_pipeline_button) - expect(new).not_to have_field('Input variable key', with: 'TEST3') - expect(new).not_to have_field('Input variable key', with: 'TEST4') - - # Legacy and GQL app will render the variable field differently - expect(new).to have_field('Input variable key', with: 'TEST5') - expect(new).to have_content(prefill_variable_description5) - end - end - end + # Sometimes the variables will not be prefilled because of reactive cache so we revisit the page again. + # TODO: Investigate alternatives to deal with cache implementation + # Issue https://gitlab.com/gitlab-org/gitlab/-/issues/381233 + page.refresh end - # TODO: Clean up tests when run_pipeline_graphql is enabled - # Issue https://gitlab.com/gitlab-org/gitlab/-/issues/372310 - context 'with feature flag disabled' do - before do - Flow::Login.sign_in - project.visit! + it 'shows only variables with description as prefill variables on the run pipeline page', + testcase: 'https://gitlab.com/gitlab-org/gitlab/-/quality/test_cases/378977' do + Page::Project::Pipeline::New.perform do |new| + aggregate_failures do + expect(new).to have_field('Input variable key', with: 'TEST1') + expect(new).to have_field('Input variable value', with: prefill_variable_value1) + expect(new).to have_content(prefill_variable_description1) - # Navigate to Run Pipeline page - Page::Project::Menu.perform(&:click_ci_cd_pipelines) - Page::Project::Pipeline::Index.perform(&:click_run_pipeline_button) + expect(new).to have_field('Input variable key', with: 'TEST2') + expect(new).to have_field('Input variable value', with: '') + expect(new).to have_content(prefill_variable_description2) - # Sometimes the variables will not be prefilled because of reactive cache so we revisit the page again. - # TODO: Investigate alternatives to deal with cache implementation - # Issue https://gitlab.com/gitlab-org/gitlab/-/issues/381233 - page.refresh - end + expect(new).not_to have_field('Input variable key', with: 'TEST3') + expect(new).not_to have_field('Input variable key', with: 'TEST4') - it_behaves_like 'pre-filled variables form', 'https://gitlab.com/gitlab-org/gitlab/-/quality/test_cases/371204' - - it 'does not prefill dropdown variables but renders them as input fields', - testcase: 'https://gitlab.com/gitlab-org/gitlab/-/quality/test_cases/383819' do - Page::Project::Pipeline::New.perform do |new| - expect(new.has_variable_dropdown?).to be(false) - expect(new).to have_field('Input variable value', with: 'FOO') + expect(new).to have_field('Input variable key', with: 'TEST5') + expect(new).to have_content(prefill_variable_description5) end end end - context 'with feature flag enabled' do - before do - Runtime::Feature.enable(:run_pipeline_graphql) - sleep 60 - - Flow::Login.sign_in - project.visit! - - # Navigate to Run Pipeline page - Page::Project::Menu.perform(&:click_ci_cd_pipelines) - Page::Project::Pipeline::Index.perform(&:click_run_pipeline_button) - - # Sometimes the variables will not be prefilled because of reactive cache so we revisit the page again. - # TODO: Investigate alternatives to deal with cache implementation - # Issue https://gitlab.com/gitlab-org/gitlab/-/issues/381233 - page.refresh - end - - after do - Runtime::Feature.disable(:run_pipeline_graphql) - sleep 60 - end - - it_behaves_like 'pre-filled variables form', 'https://gitlab.com/gitlab-org/gitlab/-/quality/test_cases/378977' - - it 'shows dropdown for variables with description, value, and options defined', - testcase: 'https://gitlab.com/gitlab-org/gitlab/-/quality/test_cases/383820' do - Page::Project::Pipeline::New.perform do |new| - aggregate_failures do - expect(new.variable_dropdown).to have_text('FOO') + it 'shows dropdown for variables with description, value, and options defined', + testcase: 'https://gitlab.com/gitlab-org/gitlab/-/quality/test_cases/383820' do + Page::Project::Pipeline::New.perform do |new| + aggregate_failures do + expect(new.variable_dropdown).to have_text('FOO') - new.click_variable_dropdown + new.click_variable_dropdown - expect(new.variable_dropdown_item_with_index(0)).to have_text(prefill_variable_value5) - expect(new.variable_dropdown_item_with_index(1)).to have_text('FOO') - end + expect(new.variable_dropdown_item_with_index(0)).to have_text(prefill_variable_value5) + expect(new.variable_dropdown_item_with_index(1)).to have_text('FOO') end end end diff --git a/spec/features/populate_new_pipeline_vars_with_params_spec.rb b/spec/features/populate_new_pipeline_vars_with_params_spec.rb index 0943b018693f55f9304da48084b43f12610e7e38..a83b5a81a41f6e8d363d03146f08b5cea788e135 100644 --- a/spec/features/populate_new_pipeline_vars_with_params_spec.rb +++ b/spec/features/populate_new_pipeline_vars_with_params_spec.rb @@ -7,42 +7,24 @@ let(:project) { create(:project) } let(:page_path) { new_project_pipeline_path(project) } - shared_examples 'form pre-filled with URL params' do - before do - sign_in(user) - project.add_maintainer(user) + before do + sign_in(user) + project.add_maintainer(user) - visit "#{page_path}?var[key1]=value1&file_var[key2]=value2" - end - - it "var[key1]=value1 populates env_var variable correctly" do - page.within(all("[data-testid='ci-variable-row']")[0]) do - expect(find("[data-testid='pipeline-form-ci-variable-key']").value).to eq('key1') - expect(find("[data-testid='pipeline-form-ci-variable-value']").value).to eq('value1') - end - end - - it "file_var[key2]=value2 populates file variable correctly" do - page.within(all("[data-testid='ci-variable-row']")[1]) do - expect(find("[data-testid='pipeline-form-ci-variable-key']").value).to eq('key2') - expect(find("[data-testid='pipeline-form-ci-variable-value']").value).to eq('value2') - end - end + visit "#{page_path}?var[key1]=value1&file_var[key2]=value2" end - context 'when feature flag is disabled' do - before do - stub_feature_flags(run_pipeline_graphql: false) + it "var[key1]=value1 populates env_var variable correctly" do + page.within(all("[data-testid='ci-variable-row']")[0]) do + expect(find("[data-testid='pipeline-form-ci-variable-key']").value).to eq('key1') + expect(find("[data-testid='pipeline-form-ci-variable-value']").value).to eq('value1') end - - it_behaves_like 'form pre-filled with URL params' end - context 'when feature flag is enabled' do - before do - stub_feature_flags(run_pipeline_graphql: true) + it "file_var[key2]=value2 populates file variable correctly" do + page.within(all("[data-testid='ci-variable-row']")[1]) do + expect(find("[data-testid='pipeline-form-ci-variable-key']").value).to eq('key2') + expect(find("[data-testid='pipeline-form-ci-variable-value']").value).to eq('value2') end - - it_behaves_like 'form pre-filled with URL params' end end diff --git a/spec/features/projects/pipelines/legacy_pipelines_spec.rb b/spec/features/projects/pipelines/legacy_pipelines_spec.rb index 0da5fc81da09c59f8b3aa05c8a2d8e9dfd0b665b..b6ae4144709009de345aed781effd62189442a78 100644 --- a/spec/features/projects/pipelines/legacy_pipelines_spec.rb +++ b/spec/features/projects/pipelines/legacy_pipelines_spec.rb @@ -673,7 +673,6 @@ def create_build(stage, stage_idx, name, status) let(:project) { create(:project, :repository) } before do - stub_feature_flags(run_pipeline_graphql: false) visit new_project_pipeline_path(project) end diff --git a/spec/features/projects/pipelines/pipelines_spec.rb b/spec/features/projects/pipelines/pipelines_spec.rb index 14151ad0a6a10c636078edac675df0a48c3023ed..3bdabd672c7fba661ce174aae1d04514e8996dc8 100644 --- a/spec/features/projects/pipelines/pipelines_spec.rb +++ b/spec/features/projects/pipelines/pipelines_spec.rb @@ -663,7 +663,19 @@ def create_build(stage, stage_idx, name, status) describe 'POST /:project/-/pipelines' do let(:project) { create(:project, :repository) } - shared_examples 'run pipeline form with gitlab-ci.yml' do + before do + visit new_project_pipeline_path(project) + end + + context 'for valid commit', :js do + before do + click_button project.default_branch + wait_for_requests + + find('p', text: 'master').click + wait_for_requests + end + context 'with gitlab-ci.yml', :js do before do stub_ci_pipeline_to_return_yaml_file @@ -697,9 +709,7 @@ def create_build(stage, stage_idx, name, status) end end end - end - shared_examples 'run pipeline form without gitlab-ci.yml' do context 'without gitlab-ci.yml' do before do click_on 'Run pipeline' @@ -719,52 +729,6 @@ def create_build(stage, stage_idx, name, status) end end end - - # Run Pipeline form with REST endpoints - # TODO: Clean up tests when run_pipeline_graphql is enabled - # Issue https://gitlab.com/gitlab-org/gitlab/-/issues/372310 - context 'with feature flag disabled' do - before do - stub_feature_flags(run_pipeline_graphql: false) - visit new_project_pipeline_path(project) - end - - context 'for valid commit', :js do - before do - click_button project.default_branch - wait_for_requests - - find('p', text: 'master').click - wait_for_requests - end - - it_behaves_like 'run pipeline form with gitlab-ci.yml' - - it_behaves_like 'run pipeline form without gitlab-ci.yml' - end - end - - # Run Pipeline form with GraphQL - context 'with feature flag enabled' do - before do - stub_feature_flags(run_pipeline_graphql: true) - visit new_project_pipeline_path(project) - end - - context 'for valid commit', :js do - before do - click_button project.default_branch - wait_for_requests - - find('p', text: 'master').click - wait_for_requests - end - - it_behaves_like 'run pipeline form with gitlab-ci.yml' - - it_behaves_like 'run pipeline form without gitlab-ci.yml' - end - end end describe 'Reset runner caches' do diff --git a/spec/frontend/editor/schema/ci/ci_schema_spec.js b/spec/frontend/editor/schema/ci/ci_schema_spec.js index a06f81e4d1c9f233e4d6e10aa99dd7b9cfefafd3..b8b91eb816771e9dda44b402c0f0c90b8cba269a 100644 --- a/spec/frontend/editor/schema/ci/ci_schema_spec.js +++ b/spec/frontend/editor/schema/ci/ci_schema_spec.js @@ -45,6 +45,7 @@ import ProjectPathIncludeNoSlashYaml from './yaml_tests/negative_tests/project_p import ProjectPathIncludeTailSlashYaml from './yaml_tests/negative_tests/project_path/include/tailing_slash.yml'; import RulesNegativeYaml from './yaml_tests/negative_tests/rules.yml'; import TriggerNegative from './yaml_tests/negative_tests/trigger.yml'; +import VariablesInvalidOptionsYaml from './yaml_tests/negative_tests/variables/invalid_options.yml'; import VariablesInvalidSyntaxDescYaml from './yaml_tests/negative_tests/variables/invalid_syntax_desc.yml'; import VariablesWrongSyntaxUsageExpand from './yaml_tests/negative_tests/variables/wrong_syntax_usage_expand.yml'; import IdTokensNegativeYaml from './yaml_tests/negative_tests/id_tokens.yml'; @@ -113,6 +114,7 @@ describe('negative tests', () => { IncludeNegativeYaml, JobWhenNegativeYaml, RulesNegativeYaml, + VariablesInvalidOptionsYaml, VariablesInvalidSyntaxDescYaml, VariablesWrongSyntaxUsageExpand, ProjectPathIncludeEmptyYaml, diff --git a/spec/frontend/editor/schema/ci/yaml_tests/negative_tests/variables/invalid_options.yml b/spec/frontend/editor/schema/ci/yaml_tests/negative_tests/variables/invalid_options.yml new file mode 100644 index 0000000000000000000000000000000000000000..aac4c4e456dc76b54e69f28f451ee1070dbd3653 --- /dev/null +++ b/spec/frontend/editor/schema/ci/yaml_tests/negative_tests/variables/invalid_options.yml @@ -0,0 +1,4 @@ +variables: + INVALID_OPTIONS: + value: "staging" + options: "staging" # must be an array diff --git a/spec/frontend/editor/schema/ci/yaml_tests/positive_tests/variables.yml b/spec/frontend/editor/schema/ci/yaml_tests/positive_tests/variables.yml index 53d020c432faa2dbc0575db27f0c7fdf480b002d..5c91de9be70c49542bcd7db5fd936dc741e7532b 100644 --- a/spec/frontend/editor/schema/ci/yaml_tests/positive_tests/variables.yml +++ b/spec/frontend/editor/schema/ci/yaml_tests/positive_tests/variables.yml @@ -4,11 +4,18 @@ variables: FOO: value: "BAR" description: "A single value variable" - DEPLOY_ENVIRONMENT: + VAR_WITH_DESCRIPTION: description: "A multi-value variable" RAW_VAR: value: "Hello $FOO" expand: false + VAR_WITH_OPTIONS: + value: "staging" + options: + - "production" + - "staging" + - "canary" + description: "The deployment target. Set to 'production' by default." rspec: script: rspec diff --git a/spec/frontend/pipeline_new/components/legacy_pipeline_new_form_spec.js b/spec/frontend/pipeline_new/components/legacy_pipeline_new_form_spec.js deleted file mode 100644 index 512b152f106d8d8859a38e08f6bb50dedd17d86b..0000000000000000000000000000000000000000 --- a/spec/frontend/pipeline_new/components/legacy_pipeline_new_form_spec.js +++ /dev/null @@ -1,456 +0,0 @@ -import { GlForm, GlSprintf, GlLoadingIcon } from '@gitlab/ui'; -import { mount, shallowMount } from '@vue/test-utils'; -import MockAdapter from 'axios-mock-adapter'; -import { nextTick } from 'vue'; -import CreditCardValidationRequiredAlert from 'ee_component/billings/components/cc_validation_required_alert.vue'; -import { TEST_HOST } from 'helpers/test_constants'; -import waitForPromises from 'helpers/wait_for_promises'; -import axios from '~/lib/utils/axios_utils'; -import httpStatusCodes from '~/lib/utils/http_status'; -import { redirectTo } from '~/lib/utils/url_utility'; -import LegacyPipelineNewForm from '~/pipeline_new/components/legacy_pipeline_new_form.vue'; -import RefsDropdown from '~/pipeline_new/components/refs_dropdown.vue'; -import { - mockQueryParams, - mockPostParams, - mockProjectId, - mockError, - mockRefs, - mockCreditCardValidationRequiredError, -} from '../mock_data'; - -jest.mock('~/lib/utils/url_utility', () => ({ - redirectTo: jest.fn(), -})); - -const projectRefsEndpoint = '/root/project/refs'; -const pipelinesPath = '/root/project/-/pipelines'; -const configVariablesPath = '/root/project/-/pipelines/config_variables'; -const newPipelinePostResponse = { id: 1 }; -const defaultBranch = 'main'; - -describe('Pipeline New Form', () => { - let wrapper; - let mock; - let dummySubmitEvent; - - const findForm = () => wrapper.findComponent(GlForm); - const findRefsDropdown = () => wrapper.findComponent(RefsDropdown); - const findSubmitButton = () => wrapper.find('[data-testid="run_pipeline_button"]'); - const findVariableRows = () => wrapper.findAll('[data-testid="ci-variable-row"]'); - const findRemoveIcons = () => wrapper.findAll('[data-testid="remove-ci-variable-row"]'); - const findDropdowns = () => wrapper.findAll('[data-testid="pipeline-form-ci-variable-type"]'); - const findKeyInputs = () => wrapper.findAll('[data-testid="pipeline-form-ci-variable-key"]'); - const findValueInputs = () => wrapper.findAll('[data-testid="pipeline-form-ci-variable-value"]'); - const findErrorAlert = () => wrapper.find('[data-testid="run-pipeline-error-alert"]'); - const findWarningAlert = () => wrapper.find('[data-testid="run-pipeline-warning-alert"]'); - const findWarningAlertSummary = () => findWarningAlert().findComponent(GlSprintf); - const findWarnings = () => wrapper.findAll('[data-testid="run-pipeline-warning"]'); - const findLoadingIcon = () => wrapper.findComponent(GlLoadingIcon); - const findCCAlert = () => wrapper.findComponent(CreditCardValidationRequiredAlert); - const getFormPostParams = () => JSON.parse(mock.history.post[0].data); - - const selectBranch = (branch) => { - // Select a branch in the dropdown - findRefsDropdown().vm.$emit('input', { - shortName: branch, - fullName: `refs/heads/${branch}`, - }); - }; - - const createComponent = (props = {}, method = shallowMount) => { - wrapper = method(LegacyPipelineNewForm, { - provide: { - projectRefsEndpoint, - }, - propsData: { - projectId: mockProjectId, - pipelinesPath, - configVariablesPath, - defaultBranch, - refParam: defaultBranch, - settingsLink: '', - maxWarnings: 25, - ...props, - }, - }); - }; - - beforeEach(() => { - mock = new MockAdapter(axios); - mock.onGet(configVariablesPath).reply(httpStatusCodes.OK, {}); - mock.onGet(projectRefsEndpoint).reply(httpStatusCodes.OK, mockRefs); - - dummySubmitEvent = { - preventDefault: jest.fn(), - }; - }); - - afterEach(() => { - wrapper.destroy(); - wrapper = null; - - mock.restore(); - }); - - describe('Form', () => { - beforeEach(async () => { - createComponent(mockQueryParams, mount); - - mock.onPost(pipelinesPath).reply(httpStatusCodes.OK, newPipelinePostResponse); - - await waitForPromises(); - }); - - it('displays the correct values for the provided query params', async () => { - expect(findDropdowns().at(0).props('text')).toBe('Variable'); - expect(findDropdowns().at(1).props('text')).toBe('File'); - expect(findRefsDropdown().props('value')).toEqual({ shortName: 'tag-1' }); - expect(findVariableRows()).toHaveLength(3); - }); - - it('displays a variable from provided query params', () => { - expect(findKeyInputs().at(0).element.value).toBe('test_var'); - expect(findValueInputs().at(0).element.value).toBe('test_var_val'); - }); - - it('displays an empty variable for the user to fill out', async () => { - expect(findKeyInputs().at(2).element.value).toBe(''); - expect(findValueInputs().at(2).element.value).toBe(''); - expect(findDropdowns().at(2).props('text')).toBe('Variable'); - }); - - it('does not display remove icon for last row', () => { - expect(findRemoveIcons()).toHaveLength(2); - }); - - it('removes ci variable row on remove icon button click', async () => { - findRemoveIcons().at(1).trigger('click'); - - await nextTick(); - - expect(findVariableRows()).toHaveLength(2); - }); - - it('creates blank variable on input change event', async () => { - const input = findKeyInputs().at(2); - input.element.value = 'test_var_2'; - input.trigger('change'); - - await nextTick(); - - expect(findVariableRows()).toHaveLength(4); - expect(findKeyInputs().at(3).element.value).toBe(''); - expect(findValueInputs().at(3).element.value).toBe(''); - }); - }); - - describe('Pipeline creation', () => { - beforeEach(async () => { - mock.onPost(pipelinesPath).reply(httpStatusCodes.OK, newPipelinePostResponse); - - await waitForPromises(); - }); - - it('does not submit the native HTML form', async () => { - createComponent(); - - findForm().vm.$emit('submit', dummySubmitEvent); - - expect(dummySubmitEvent.preventDefault).toHaveBeenCalled(); - }); - - it('disables the submit button immediately after submitting', async () => { - createComponent(); - - expect(findSubmitButton().props('disabled')).toBe(false); - - findForm().vm.$emit('submit', dummySubmitEvent); - await waitForPromises(); - - expect(findSubmitButton().props('disabled')).toBe(true); - }); - - it('creates pipeline with full ref and variables', async () => { - createComponent(); - - findForm().vm.$emit('submit', dummySubmitEvent); - await waitForPromises(); - - expect(getFormPostParams().ref).toEqual(`refs/heads/${defaultBranch}`); - expect(redirectTo).toHaveBeenCalledWith(`${pipelinesPath}/${newPipelinePostResponse.id}`); - }); - - it('creates a pipeline with short ref and variables from the query params', async () => { - createComponent(mockQueryParams); - - await waitForPromises(); - - findForm().vm.$emit('submit', dummySubmitEvent); - - await waitForPromises(); - - expect(getFormPostParams()).toEqual(mockPostParams); - expect(redirectTo).toHaveBeenCalledWith(`${pipelinesPath}/${newPipelinePostResponse.id}`); - }); - }); - - describe('When the ref has been changed', () => { - beforeEach(async () => { - createComponent({}, mount); - - await waitForPromises(); - }); - it('variables persist between ref changes', async () => { - selectBranch('main'); - - await waitForPromises(); - - const mainInput = findKeyInputs().at(0); - mainInput.element.value = 'build_var'; - mainInput.trigger('change'); - - await nextTick(); - - selectBranch('branch-1'); - - await waitForPromises(); - - const branchOneInput = findKeyInputs().at(0); - branchOneInput.element.value = 'deploy_var'; - branchOneInput.trigger('change'); - - await nextTick(); - - selectBranch('main'); - - await waitForPromises(); - - expect(findKeyInputs().at(0).element.value).toBe('build_var'); - expect(findVariableRows().length).toBe(2); - - selectBranch('branch-1'); - - await waitForPromises(); - - expect(findKeyInputs().at(0).element.value).toBe('deploy_var'); - expect(findVariableRows().length).toBe(2); - }); - }); - - describe('when yml defines a variable', () => { - const mockYmlKey = 'yml_var'; - const mockYmlValue = 'yml_var_val'; - const mockYmlMultiLineValue = `A value - with multiple - lines`; - const mockYmlDesc = 'A var from yml.'; - - it('loading icon is shown when content is requested and hidden when received', async () => { - createComponent(mockQueryParams, mount); - - mock.onGet(configVariablesPath).reply(httpStatusCodes.OK, { - [mockYmlKey]: { - value: mockYmlValue, - description: mockYmlDesc, - }, - }); - - expect(findLoadingIcon().exists()).toBe(true); - - await waitForPromises(); - - expect(findLoadingIcon().exists()).toBe(false); - }); - - it('multi-line strings are added to the value field without removing line breaks', async () => { - createComponent(mockQueryParams, mount); - - mock.onGet(configVariablesPath).reply(httpStatusCodes.OK, { - [mockYmlKey]: { - value: mockYmlMultiLineValue, - description: mockYmlDesc, - }, - }); - - await waitForPromises(); - - expect(findValueInputs().at(0).element.value).toBe(mockYmlMultiLineValue); - }); - - describe('with description', () => { - beforeEach(async () => { - createComponent(mockQueryParams, mount); - - mock.onGet(configVariablesPath).reply(httpStatusCodes.OK, { - [mockYmlKey]: { - value: mockYmlValue, - description: mockYmlDesc, - }, - }); - - await waitForPromises(); - }); - - it('displays all the variables', async () => { - expect(findVariableRows()).toHaveLength(4); - }); - - it('displays a variable from yml', () => { - expect(findKeyInputs().at(0).element.value).toBe(mockYmlKey); - expect(findValueInputs().at(0).element.value).toBe(mockYmlValue); - }); - - it('displays a variable from provided query params', () => { - expect(findKeyInputs().at(1).element.value).toBe('test_var'); - expect(findValueInputs().at(1).element.value).toBe('test_var_val'); - }); - - it('adds a description to the first variable from yml', () => { - expect(findVariableRows().at(0).text()).toContain(mockYmlDesc); - }); - - it('removes the description when a variable key changes', async () => { - findKeyInputs().at(0).element.value = 'yml_var_modified'; - findKeyInputs().at(0).trigger('change'); - - await nextTick(); - - expect(findVariableRows().at(0).text()).not.toContain(mockYmlDesc); - }); - }); - - describe('without description', () => { - beforeEach(async () => { - createComponent(mockQueryParams, mount); - - mock.onGet(configVariablesPath).reply(httpStatusCodes.OK, { - [mockYmlKey]: { - value: mockYmlValue, - description: null, - }, - yml_var2: { - value: 'yml_var2_val', - }, - yml_var3: { - description: '', - }, - }); - - await waitForPromises(); - }); - - it('displays all the variables', async () => { - expect(findVariableRows()).toHaveLength(3); - }); - }); - }); - - describe('Form errors and warnings', () => { - beforeEach(() => { - createComponent(); - }); - - describe('when the refs cannot be loaded', () => { - beforeEach(() => { - mock - .onGet(projectRefsEndpoint, { params: { search: '' } }) - .reply(httpStatusCodes.INTERNAL_SERVER_ERROR); - - findRefsDropdown().vm.$emit('loadingError'); - }); - - it('shows both an error alert', () => { - expect(findErrorAlert().exists()).toBe(true); - expect(findWarningAlert().exists()).toBe(false); - }); - }); - - describe('when the error response can be handled', () => { - beforeEach(async () => { - mock.onPost(pipelinesPath).reply(httpStatusCodes.BAD_REQUEST, mockError); - - findForm().vm.$emit('submit', dummySubmitEvent); - - await waitForPromises(); - }); - - it('shows both error and warning', () => { - expect(findErrorAlert().exists()).toBe(true); - expect(findWarningAlert().exists()).toBe(true); - }); - - it('shows the correct error', () => { - expect(findErrorAlert().text()).toBe(mockError.errors[0]); - }); - - it('shows the correct warning title', () => { - const { length } = mockError.warnings; - - expect(findWarningAlertSummary().attributes('message')).toBe(`${length} warnings found:`); - }); - - it('shows the correct amount of warnings', () => { - expect(findWarnings()).toHaveLength(mockError.warnings.length); - }); - - it('re-enables the submit button', () => { - expect(findSubmitButton().props('disabled')).toBe(false); - }); - - it('does not show the credit card validation required alert', () => { - expect(findCCAlert().exists()).toBe(false); - }); - - describe('when the error response is credit card validation required', () => { - beforeEach(async () => { - mock - .onPost(pipelinesPath) - .reply(httpStatusCodes.BAD_REQUEST, mockCreditCardValidationRequiredError); - - window.gon = { - subscriptions_url: TEST_HOST, - payment_form_url: TEST_HOST, - }; - - findForm().vm.$emit('submit', dummySubmitEvent); - - await waitForPromises(); - }); - - it('shows credit card validation required alert', () => { - expect(findErrorAlert().exists()).toBe(false); - expect(findCCAlert().exists()).toBe(true); - }); - - it('clears error and hides the alert on dismiss', async () => { - expect(findCCAlert().exists()).toBe(true); - expect(wrapper.vm.$data.error).toBe(mockCreditCardValidationRequiredError.errors[0]); - - findCCAlert().vm.$emit('dismiss'); - - await nextTick(); - - expect(findCCAlert().exists()).toBe(false); - expect(wrapper.vm.$data.error).toBe(null); - }); - }); - }); - - describe('when the error response cannot be handled', () => { - beforeEach(async () => { - mock - .onPost(pipelinesPath) - .reply(httpStatusCodes.INTERNAL_SERVER_ERROR, 'something went wrong'); - - findForm().vm.$emit('submit', dummySubmitEvent); - - await waitForPromises(); - }); - - it('re-enables the submit button', () => { - expect(findSubmitButton().props('disabled')).toBe(false); - }); - }); - }); -});