debian-mirror-gitlab/qa/tasks/ci.rake

69 lines
2.6 KiB
Ruby
Raw Normal View History

2022-10-11 01:57:18 +05:30
# frozen_string_literal: true
namespace :ci do
2023-01-13 00:05:48 +05:30
require_relative "helpers/util"
2022-10-11 01:57:18 +05:30
include Task::Helpers::Util
desc "Detect changes and populate test variables for selective test execution and feature flag testing"
task :detect_changes, [:env_file] do |_, args|
env_file = args[:env_file]
abort("ERROR: Path for environment file must be provided") unless env_file
diff = mr_diff
labels = mr_labels
2022-11-25 23:54:43 +05:30
# Assign mapping of groups to tests in stages other than the groups defined stage
additional_group_spec_list = { 'gitaly' => %w[create] }
2022-10-11 01:57:18 +05:30
2022-11-25 23:54:43 +05:30
qa_changes = QA::Tools::Ci::QaChanges.new(diff, labels, additional_group_spec_list)
2022-10-11 01:57:18 +05:30
logger = qa_changes.logger
logger.info("Analyzing merge request changes")
# skip running tests when only quarantine changes detected
if qa_changes.quarantine_changes?
logger.info(" merge request contains only quarantine changes, e2e test execution will be skipped!")
2023-01-13 00:05:48 +05:30
append_to_file(env_file, "QA_SKIP_ALL_TESTS=true")
2022-10-11 01:57:18 +05:30
next
end
2023-01-13 00:05:48 +05:30
run_all_label_present = mr_labels.include?("pipeline:run-all-e2e")
# on run-all label of framework changes do not infer specific tests
tests = run_all_label_present || qa_changes.framework_changes? ? nil : qa_changes.qa_tests
if run_all_label_present
logger.info(" merge request has pipeline:run-all-e2e label, full test suite will be executed")
append_to_file(env_file, "QA_RUN_ALL_TESTS=true\n")
elsif qa_changes.framework_changes? # run all tests when framework changes detected
2022-10-11 01:57:18 +05:30
logger.info(" merge request contains qa framework changes, full test suite will be executed")
2023-01-13 00:05:48 +05:30
append_to_file(env_file, "QA_FRAMEWORK_CHANGES=true\n")
2022-10-11 01:57:18 +05:30
elsif tests
logger.info(" detected following specs to execute: '#{tests}'")
else
logger.info(" no specific specs to execute detected")
end
# always check all test suites in case a suite is defined but doesn't have any runnable specs
suites = QA::Tools::Ci::NonEmptySuites.new(tests).fetch
append_to_file(env_file, <<~TXT)
QA_SUITES='#{suites}'
2023-01-13 00:05:48 +05:30
QA_TESTS='#{tests}'
2022-10-11 01:57:18 +05:30
TXT
# check if mr contains feature flag changes
feature_flags = QA::Tools::Ci::FfChanges.new(diff).fetch
2023-01-13 00:05:48 +05:30
append_to_file(env_file, "QA_FEATURE_FLAGS='#{feature_flags}'")
2022-10-11 01:57:18 +05:30
end
2023-01-13 00:05:48 +05:30
desc "Export test run metrics to influxdb"
task :export_test_metrics, [:glob] do |_, args|
raise("Metrics file glob pattern is required") unless args[:glob]
QA::Tools::Ci::TestMetrics.export(args[:glob])
end
2023-04-23 21:23:45 +05:30
desc "Get available QA environment variables"
task :env_var_name_list do
puts Gitlab::QA::Runtime::Env.variables.keys.join("\n")
end
2022-10-11 01:57:18 +05:30
end