summaryrefslogtreecommitdiff
path: root/qa/tasks/ci.rake
blob: 435fe8ebb773affe1a6e5dc343448bc3eb96082f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# frozen_string_literal: true

require_relative "helpers/util"

# rubocop:disable Rails/RakeEnvironment
namespace :ci do
  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
    # Assign mapping of groups to tests in stages other than the groups defined stage
    additional_group_spec_list = { 'gitaly' => %w[create] }

    qa_changes = QA::Tools::Ci::QaChanges.new(diff, labels, additional_group_spec_list)
    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!")
      append_to_file(env_file, <<~TXT)
        QA_SKIP_ALL_TESTS=true
      TXT
      next
    end

    tests = qa_changes.qa_tests
    if qa_changes.framework_changes? # run all tests when framework changes detected
      logger.info(" merge request contains qa framework changes, full test suite will be executed")
      append_to_file(env_file, <<~TXT)
        QA_FRAMEWORK_CHANGES=true
      TXT
    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_TESTS='#{tests}'
      QA_SUITES='#{suites}'
    TXT

    # check if mr contains feature flag changes
    feature_flags = QA::Tools::Ci::FfChanges.new(diff).fetch
    append_to_file(env_file, <<~TXT)
      QA_FEATURE_FLAGS='#{feature_flags}'
    TXT
  end

  desc "Download test results from downstream pipeline"
  task :download_test_results, [:trigger_name, :test_report_job_name, :report_path] do |_, args|
    QA::Tools::Ci::TestResults.get(args[:trigger_name], args[:test_report_job_name], args[:report_path])
  end
end
# rubocop:enable Rails/RakeEnvironment