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>2023-02-20 16:49:51 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-02-20 16:49:51 +0300
commit71786ddc8e28fbd3cb3fcc4b3ff15e5962a1c82e (patch)
tree6a2d93ef3fb2d353bb7739e4b57e6541f51cdd71 /tooling/lib
parenta7253423e3403b8c08f8a161e5937e1488f5f407 (diff)
Add latest changes from gitlab-org/gitlab@15-9-stable-eev15.9.0-rc42
Diffstat (limited to 'tooling/lib')
-rw-r--r--tooling/lib/tooling/find_codeowners.rb2
-rw-r--r--tooling/lib/tooling/helm3_client.rb20
-rw-r--r--tooling/lib/tooling/kubernetes_client.rb11
-rw-r--r--tooling/lib/tooling/mappings/base.rb30
-rw-r--r--tooling/lib/tooling/mappings/js_to_system_specs_mappings.rb61
-rw-r--r--tooling/lib/tooling/mappings/view_to_js_mappings.rb74
-rw-r--r--tooling/lib/tooling/parallel_rspec_runner.rb2
-rw-r--r--tooling/lib/tooling/test_map_packer.rb4
-rw-r--r--tooling/lib/tooling/view_to_js_mappings.rb77
9 files changed, 186 insertions, 95 deletions
diff --git a/tooling/lib/tooling/find_codeowners.rb b/tooling/lib/tooling/find_codeowners.rb
index 6a90f86eecc..cc37d4db1ec 100644
--- a/tooling/lib/tooling/find_codeowners.rb
+++ b/tooling/lib/tooling/find_codeowners.rb
@@ -89,7 +89,7 @@ module Tooling
end
def consolidate_paths(matched_files)
- matched_files.group_by(&File.method(:dirname)).flat_map do |dir, files|
+ matched_files.group_by { |file| File.dirname(file) }.flat_map do |dir, files|
# First line is the dir itself
if find_dir_maxdepth_1(dir).lines.drop(1).sort == files.sort
"#{dir}\n"
diff --git a/tooling/lib/tooling/helm3_client.rb b/tooling/lib/tooling/helm3_client.rb
index d4e7faa802e..9059387351a 100644
--- a/tooling/lib/tooling/helm3_client.rb
+++ b/tooling/lib/tooling/helm3_client.rb
@@ -8,34 +8,32 @@ module Tooling
class Helm3Client
CommandFailedError = Class.new(StandardError)
- attr_reader :namespace
-
RELEASE_JSON_ATTRIBUTES = %w[name revision updated status chart app_version namespace].freeze
PAGINATION_SIZE = 256 # Default helm list pagination size
- Release = Struct.new(:name, :revision, :last_update, :status, :chart, :app_version, :namespace) do
+ Release = Struct.new(:name, :namespace, :revision, :updated, :status, :chart, :app_version, keyword_init: true) do
def revision
@revision ||= self[:revision].to_i
end
def last_update
- @last_update ||= self[:last_update] ? Time.parse(self[:last_update]) : nil
+ @last_update ||= self[:updated] ? Time.parse(self[:updated]) : nil
end
end
# A single page of data and the corresponding page number.
Page = Struct.new(:releases, :number)
- def initialize(namespace:)
- @namespace = namespace
- end
-
def releases(args: [])
each_release(args)
end
- def delete(release_name:)
- run_command(['uninstall', release_name])
+ def delete(release_name:, namespace: nil)
+ release_name = Array(release_name)
+
+ release_name.each do |release|
+ run_command(['uninstall', '--namespace', (namespace || release), release])
+ end
end
private
@@ -66,7 +64,7 @@ module Tooling
releases = JSON.parse(response) # rubocop:disable Gitlab/Json
releases.map do |release|
- Release.new(*release.values_at(*RELEASE_JSON_ATTRIBUTES))
+ Release.new(release.slice(*RELEASE_JSON_ATTRIBUTES))
end
rescue ::JSON::ParserError => ex
puts "Ignoring this JSON parsing error: #{ex}\n\nResponse was:\n#{response}" # rubocop:disable Rails/Output
diff --git a/tooling/lib/tooling/kubernetes_client.rb b/tooling/lib/tooling/kubernetes_client.rb
index 1d7b924e2c3..ab914db5777 100644
--- a/tooling/lib/tooling/kubernetes_client.rb
+++ b/tooling/lib/tooling/kubernetes_client.rb
@@ -6,8 +6,9 @@ require_relative '../../../lib/gitlab/popen' unless defined?(Gitlab::Popen)
module Tooling
class KubernetesClient
- RESOURCE_LIST = 'ingress,svc,pdb,hpa,deploy,statefulset,job,pod,secret,configmap,pvc,secret,clusterrole,clusterrolebinding,role,rolebinding,sa,crd'
- CommandFailedError = Class.new(StandardError)
+ RESOURCE_LIST = 'ingress,svc,pdb,hpa,deploy,statefulset,job,pod,secret,configmap,pvc,secret,clusterrole,clusterrolebinding,role,rolebinding,sa,crd'
+ K8S_ALLOWED_NAMESPACES_REGEX = /^review-(?!apps).+/.freeze
+ CommandFailedError = Class.new(StandardError)
attr_reader :namespace
@@ -129,14 +130,16 @@ module Tooling
command = [
'get',
'namespace',
- "-l tls=review-apps-tls", # Get only namespaces used for review-apps
"--sort-by='{.metadata.creationTimestamp}'",
'-o json'
]
response = run_command(command)
- resources_created_before_date(response, created_before)
+ stale_namespaces = resources_created_before_date(response, created_before)
+
+ # `kubectl` doesn't allow us to filter namespaces with a regexp. We therefore do the filtering in Ruby.
+ stale_namespaces.select { |ns| K8S_ALLOWED_NAMESPACES_REGEX.match?(ns) }
end
def resources_created_before_date(response, date)
diff --git a/tooling/lib/tooling/mappings/base.rb b/tooling/lib/tooling/mappings/base.rb
new file mode 100644
index 00000000000..93d3a967114
--- /dev/null
+++ b/tooling/lib/tooling/mappings/base.rb
@@ -0,0 +1,30 @@
+# frozen_string_literal: true
+
+require_relative '../../../../lib/gitlab_edition'
+
+# Returns system specs files that are related to the JS files that were changed in the MR.
+module Tooling
+ module Mappings
+ class Base
+ # Input: A list of space-separated files
+ # Output: A list of space-separated specs files (JS, Ruby, ...)
+ def execute(changed_files)
+ raise "Not Implemented"
+ end
+
+ # Input: A list of space-separated files
+ # Output: array/hash of files
+ def filter_files(changed_files)
+ raise "Not Implemented"
+ end
+
+ # Input: A folder
+ # Output: An array of folders, each prefixed with a GitLab edition
+ def folders_for_available_editions(base_folder)
+ foss_prefix = base_folder
+ extension_prefixes = ::GitlabEdition.extensions.map { |prefix| "#{prefix}/#{foss_prefix}" }
+ [foss_prefix, *extension_prefixes]
+ end
+ end
+ end
+end
diff --git a/tooling/lib/tooling/mappings/js_to_system_specs_mappings.rb b/tooling/lib/tooling/mappings/js_to_system_specs_mappings.rb
new file mode 100644
index 00000000000..365e466011b
--- /dev/null
+++ b/tooling/lib/tooling/mappings/js_to_system_specs_mappings.rb
@@ -0,0 +1,61 @@
+# frozen_string_literal: true
+
+require 'active_support/inflector'
+
+require_relative 'base'
+require_relative '../../../../lib/gitlab_edition'
+
+# Returns system specs files that are related to the JS files that were changed in the MR.
+module Tooling
+ module Mappings
+ class JsToSystemSpecsMappings < Base
+ def initialize(js_base_folder: 'app/assets/javascripts', system_specs_base_folder: 'spec/features')
+ @js_base_folder = js_base_folder
+ @js_base_folders = folders_for_available_editions(js_base_folder)
+ @system_specs_base_folder = system_specs_base_folder
+
+ # Cannot be extracted to a constant, as it depends on a variable
+ @first_js_folder_extract_regexp = %r{
+ (?:.*/)? # Skips the GitLab edition (e.g. ee/, jh/)
+ #{@js_base_folder}/ # Most likely app/assets/javascripts/
+ ([\w-]*) # Captures the first folder
+ }x
+ end
+
+ def execute(changed_files)
+ filter_files(changed_files).flat_map do |edition, js_files|
+ js_keywords_regexp = Regexp.union(construct_js_keywords(js_files))
+
+ system_specs_for_edition(edition).select do |system_spec_file|
+ system_spec_file if js_keywords_regexp.match?(system_spec_file)
+ end
+ end
+ end
+
+ # Keep the files that are in the @js_base_folders folders
+ #
+ # Returns a hash, where the key is the GitLab edition, and the values the JS specs
+ def filter_files(changed_files)
+ selected_files = changed_files.select do |filename|
+ filename.start_with?(*@js_base_folders) && File.exist?(filename)
+ end
+
+ selected_files.group_by { |filename| filename[/^#{Regexp.union(::GitlabEdition.extensions)}/] }
+ end
+
+ # Extract keywords in the JS filenames to be used for searching matching system specs
+ def construct_js_keywords(js_files)
+ js_files.map do |js_file|
+ filename = js_file.scan(@first_js_folder_extract_regexp).flatten.first
+ filename.singularize
+ end.uniq
+ end
+
+ def system_specs_for_edition(edition)
+ all_files_in_folders_glob = File.join(@system_specs_base_folder, '**', '*')
+ all_files_in_folders_glob = File.join(edition, all_files_in_folders_glob) if edition
+ Dir[all_files_in_folders_glob].select { |f| File.file?(f) }
+ end
+ end
+ end
+end
diff --git a/tooling/lib/tooling/mappings/view_to_js_mappings.rb b/tooling/lib/tooling/mappings/view_to_js_mappings.rb
new file mode 100644
index 00000000000..db80eb9bfe8
--- /dev/null
+++ b/tooling/lib/tooling/mappings/view_to_js_mappings.rb
@@ -0,0 +1,74 @@
+# frozen_string_literal: true
+
+require_relative 'base'
+require_relative '../../../../lib/gitlab_edition'
+
+# Returns JS files that are related to the Rails views files that were changed in the MR.
+module Tooling
+ module Mappings
+ class ViewToJsMappings < Base
+ # The HTML attribute value pattern we're looking for to match an HTML file to a JS file.
+ HTML_ATTRIBUTE_VALUE_REGEXP = /js-[-\w]+/.freeze
+
+ # Search for Rails partials included in an HTML file
+ RAILS_PARTIAL_INVOCATION_REGEXP = %r{(?:render|render_if_exist)(?: |\()(?:partial: ?)?['"]([\w/-]+)['"]}.freeze
+
+ def initialize(view_base_folder: 'app/views', js_base_folder: 'app/assets/javascripts')
+ @view_base_folders = folders_for_available_editions(view_base_folder)
+ @js_base_folders = folders_for_available_editions(js_base_folder)
+ end
+
+ def execute(changed_files)
+ changed_view_files = filter_files(changed_files)
+
+ partials = changed_view_files.flat_map do |file|
+ find_partials(file)
+ end
+
+ files_to_scan = changed_view_files + partials
+ js_tags = files_to_scan.flat_map do |file|
+ find_pattern_in_file(file, HTML_ATTRIBUTE_VALUE_REGEXP)
+ end
+ js_tags_regexp = Regexp.union(js_tags)
+
+ @js_base_folders.flat_map do |js_base_folder|
+ Dir["#{js_base_folder}/**/*.{js,vue}"].select do |js_file|
+ file_content = File.read(js_file)
+ js_tags_regexp.match?(file_content)
+ end
+ end
+ end
+
+ # Keep the files that are in the @view_base_folders folder
+ def filter_files(changed_files)
+ changed_files.select do |filename|
+ filename.start_with?(*@view_base_folders) &&
+ File.exist?(filename)
+ end
+ end
+
+ # Note: We only search for partials with depth 1. We don't do recursive search, as
+ # it is probably not necessary for a first iteration.
+ def find_partials(file)
+ partial_paths = find_pattern_in_file(file, RAILS_PARTIAL_INVOCATION_REGEXP)
+ partial_paths.flat_map do |partial_path|
+ view_file_folder = File.dirname(file)
+ partial_relative_folder = File.dirname(partial_path)
+
+ dirname =
+ if partial_relative_folder == '.' # The partial is in the same folder as the HTML file
+ view_file_folder
+ else
+ File.join(view_file_folder, partial_relative_folder)
+ end
+
+ Dir["#{dirname}/_#{File.basename(partial_path)}.*"]
+ end
+ end
+
+ def find_pattern_in_file(file, pattern)
+ File.read(file).scan(pattern).flatten.uniq
+ end
+ end
+ end
+end
diff --git a/tooling/lib/tooling/parallel_rspec_runner.rb b/tooling/lib/tooling/parallel_rspec_runner.rb
index b482160d3c0..b1ddc91e831 100644
--- a/tooling/lib/tooling/parallel_rspec_runner.rb
+++ b/tooling/lib/tooling/parallel_rspec_runner.rb
@@ -43,6 +43,8 @@ module Tooling
return
end
+ Knapsack.logger.info "Running command: #{rspec_command.join(' ')}"
+
exec(*rspec_command)
end
diff --git a/tooling/lib/tooling/test_map_packer.rb b/tooling/lib/tooling/test_map_packer.rb
index 151ce88111f..15191e35c54 100644
--- a/tooling/lib/tooling/test_map_packer.rb
+++ b/tooling/lib/tooling/test_map_packer.rb
@@ -6,11 +6,11 @@ module Tooling
MARKER = 1
def pack(map)
- map.transform_values(&method(:create_tree_from_tests))
+ map.transform_values { |tests| create_tree_from_tests(tests) }
end
def unpack(compact_map)
- compact_map.transform_values(&method(:retrieve_tests_from_tree))
+ compact_map.transform_values { |tree| retrieve_tests_from_tree(tree) }
end
private
diff --git a/tooling/lib/tooling/view_to_js_mappings.rb b/tooling/lib/tooling/view_to_js_mappings.rb
deleted file mode 100644
index 76704a04469..00000000000
--- a/tooling/lib/tooling/view_to_js_mappings.rb
+++ /dev/null
@@ -1,77 +0,0 @@
-# frozen_string_literal: true
-
-require_relative '../../../lib/gitlab_edition'
-
-# Returns JS files that are related to the Rails views files that were changed in the MR.
-module Tooling
- class ViewToJsMappings
- # The HTML attribute value pattern we're looking for to match an HTML file to a JS file.
- HTML_ATTRIBUTE_VALUE_REGEXP = /js-[-\w]+/.freeze
-
- # Search for Rails partials included in an HTML file
- RAILS_PARTIAL_INVOCATION_REGEXP = %r{(?:render|render_if_exist)(?: |\()(?:partial: ?)?['"]([\w/-]+)['"]}.freeze
-
- def initialize(view_base_folder: 'app/views', js_base_folder: 'app/assets/javascripts')
- @view_base_folders = folders_for_available_editions(view_base_folder)
- @js_base_folders = folders_for_available_editions(js_base_folder)
- end
-
- def execute(changed_files)
- changed_view_files = view_files(changed_files)
-
- partials = changed_view_files.flat_map do |file|
- find_partials(file)
- end
-
- files_to_scan = changed_view_files + partials
- js_tags = files_to_scan.flat_map do |file|
- find_pattern_in_file(file, HTML_ATTRIBUTE_VALUE_REGEXP)
- end
- js_tags_regexp = Regexp.union(js_tags)
-
- @js_base_folders.flat_map do |js_base_folder|
- Dir["#{js_base_folder}/**/*.{js,vue}"].select do |js_file|
- file_content = File.read(js_file)
- js_tags_regexp.match?(file_content)
- end
- end
- end
-
- # Keep the files that are in the @view_base_folders folder
- def view_files(changed_files)
- changed_files.select do |filename|
- filename.start_with?(*@view_base_folders) &&
- File.exist?(filename)
- end
- end
-
- def folders_for_available_editions(base_folder)
- foss_prefix = base_folder
- extension_prefixes = ::GitlabEdition.extensions.map { |prefix| "#{prefix}/#{foss_prefix}" }
- [foss_prefix, *extension_prefixes]
- end
-
- # Note: We only search for partials with depth 1. We don't do recursive search, as
- # it is probably not necessary for a first iteration.
- def find_partials(file)
- partial_paths = find_pattern_in_file(file, RAILS_PARTIAL_INVOCATION_REGEXP)
- partial_paths.flat_map do |partial_path|
- view_file_folder = File.dirname(file)
- partial_relative_folder = File.dirname(partial_path)
-
- dirname =
- if partial_relative_folder == '.' # The partial is in the same folder as the HTML file
- view_file_folder
- else
- File.join(view_file_folder, partial_relative_folder)
- end
-
- Dir["#{dirname}/_#{File.basename(partial_path)}.*"]
- end
- end
-
- def find_pattern_in_file(file, pattern)
- File.read(file).scan(pattern).flatten.uniq
- end
- end
-end