diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-08 21:11:24 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-08 21:11:24 +0300 |
commit | 70b375c29f67bdc8bd7e8ade1d5355444106482d (patch) | |
tree | 7e4fdec178464a016953a9aecfd349441edb9f44 /qa | |
parent | 3de2ce7c6b536d63ea2f93239022eb51fa9241c1 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'qa')
-rw-r--r-- | qa/qa/resource/project.rb | 6 | ||||
-rw-r--r-- | qa/qa/specs/features/browser_ui/1_manage/project/create_project_spec.rb | 5 | ||||
-rw-r--r-- | qa/qa/support/parallel_pipeline_jobs.rb | 74 | ||||
-rw-r--r-- | qa/tasks/knapsack.rake | 25 |
4 files changed, 98 insertions, 12 deletions
diff --git a/qa/qa/resource/project.rb b/qa/qa/resource/project.rb index 501c43d6bd0..53104a51398 100644 --- a/qa/qa/resource/project.rb +++ b/qa/qa/resource/project.rb @@ -13,7 +13,8 @@ module QA :github_personal_access_token, :github_repository_path, :gitlab_repository_path, - :personal_namespace + :personal_namespace, + :description attr_reader :repository_storage @@ -21,7 +22,6 @@ module QA :name, :path, :add_name_uuid, - :description, :runners_token, :visibility, :template_name, @@ -108,7 +108,7 @@ module QA end new_page.choose_name(@name) - new_page.add_description(@description) + new_page.add_description(@description) if @description new_page.set_visibility(@visibility) new_page.disable_initialize_with_sast new_page.disable_initialize_with_readme unless @initialize_with_readme diff --git a/qa/qa/specs/features/browser_ui/1_manage/project/create_project_spec.rb b/qa/qa/specs/features/browser_ui/1_manage/project/create_project_spec.rb index 0063ce2613a..2d4ec6d5f72 100644 --- a/qa/qa/specs/features/browser_ui/1_manage/project/create_project_spec.rb +++ b/qa/qa/specs/features/browser_ui/1_manage/project/create_project_spec.rb @@ -10,7 +10,6 @@ module QA expect(project_page).to have_content( /Project \S?#{project_name}\S+ was successfully created/ ) - expect(project_page).to have_content('create awesome project test') expect(project_page).to have_content('The repository for this project is empty') end end @@ -26,7 +25,7 @@ module QA let(:project) do Resource::Project.fabricate_via_browser_ui! do |project| project.name = project_name - project.description = 'create awesome project test' + project.description = nil end end @@ -38,8 +37,8 @@ module QA let(:project) do Resource::Project.fabricate_via_browser_ui! do |project| project.name = project_name - project.description = 'create awesome project test' project.personal_namespace = Runtime::User.username + project.description = nil end end diff --git a/qa/qa/support/parallel_pipeline_jobs.rb b/qa/qa/support/parallel_pipeline_jobs.rb new file mode 100644 index 00000000000..c37958267de --- /dev/null +++ b/qa/qa/support/parallel_pipeline_jobs.rb @@ -0,0 +1,74 @@ +# frozen_string_literal: true + +module QA + module Support + # Helper utility to fetch parallel job names in a given pipelines stage + # + class ParallelPipelineJobs + include Support::API + + PARALLEL_JOB_NAME_PATTERN = %r{^\S+ \d+/\d+$}.freeze + + def initialize(stage_name:, project_id:, pipeline_id:, access_token:) + @stage_name = stage_name + @access_token = access_token + @project_id = project_id || raise("project_id must be provided") + @pipeline_id = pipeline_id || raise("pipeline_id must be provided") + end + + # Fetch parallel job names in given stage + # + # Default to arguments available on CI + # + # @param [String] stage_name + # @param [Integer] project_id + # @param [Integer] pipeline_id + # @param [String] access_token + # @return [Array] + def self.fetch( + stage_name:, + access_token:, + project_id: ENV["CI_PROJECT_ID"], + pipeline_id: ENV["CI_PIPELINE_ID"] + ) + new( + stage_name: stage_name, + project_id: project_id, + pipeline_id: pipeline_id, + access_token: access_token + ).parallel_jobs + end + + # Parallel job list + # + # @return [Array<String>] + def parallel_jobs + api_get("projects/#{project_id}/pipelines/#{pipeline_id}/jobs?per_page=100") + .select { |job| job[:stage] == stage_name && job[:name].match?(PARALLEL_JOB_NAME_PATTERN) } + .map { |job| job[:name].gsub(%r{ \d+/\d+}, "") } + .uniq + end + + private + + attr_reader :stage_name, :access_token, :project_id, :pipeline_id + + # Api get request + # + # @param [String] path + # @param [Hash] payload + # @return [Hash, Array] + def api_get(path) + response = get("#{api_url}/#{path}", { headers: { "PRIVATE-TOKEN" => access_token } }) + parse_body(response) + end + + # Gitlab api url + # + # @return [String] + def api_url + @api_url ||= ENV['CI_API_V4_URL'] || "https://gitlab.com/api/v4" + end + end + end +end diff --git a/qa/tasks/knapsack.rake b/qa/tasks/knapsack.rake index fe9a9c4586f..c1225964aef 100644 --- a/qa/tasks/knapsack.rake +++ b/qa/tasks/knapsack.rake @@ -1,6 +1,5 @@ # frozen_string_literal: true -# rubocop:disable Rails/RakeEnvironment namespace :knapsack do desc "Run tests with knapsack runner" task :rspec, [:rspec_args] do |_, args| @@ -16,11 +15,26 @@ namespace :knapsack do exit QA::Specs::KnapsackRunner.run(rspec_args) end - desc "Download latest knapsack report or multiple reports passed via QA_KNAPSACK_REPORTS env variable" - task :download do - next QA::Support::KnapsackReport.download_report unless ENV["QA_KNAPSACK_REPORTS"] + desc "Download latest knapsack reports for parallel jobs" + task :download, [:stage_name] do |_, args| + test_stage_name = args[:stage_name] - ENV["QA_KNAPSACK_REPORTS"].split(",").each do |report_name| + # QA_KNAPSACK_REPORTS remains for changes to be backwards compatible + # TODO: remove and only use automated detection once changes are merged + unless ENV["QA_KNAPSACK_REPORTS"] || test_stage_name + QA::Runtime::Logger.warn("Missing QA_KNAPSACK_REPORTS environment variable or test stage name for autodetection") + next + end + + reports = if test_stage_name + QA::Support::ParallelPipelineJobs + .fetch(stage_name: test_stage_name, access_token: ENV["QA_GITLAB_CI_TOKEN"]) + .map { |job| job.tr(":", "-") } + else + ENV["QA_KNAPSACK_REPORTS"].split(",") + end + + reports.each do |report_name| QA::Support::KnapsackReport.new(report_name).download_report rescue StandardError => e QA::Runtime::Logger.error(e) @@ -37,4 +51,3 @@ namespace :knapsack do QA::Tools::LongRunningSpecReporter.execute end end -# rubocop:enable Rails/RakeEnvironment |