2021-11-08 07:12:07 -05:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'pathname'
|
|
|
|
|
2022-08-02 11:09:10 -04:00
|
|
|
# This script checks if the code changes justify running the QA suite.
|
2021-11-08 07:12:07 -05:00
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
2022-08-02 11:09:10 -04:00
|
|
|
# The following condition will result in a failure code (2), indicating that QA tests should not run:
|
2021-11-08 07:12:07 -05:00
|
|
|
#
|
|
|
|
# - 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
|
|
|
|
|
2022-08-02 11:09:10 -04:00
|
|
|
# Run QA tests if there are no diffs. E.g., in scheduled pipelines
|
2021-11-08 07:12:07 -05:00
|
|
|
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
|
|
|
|
|
2022-08-02 11:09:10 -04:00
|
|
|
# Run QA tests if there are no specs. E.g., when the MR changes QA framework files.
|
2021-11-08 07:12:07 -05:00
|
|
|
exit 0 if specs_count == 0
|
|
|
|
|
2022-08-02 11:09:10 -04:00
|
|
|
# Skip QA tests if there are only specs being put in quarantine.
|
2021-11-08 07:12:07 -05:00
|
|
|
exit 2 if quarantine_specs_count == specs_count && quarantine_specs_count == files_count
|
|
|
|
|
2022-08-02 11:09:10 -04:00
|
|
|
# Run QA tests under any other circumstances. E.g., if there are specs being put in quarantine but there are also
|
2021-11-08 07:12:07 -05:00
|
|
|
# other changes that might need to be tested.
|