diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-09-20 13:18:24 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-09-20 13:18:24 +0000 |
commit | 0653e08efd039a5905f3fa4f6e9cef9f5d2f799c (patch) | |
tree | 4dcc884cf6d81db44adae4aa99f8ec1233a41f55 /lib/tasks | |
parent | 744144d28e3e7fddc117924fef88de5d9674fe4c (diff) | |
download | gitlab-ce-0653e08efd039a5905f3fa4f6e9cef9f5d2f799c.tar.gz |
Add latest changes from gitlab-org/gitlab@14-3-stable-eev14.3.0-rc42
Diffstat (limited to 'lib/tasks')
-rw-r--r-- | lib/tasks/gitlab/db.rake | 8 | ||||
-rw-r--r-- | lib/tasks/gitlab/docs/compile_deprecations.rake | 29 | ||||
-rw-r--r-- | lib/tasks/gitlab/gitaly.rake | 5 | ||||
-rw-r--r-- | lib/tasks/gitlab/graphql.rake | 4 | ||||
-rw-r--r-- | lib/tasks/gitlab/product_intelligence.rake | 24 | ||||
-rw-r--r-- | lib/tasks/gitlab/sidekiq.rake | 5 | ||||
-rw-r--r-- | lib/tasks/gitlab/usage_data.rake | 28 | ||||
-rw-r--r-- | lib/tasks/karma.rake | 19 | ||||
-rw-r--r-- | lib/tasks/pngquant.rake | 55 | ||||
-rw-r--r-- | lib/tasks/rubocop.rake | 17 |
10 files changed, 87 insertions, 107 deletions
diff --git a/lib/tasks/gitlab/db.rake b/lib/tasks/gitlab/db.rake index 51f15f5a56a..a6738b01f18 100644 --- a/lib/tasks/gitlab/db.rake +++ b/lib/tasks/gitlab/db.rake @@ -118,7 +118,7 @@ namespace :gitlab do desc 'Create missing dynamic database partitions' task create_dynamic_partitions: :environment do - Gitlab::Database::Partitioning::PartitionManager.new.sync_partitions + Gitlab::Database::Partitioning.sync_partitions end # This is targeted towards deploys and upgrades of GitLab. @@ -151,6 +151,12 @@ namespace :gitlab do # initializers here as the application can continue to run while # a rake task reloads the database schema. Rake::Task['db:test:load'].enhance do + # Due to bug in `db:test:load` if many DBs are used + # the `ActiveRecord::Base.connection` might be switched to another one + # This is due to `if should_reconnect`: + # https://github.com/rails/rails/blob/a81aeb63a007ede2fe606c50539417dada9030c7/activerecord/lib/active_record/railties/databases.rake#L622 + ActiveRecord::Base.establish_connection :main + Rake::Task['gitlab:db:create_dynamic_partitions'].invoke end diff --git a/lib/tasks/gitlab/docs/compile_deprecations.rake b/lib/tasks/gitlab/docs/compile_deprecations.rake new file mode 100644 index 00000000000..0fd43775015 --- /dev/null +++ b/lib/tasks/gitlab/docs/compile_deprecations.rake @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +namespace :gitlab do + namespace :docs do + desc "Generate deprecation list from individual files" + task :compile_deprecations do + require_relative '../../../../tooling/deprecations/docs' + + File.write(Deprecations::Docs.path, Deprecations::Docs.render) + + puts "Deprecations compiled to #{Deprecations::Docs.path}" + end + + desc "Check that the deprecation doc is up to date" + task :check_deprecations do + require_relative '../../../../tooling/deprecations/docs' + + contents = Deprecations::Docs.render + doc = File.read(Deprecations::Docs.path) + + if doc == contents + puts "Deprecations doc is up to date." + else + format_output('Deprecations doc is outdated! Please update it by running `bundle exec rake gitlab:docs:compile_deprecations`.') + abort + end + end + end +end diff --git a/lib/tasks/gitlab/gitaly.rake b/lib/tasks/gitlab/gitaly.rake index 6675439e430..ef58c9339f1 100644 --- a/lib/tasks/gitlab/gitaly.rake +++ b/lib/tasks/gitlab/gitaly.rake @@ -15,8 +15,7 @@ namespace :gitlab do gdk_gitaly_dir = ENV.fetch('GDK_GITALY', Rails.root.join('../gitaly')) # Our test setup expects a git repo, so clone rather than copy - version = Gitlab::GitalyClient.expected_server_version - checkout_or_clone_version(version: version, repo: gdk_gitaly_dir, target_dir: args.dir, clone_opts: %w[--depth 1]) + clone_repo(gdk_gitaly_dir, args.dir, clone_opts: %w[--depth 1]) unless Dir.exist?(args.dir) # We assume the GDK gitaly already compiled binaries build_dir = File.join(gdk_gitaly_dir, '_build') @@ -31,7 +30,7 @@ namespace :gitlab do FileUtils.cp_r(ruby_bundle_file, args.dir) gitaly_binary = File.join(build_dir, 'bin', 'gitaly') - warn_gitaly_out_of_date!(gitaly_binary, version) + warn_gitaly_out_of_date!(gitaly_binary, Gitlab::GitalyClient.expected_server_version) rescue Errno::ENOENT => e puts "Could not copy files, did you run `gdk update`? Error: #{e.message}" diff --git a/lib/tasks/gitlab/graphql.rake b/lib/tasks/gitlab/graphql.rake index 52c5c680292..b9137aa0d4c 100644 --- a/lib/tasks/gitlab/graphql.rake +++ b/lib/tasks/gitlab/graphql.rake @@ -111,7 +111,7 @@ namespace :gitlab do desc 'GitLab | GraphQL | Generate GraphQL docs' task compile_docs: [:environment, :enable_feature_flags] do - renderer = Tooling::Graphql::Docs::Renderer.new(GitlabSchema, render_options) + renderer = Tooling::Graphql::Docs::Renderer.new(GitlabSchema, **render_options) renderer.write @@ -120,7 +120,7 @@ namespace :gitlab do desc 'GitLab | GraphQL | Check if GraphQL docs are up to date' task check_docs: [:environment, :enable_feature_flags] do - renderer = Tooling::Graphql::Docs::Renderer.new(GitlabSchema, render_options) + renderer = Tooling::Graphql::Docs::Renderer.new(GitlabSchema, **render_options) doc = File.read(Rails.root.join(OUTPUT_DIR, 'index.md')) diff --git a/lib/tasks/gitlab/product_intelligence.rake b/lib/tasks/gitlab/product_intelligence.rake deleted file mode 100644 index 329cd9c8c2a..00000000000 --- a/lib/tasks/gitlab/product_intelligence.rake +++ /dev/null @@ -1,24 +0,0 @@ -# frozen_string_literal: true - -namespace :gitlab do - namespace :product_intelligence do - # @example - # bundle exec rake gitlab:product_intelligence:activate_metrics MILESTONE=14.0 - - desc 'GitLab | Product Intelligence | Update milestone metrics status to data_available' - task activate_metrics: :environment do - milestone = ENV['MILESTONE'] - raise "Please supply the MILESTONE env var".color(:red) unless milestone.present? - - Gitlab::Usage::MetricDefinition.definitions.values.each do |metric| - next if metric.attributes[:milestone] != milestone || metric.attributes[:status] != 'implemented' - - metric.attributes[:status] = 'data_available' - path = metric.path - File.open(path, "w") { |file| file << metric.to_h.deep_stringify_keys.to_yaml } - end - - puts "Task completed successfully" - end - end -end diff --git a/lib/tasks/gitlab/sidekiq.rake b/lib/tasks/gitlab/sidekiq.rake index d3060d92e88..90ed91221ae 100644 --- a/lib/tasks/gitlab/sidekiq.rake +++ b/lib/tasks/gitlab/sidekiq.rake @@ -86,9 +86,8 @@ namespace :gitlab do # 3: high priority # 5: _super_ high priority, this should only be used for _very_ important queues # - # As per http://stackoverflow.com/a/21241357/290102 the formula for calculating - # the likelihood of a job being popped off a queue (given all queues have work - # to perform) is: + # The formula for calculating the likelihood of a job being popped off a queue + # (given all queues have work to perform) is: # # chance = (queue weight / total weight of all queues) * 100 BANNER diff --git a/lib/tasks/gitlab/usage_data.rake b/lib/tasks/gitlab/usage_data.rake index ddd3424acda..35ddc627389 100644 --- a/lib/tasks/gitlab/usage_data.rake +++ b/lib/tasks/gitlab/usage_data.rake @@ -28,5 +28,33 @@ namespace :gitlab do task generate_from_yaml: :environment do puts Gitlab::Json.pretty_generate(Gitlab::UsageDataMetrics.uncached_data) end + + desc 'GitLab | UsageDataMetrics | Generate known_events/ci_templates.yml based on template definitions' + task generate_ci_template_events: :environment do + banner = <<~BANNER + # This file is generated automatically by + # bin/rake gitlab:usage_data:generate_ci_template_events + # + # Do not edit it manually! + BANNER + + repository_includes = ci_template_includes_hash(:repository_source) + auto_devops_jobs_includes = ci_template_includes_hash(:auto_devops_source, 'Jobs') + auto_devops_security_includes = ci_template_includes_hash(:auto_devops_source, 'Security') + all_includes = [*repository_includes, *auto_devops_jobs_includes, *auto_devops_security_includes] + + File.write(Gitlab::UsageDataCounters::CiTemplateUniqueCounter::KNOWN_EVENTS_FILE_PATH, banner + YAML.dump(all_includes).gsub(/ *$/m, '')) + end + + def ci_template_includes_hash(source, template_directory = nil) + Gitlab::UsageDataCounters::CiTemplateUniqueCounter.ci_templates("lib/gitlab/ci/templates/#{template_directory}").map do |template| + { + 'name' => Gitlab::UsageDataCounters::CiTemplateUniqueCounter.ci_template_event_name("#{template_directory}/#{template}", source), + 'category' => 'ci_templates', + 'redis_slot' => Gitlab::UsageDataCounters::CiTemplateUniqueCounter::REDIS_SLOT, + 'aggregation' => 'weekly' + } + end + end end end diff --git a/lib/tasks/karma.rake b/lib/tasks/karma.rake deleted file mode 100644 index fa3f8805159..00000000000 --- a/lib/tasks/karma.rake +++ /dev/null @@ -1,19 +0,0 @@ -# frozen_string_literal: true - -unless Rails.env.production? - namespace :karma do - # alias exists for legacy reasons - desc 'GitLab | Karma | Generate fixtures for JavaScript tests' - task fixtures: ['frontend:fixtures'] - - desc 'GitLab | Karma | Run JavaScript tests' - task tests: ['yarn:check'] do - sh "yarn run karma" do |ok, res| - abort('rake karma:tests failed') unless ok - end - end - end - - desc 'GitLab | Karma | Shortcut for karma:fixtures and karma:tests' - task karma: ['karma:fixtures', 'karma:tests'] -end diff --git a/lib/tasks/pngquant.rake b/lib/tasks/pngquant.rake deleted file mode 100644 index 45c0288cadf..00000000000 --- a/lib/tasks/pngquant.rake +++ /dev/null @@ -1,55 +0,0 @@ -# frozen_string_literal: true - -return if Rails.env.production? - -require 'png_quantizator' -require 'parallel' -require_relative '../../tooling/lib/tooling/images' - -# The amount of variance (in bytes) allowed in -# file size when testing for compression size - -namespace :pngquant do - # Returns an array of all images eligible for compression - def doc_images - Dir.glob('doc/**/*.png', File::FNM_CASEFOLD) - end - - desc 'GitLab | Pngquant | Compress all documentation PNG images using pngquant' - task :compress do - files = doc_images - puts "Compressing #{files.size} PNG files in doc/**" - - Parallel.each(files) do |file| - was_uncompressed, savings = Tooling::Image.compress_image(file) - - if was_uncompressed - puts "#{file} was reduced by #{savings} bytes" - end - end - end - - desc 'GitLab | Pngquant | Checks that all documentation PNG images have been compressed with pngquant' - task :lint do - files = doc_images - puts "Checking #{files.size} PNG files in doc/**" - - uncompressed_files = Parallel.map(files) do |file| - is_uncompressed, _ = Tooling::Image.compress_image(file, true) - if is_uncompressed - puts "Uncompressed file detected: ".color(:red) + file - file - end - end.compact - - if uncompressed_files.empty? - puts "All documentation images are optimally compressed!".color(:green) - else - warn( - "The #{uncompressed_files.size} image(s) above have not been optimally compressed using pngquant.".color(:red), - 'Please run "bin/rake pngquant:compress" and commit the result.' - ) - abort - end - end -end diff --git a/lib/tasks/rubocop.rake b/lib/tasks/rubocop.rake index f5d16835347..a4147ae1bba 100644 --- a/lib/tasks/rubocop.rake +++ b/lib/tasks/rubocop.rake @@ -4,4 +4,21 @@ unless Rails.env.production? require 'rubocop/rake_task' RuboCop::RakeTask.new + + namespace :rubocop do + namespace :todo do + desc 'Generate RuboCop todos' + task :generate do + require 'rubocop' + + options = %w[ + --auto-gen-config + --auto-gen-only-exclude + --exclude-limit=100000 + ] + + RuboCop::CLI.new.run(options) + end + end + end end |