Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-11-08 15:12:07 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-11-08 15:12:07 +0300
commit6a380347147d1a55afbc6a1c16e04b567ab90d86 (patch)
tree9854eb7894cbe8a47976cce0289aa861df79eee3 /tooling
parent4901ff1764398bb017487d4a5104b74bc284f33a (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'tooling')
-rwxr-xr-xtooling/bin/find_change_diffs15
-rwxr-xr-xtooling/bin/qa/check_if_only_quarantined_specs18
-rwxr-xr-xtooling/bin/qa/package_and_qa_check45
3 files changed, 58 insertions, 20 deletions
diff --git a/tooling/bin/find_change_diffs b/tooling/bin/find_change_diffs
index 8ac26d56476..7857945ea74 100755
--- a/tooling/bin/find_change_diffs
+++ b/tooling/bin/find_change_diffs
@@ -5,11 +5,22 @@ require 'gitlab'
require 'pathname'
# This script saves the diffs of changes in an MR to the directory specified as the first argument
+#
+# It exits with a success code if diffs are found and saved, or if there are no changes, including if the script runs in
+# a pipeline that is not for a merge request.
gitlab_token = ENV.fetch('PROJECT_TOKEN_FOR_CI_SCRIPTS_API_USAGE')
gitlab_endpoint = ENV.fetch('CI_API_V4_URL')
-mr_project_path = ENV.fetch('CI_MERGE_REQUEST_PROJECT_PATH')
-mr_iid = ENV.fetch('CI_MERGE_REQUEST_IID')
+mr_project_path = ENV['CI_MERGE_REQUEST_PROJECT_PATH']
+mr_iid = ENV['CI_MERGE_REQUEST_IID']
+
+puts "CI_MERGE_REQUEST_PROJECT_PATH is missing." if mr_project_path.to_s.empty?
+puts "CI_MERGE_REQUEST_IID is missing." if mr_iid.to_s.empty?
+
+unless mr_project_path && mr_iid
+ puts "Exiting as this does not appear to be a merge request pipeline."
+ exit
+end
abort("ERROR: Please specify a directory to write MR diffs into.") if ARGV.empty?
output_diffs_dir = Pathname.new(ARGV.shift).expand_path
diff --git a/tooling/bin/qa/check_if_only_quarantined_specs b/tooling/bin/qa/check_if_only_quarantined_specs
deleted file mode 100755
index 8a36761c58a..00000000000
--- a/tooling/bin/qa/check_if_only_quarantined_specs
+++ /dev/null
@@ -1,18 +0,0 @@
-#!/usr/bin/env ruby
-# frozen_string_literal: true
-
-require 'pathname'
-
-# This script assumes the first argument is a directory of files containing diffs of changes from an MR. It exits with a
-# success code if all diffs add a line that quarantines a test. If any diffs are not specs, or they are specs that don't
-# quarantine a test, it exits with code 1 to indicate failure (i.e., there was _not_ only quarantined specs).
-
-abort("ERROR: Please specify the directory containing MR diffs.") if ARGV.empty?
-diffs_dir = Pathname.new(ARGV.shift).expand_path
-
-diffs_dir.glob('**/*').each do |path|
- next if path.directory?
-
- exit 1 unless path.to_s.end_with?('_spec.rb.diff')
- exit 1 unless path.read.match?(/^\+.*, quarantine:/)
-end
diff --git a/tooling/bin/qa/package_and_qa_check b/tooling/bin/qa/package_and_qa_check
new file mode 100755
index 00000000000..21deb0fcd2d
--- /dev/null
+++ b/tooling/bin/qa/package_and_qa_check
@@ -0,0 +1,45 @@
+#!/usr/bin/env ruby
+# frozen_string_literal: true
+
+require 'pathname'
+
+# This script checks if the package-and-qa job should trigger downstream pipelines to run the QA suite.
+#
+# It assumes the first argument is a directory of files containing diffs of changes from an MR
+# (e.g., created by tooling/bin/find_change_diffs). It exits with a success code if there are no diffs, or if the diffs
+# are suitable to run QA tests.
+#
+# The script will abort (exit code 1) if the argument is missing.
+#
+# The following condition will result in a failure code (2), indicating that package-and-qa should not run:
+#
+# - If the changes only include tests being put in quarantine
+
+abort("ERROR: Please specify the directory containing MR diffs.") if ARGV.empty?
+diffs_dir = Pathname.new(ARGV.shift).expand_path
+
+# Run package-and-qa if there are no diffs. E.g., in scheduled pipelines
+exit 0 if diffs_dir.glob('**/*').empty?
+
+files_count = 0
+specs_count = 0
+quarantine_specs_count = 0
+
+diffs_dir.glob('**/*').each do |path|
+ next if path.directory?
+
+ files_count += 1
+ next unless path.to_s.end_with?('_spec.rb.diff')
+
+ specs_count += 1
+ quarantine_specs_count += 1 if path.read.match?(/^\+.*, quarantine:/)
+end
+
+# Run package-and-qa if there are no specs. E.g., when the MR changes QA framework files.
+exit 0 if specs_count == 0
+
+# Skip package-and-qa if there are only specs being put in quarantine.
+exit 2 if quarantine_specs_count == specs_count && quarantine_specs_count == files_count
+
+# Run package-and-qa under any other circumstances. E.g., if there are specs being put in quarantine but there are also
+# other changes that might need to be tested.