diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-12-20 13:37:47 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-12-20 13:37:47 +0000 |
commit | aee0a117a889461ce8ced6fcf73207fe017f1d99 (patch) | |
tree | 891d9ef189227a8445d83f35c1b0fc99573f4380 /tooling/bin | |
parent | 8d46af3258650d305f53b819eabf7ab18d22f59e (diff) | |
download | gitlab-ce-aee0a117a889461ce8ced6fcf73207fe017f1d99.tar.gz |
Add latest changes from gitlab-org/gitlab@14-6-stable-eev14.6.0-rc42
Diffstat (limited to 'tooling/bin')
-rwxr-xr-x | tooling/bin/find_changes | 79 | ||||
-rwxr-xr-x | tooling/bin/qa/check_if_qa_only_spec_changes | 22 |
2 files changed, 90 insertions, 11 deletions
diff --git a/tooling/bin/find_changes b/tooling/bin/find_changes index 20df085879a..c6b8bafbd85 100755 --- a/tooling/bin/find_changes +++ b/tooling/bin/find_changes @@ -3,19 +3,76 @@ require 'gitlab' -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') +class FindChanges # rubocop:disable Gitlab/NamespacedClass + def initialize(output_file:, matched_tests_file: nil, frontend_fixtures_mapping_path: nil) + @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') + @output_file = output_file + @matched_tests_file = matched_tests_file + @frontend_fixtures_mapping_path = frontend_fixtures_mapping_path + end -output_file = ARGV.shift + def execute + add_frontend_fixture_files! + + File.write(output_file, file_changes.join(' ')) + end + + private + + def add_frontend_fixture_files? + matched_tests_file && frontend_fixtures_mapping_path + end + + def add_frontend_fixture_files! + return unless add_frontend_fixture_files? + + # If we have a `test file -> JSON frontend fixture` mapping file, we add the files JSON frontend fixtures + # files to the list of changed files so that Jest can automatically run the dependent tests thanks to --findRelatedTests + test_files.each do |test_file| + file_changes.concat(frontend_fixtures_mapping[test_file]) if frontend_fixtures_mapping.key?(test_file) + end + end + + def file_changes + @file_changes ||= + if File.exist?(output_file) + File.read(output_file).split(' ') + else + Gitlab.configure do |config| + config.endpoint = gitlab_endpoint + config.private_token = gitlab_token + end + + mr_changes = Gitlab.merge_request_changes(mr_project_path, mr_iid) -Gitlab.configure do |config| - config.endpoint = gitlab_endpoint - config.private_token = gitlab_token + mr_changes.changes.map { |change| change['new_path'] } + end + end + + def test_files + return [] if !matched_tests_file || !File.exist?(matched_tests_file) + + File.read(matched_tests_file).split(' ') + end + + def frontend_fixtures_mapping + return {} if !frontend_fixtures_mapping_path || !File.exist?(frontend_fixtures_mapping_path) + + JSON.parse(File.read(frontend_fixtures_mapping_path)) # rubocop:disable Gitlab/Json + end + + attr_reader :gitlab_token, :gitlab_endpoint, :mr_project_path, :mr_iid, :output_file, :matched_tests_file, :frontend_fixtures_mapping_path end -mr_changes = Gitlab.merge_request_changes(mr_project_path, mr_iid) -file_changes = mr_changes.changes.map { |change| change['new_path'] } +output_file = ARGV.shift +raise ArgumentError, "An path to an output file must be given as first argument of #{__FILE__}." if output_file.nil? + +matched_tests_file = ARGV.shift +frontend_fixtures_mapping_path = ARGV.shift -File.write(output_file, file_changes.join(' ')) +FindChanges + .new(output_file: output_file, matched_tests_file: matched_tests_file, frontend_fixtures_mapping_path: frontend_fixtures_mapping_path) + .execute diff --git a/tooling/bin/qa/check_if_qa_only_spec_changes b/tooling/bin/qa/check_if_qa_only_spec_changes new file mode 100755 index 00000000000..5b9166b41fe --- /dev/null +++ b/tooling/bin/qa/check_if_qa_only_spec_changes @@ -0,0 +1,22 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# This script assumes the first argument is a path to a file containing a list of changed files and the second argument +# is the path of a file where a list of end-to-end spec files with the leading 'qa/' trimmed will be written to if +# all the files are end-to-end test spec files. + +abort("ERROR: Please specify the file containing the list of changed files and a file where the qa only spec files will be written") if ARGV.size != 2 + +changed_files_path = ARGV.shift +output_file = ARGV.shift + +return unless File.exist?(changed_files_path) + +changed_files = File.read(changed_files_path).split(' ') + +all_files_are_qa_specs = changed_files.all? { |file_path| file_path =~ %r{^qa\/qa\/specs\/features\/} } + +if all_files_are_qa_specs + qa_spec_paths_trimmed = changed_files.map { |path| path.sub('qa/', '') } + File.write(output_file, qa_spec_paths_trimmed.join(' ')) +end |