diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-18 16:16:36 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-18 16:16:36 +0300 |
commit | 311b0269b4eb9839fa63f80c8d7a58f32b8138a0 (patch) | |
tree | 07e7870bca8aed6d61fdcc810731c50d2c40af47 /tooling/bin | |
parent | 27909cef6c4170ed9205afa7426b8d3de47cbb0c (diff) |
Add latest changes from gitlab-org/gitlab@14-5-stable-eev14.5.0-rc42
Diffstat (limited to 'tooling/bin')
-rwxr-xr-x | tooling/bin/find_change_diffs | 38 | ||||
-rwxr-xr-x | tooling/bin/find_changes | 2 | ||||
-rwxr-xr-x | tooling/bin/qa/package_and_qa_check | 45 |
3 files changed, 84 insertions, 1 deletions
diff --git a/tooling/bin/find_change_diffs b/tooling/bin/find_change_diffs new file mode 100755 index 00000000000..7857945ea74 --- /dev/null +++ b/tooling/bin/find_change_diffs @@ -0,0 +1,38 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +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['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 + +Gitlab.configure do |config| + config.endpoint = gitlab_endpoint + config.private_token = gitlab_token +end + +Gitlab.merge_request_changes(mr_project_path, mr_iid).changes.each do |change| + next if change['diff'].empty? + + output_diffs_dir.join(File.dirname(change['new_path'])).mkpath + output_diffs_dir.join("#{change['new_path']}.diff").write(change['diff']) +end diff --git a/tooling/bin/find_changes b/tooling/bin/find_changes index 466510ccb19..20df085879a 100755 --- a/tooling/bin/find_changes +++ b/tooling/bin/find_changes @@ -3,7 +3,7 @@ require 'gitlab' -gitlab_token = ENV.fetch('DANGER_GITLAB_API_TOKEN', '') +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') 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. |