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
path: root/lib/tasks
diff options
context:
space:
mode:
Diffstat (limited to 'lib/tasks')
-rw-r--r--lib/tasks/brakeman.rake13
-rw-r--r--lib/tasks/cache.rake2
-rw-r--r--lib/tasks/db_obsolete_ignored_columns.rake2
-rw-r--r--lib/tasks/downtime_check.rake14
-rw-r--r--lib/tasks/gitlab/db.rake19
-rw-r--r--lib/tasks/gitlab/docs/redirect.rake57
-rw-r--r--lib/tasks/gitlab/gitaly.rake31
-rw-r--r--lib/tasks/gitlab/graphql.rake4
-rw-r--r--lib/tasks/gitlab/pages.rake40
-rw-r--r--lib/tasks/gitlab/test.rake17
-rw-r--r--lib/tasks/spec.rake20
-rw-r--r--lib/tasks/test.rake13
12 files changed, 146 insertions, 86 deletions
diff --git a/lib/tasks/brakeman.rake b/lib/tasks/brakeman.rake
deleted file mode 100644
index 44d2071751f..00000000000
--- a/lib/tasks/brakeman.rake
+++ /dev/null
@@ -1,13 +0,0 @@
-# frozen_string_literal: true
-
-desc 'Security check via brakeman'
-task :brakeman do
- # We get 0 warnings at level 'w3' but we would like to reach 'w2'. Merge
- # requests are welcome!
- if system(*%w(brakeman --no-progress --skip-files lib/backup/repository.rb -w3 -z))
- puts 'Security check succeed'
- else
- puts 'Security check failed'
- exit 1
- end
-end
diff --git a/lib/tasks/cache.rake b/lib/tasks/cache.rake
index 4d698e56444..13365b9ec07 100644
--- a/lib/tasks/cache.rake
+++ b/lib/tasks/cache.rake
@@ -3,7 +3,7 @@
namespace :cache do
namespace :clear do
REDIS_CLEAR_BATCH_SIZE = 1000 # There seems to be no speedup when pushing beyond 1,000
- REDIS_SCAN_START_STOP = '0'.freeze # Magic value, see http://redis.io/commands/scan
+ REDIS_SCAN_START_STOP = '0' # Magic value, see http://redis.io/commands/scan
desc "GitLab | Cache | Clear redis cache"
task redis: :environment do
diff --git a/lib/tasks/db_obsolete_ignored_columns.rake b/lib/tasks/db_obsolete_ignored_columns.rake
index cf35a355ce9..a689a9bf2d8 100644
--- a/lib/tasks/db_obsolete_ignored_columns.rake
+++ b/lib/tasks/db_obsolete_ignored_columns.rake
@@ -20,7 +20,7 @@ task 'db:obsolete_ignored_columns' => :environment do
WARNING: Removing columns is tricky because running GitLab processes may still be using the columns.
- See also https://docs.gitlab.com/ee/development/what_requires_downtime.html#dropping-columns
+ See also https://docs.gitlab.com/ee/development/avoiding_downtime_in_migrations.html#dropping-columns
TEXT
end
end
diff --git a/lib/tasks/downtime_check.rake b/lib/tasks/downtime_check.rake
deleted file mode 100644
index 3428e3f8f53..00000000000
--- a/lib/tasks/downtime_check.rake
+++ /dev/null
@@ -1,14 +0,0 @@
-# frozen_string_literal: true
-
-desc 'Checks if migrations in a branch require downtime'
-task downtime_check: :environment do
- repo = if defined?(Gitlab::License)
- 'gitlab'
- else
- 'gitlab-foss'
- end
-
- `git fetch https://gitlab.com/gitlab-org/#{repo}.git --depth 1`
-
- Rake::Task['gitlab:db:downtime_check'].invoke('FETCH_HEAD')
-end
diff --git a/lib/tasks/gitlab/db.rake b/lib/tasks/gitlab/db.rake
index 541a4fc62af..3baf4e7b7c6 100644
--- a/lib/tasks/gitlab/db.rake
+++ b/lib/tasks/gitlab/db.rake
@@ -80,22 +80,6 @@ namespace :gitlab do
end
end
- desc 'GitLab | DB | Checks if migrations require downtime or not'
- task :downtime_check, [:ref] => :environment do |_, args|
- abort 'You must specify a Git reference to compare with' unless args[:ref]
-
- require 'shellwords'
-
- ref = Shellwords.escape(args[:ref])
-
- migrations = `git diff #{ref}.. --diff-filter=A --name-only -- db/migrate`.lines
- .map { |file| Rails.root.join(file.strip).to_s }
- .select { |file| File.file?(file) }
- .select { |file| /\A[0-9]+.*\.rb\z/ =~ File.basename(file) }
-
- Gitlab::DowntimeCheck.new.check_and_print(migrations)
- end
-
desc 'GitLab | DB | Sets up EE specific database functionality'
if Gitlab.ee?
@@ -237,7 +221,8 @@ namespace :gitlab do
result_file = args[:result_file] || raise("Please specify result_file argument")
raise "File exists already, won't overwrite: #{result_file}" if File.exist?(result_file)
- verbose_was, ActiveRecord::Migration.verbose = ActiveRecord::Migration.verbose, true
+ verbose_was = ActiveRecord::Migration.verbose
+ ActiveRecord::Migration.verbose = true
ctx = ActiveRecord::Base.connection.migration_context
existing_versions = ctx.get_all_versions.to_set
diff --git a/lib/tasks/gitlab/docs/redirect.rake b/lib/tasks/gitlab/docs/redirect.rake
new file mode 100644
index 00000000000..0c8e0755348
--- /dev/null
+++ b/lib/tasks/gitlab/docs/redirect.rake
@@ -0,0 +1,57 @@
+# frozen_string_literal: true
+require 'date'
+require 'pathname'
+
+# https://docs.gitlab.com/ee/development/documentation/#move-or-rename-a-page
+namespace :gitlab do
+ namespace :docs do
+ desc 'GitLab | Docs | Create a doc redirect'
+ task :redirect, [:old_path, :new_path] do |_, args|
+ if args.old_path
+ old_path = args.old_path
+ else
+ puts '=> Enter the path of the OLD file:'
+ old_path = STDIN.gets.chomp
+ end
+
+ if args.new_path
+ new_path = args.new_path
+ else
+ puts '=> Enter the path of the NEW file:'
+ new_path = STDIN.gets.chomp
+ end
+
+ #
+ # If the new path is a relative URL, find the relative path between
+ # the old and new paths.
+ # The returned path is one level deeper, so remove the leading '../'.
+ #
+ unless new_path.start_with?('http')
+ old_pathname = Pathname.new(old_path)
+ new_pathname = Pathname.new(new_path)
+ relative_path = new_pathname.relative_path_from(old_pathname).to_s
+ (_, *last) = relative_path.split('/')
+ new_path = last.join('/')
+ end
+
+ #
+ # - If this is an external URL, move the date 1 year later.
+ # - If this is a relative URL, move the date 3 months later.
+ #
+ date = Time.now.utc.strftime('%Y-%m-%d')
+ date = new_path.start_with?('http') ? Date.parse(date) >> 12 : Date.parse(date) >> 3
+
+ puts "=> Creating new redirect from #{old_path} to #{new_path}"
+ File.open(old_path, 'w') do |post|
+ post.puts '---'
+ post.puts "redirect_to: '#{new_path}'"
+ post.puts '---'
+ post.puts
+ post.puts "This file was moved to [another location](#{new_path})."
+ post.puts
+ post.puts "<!-- This redirect file can be deleted after <#{date}>. -->"
+ post.puts "<!-- Before deletion, see: https://docs.gitlab.com/ee/development/documentation/#move-or-rename-a-page -->"
+ end
+ end
+ end
+end
diff --git a/lib/tasks/gitlab/gitaly.rake b/lib/tasks/gitlab/gitaly.rake
index 9e474b00ba7..df75b3cf716 100644
--- a/lib/tasks/gitlab/gitaly.rake
+++ b/lib/tasks/gitlab/gitaly.rake
@@ -17,24 +17,29 @@ Usage: rake "gitlab:gitaly:install[/installation/dir,/storage/path]")
checkout_or_clone_version(version: version, repo: args.repo, target_dir: args.dir, clone_opts: %w[--depth 1])
- command = []
- _, status = Gitlab::Popen.popen(%w[which gmake])
- command << (status == 0 ? 'gmake' : 'make')
-
- if Rails.env.test?
- command.push(
- 'BUNDLE_FLAGS=--no-deployment',
- "GEM_HOME=#{Bundler.bundle_path}")
- end
-
storage_paths = { 'default' => args.storage_path }
Gitlab::SetupHelper::Gitaly.create_configuration(args.dir, storage_paths)
+
+ # In CI we run scripts/gitaly-test-build
+ next if ENV['CI'].present?
+
Dir.chdir(args.dir) do
- # In CI we run scripts/gitaly-test-build instead of this command
- unless ENV['CI'].present?
- Bundler.with_original_env { Gitlab::Popen.popen(command, nil, { "RUBYOPT" => nil, "BUNDLE_GEMFILE" => nil }) }
+ Bundler.with_original_env do
+ env = { "RUBYOPT" => nil, "BUNDLE_GEMFILE" => nil }
+
+ if Rails.env.test?
+ env["GEM_HOME"] = Bundler.bundle_path.to_s
+ env["BUNDLE_DEPLOYMENT"] = 'false'
+ end
+
+ Gitlab::Popen.popen([make_cmd], nil, env)
end
end
end
+
+ def make_cmd
+ _, status = Gitlab::Popen.popen(%w[which gmake])
+ status == 0 ? 'gmake' : 'make'
+ end
end
end
diff --git a/lib/tasks/gitlab/graphql.rake b/lib/tasks/gitlab/graphql.rake
index 77377a7e0fd..27bba6aa307 100644
--- a/lib/tasks/gitlab/graphql.rake
+++ b/lib/tasks/gitlab/graphql.rake
@@ -110,7 +110,7 @@ namespace :gitlab do
desc 'GitLab | GraphQL | Generate GraphQL docs'
task compile_docs: [:environment, :enable_feature_flags] do
- renderer = Gitlab::Graphql::Docs::Renderer.new(GitlabSchema.graphql_definition, render_options)
+ renderer = Gitlab::Graphql::Docs::Renderer.new(GitlabSchema, render_options)
renderer.write
@@ -119,7 +119,7 @@ namespace :gitlab do
desc 'GitLab | GraphQL | Check if GraphQL docs are up to date'
task check_docs: [:environment, :enable_feature_flags] do
- renderer = Gitlab::Graphql::Docs::Renderer.new(GitlabSchema.graphql_definition, render_options)
+ renderer = Gitlab::Graphql::Docs::Renderer.new(GitlabSchema, render_options)
doc = File.read(Rails.root.join(OUTPUT_DIR, 'index.md'))
diff --git a/lib/tasks/gitlab/pages.rake b/lib/tasks/gitlab/pages.rake
index b598dab901d..ee2931f0c4f 100644
--- a/lib/tasks/gitlab/pages.rake
+++ b/lib/tasks/gitlab/pages.rake
@@ -9,9 +9,9 @@ namespace :gitlab do
logger.info('Starting to migrate legacy pages storage to zip deployments')
result = ::Pages::MigrateFromLegacyStorageService.new(logger,
- migration_threads: migration_threads,
- batch_size: batch_size,
- ignore_invalid_entries: ignore_invalid_entries).execute
+ ignore_invalid_entries: ignore_invalid_entries,
+ mark_projects_as_not_deployed: mark_projects_as_not_deployed)
+ .execute_with_threads(threads: migration_threads, batch_size: batch_size)
logger.info("A total of #{result[:migrated] + result[:errored]} projects were processed.")
logger.info("- The #{result[:migrated]} projects migrated successfully")
@@ -51,5 +51,39 @@ namespace :gitlab do
ENV.fetch('PAGES_MIGRATION_IGNORE_INVALID_ENTRIES', 'false')
)
end
+
+ def mark_projects_as_not_deployed
+ Gitlab::Utils.to_boolean(
+ ENV.fetch('PAGES_MIGRATION_MARK_PROJECTS_AS_NOT_DEPLOYED', 'false')
+ )
+ end
+
+ namespace :deployments do
+ task migrate_to_object_storage: :gitlab_environment do
+ logger = Logger.new(STDOUT)
+ logger.info('Starting transfer of pages deployments to remote storage')
+
+ helper = Gitlab::Pages::MigrationHelper.new(logger)
+
+ begin
+ helper.migrate_to_remote_storage
+ rescue => e
+ logger.error(e.message)
+ end
+ end
+
+ task migrate_to_local: :gitlab_environment do
+ logger = Logger.new(STDOUT)
+ logger.info('Starting transfer of Pages deployments to local storage')
+
+ helper = Gitlab::Pages::MigrationHelper.new(logger)
+
+ begin
+ helper.migrate_to_local_storage
+ rescue => e
+ logger.error(e.message)
+ end
+ end
+ end
end
end
diff --git a/lib/tasks/gitlab/test.rake b/lib/tasks/gitlab/test.rake
deleted file mode 100644
index a83ba69bc75..00000000000
--- a/lib/tasks/gitlab/test.rake
+++ /dev/null
@@ -1,17 +0,0 @@
-# frozen_string_literal: true
-
-namespace :gitlab do
- desc "GitLab | Run all tests"
- task :test do
- cmds = [
- %w(rake brakeman),
- %w(rake rubocop),
- %w(rake spec),
- %w(rake karma)
- ]
-
- cmds.each do |cmd|
- system({ 'RAILS_ENV' => 'test', 'force' => 'yes' }, *cmd) || raise("#{cmd} failed!")
- end
- end
-end
diff --git a/lib/tasks/spec.rake b/lib/tasks/spec.rake
index bf18332a8eb..5eed5d4dce4 100644
--- a/lib/tasks/spec.rake
+++ b/lib/tasks/spec.rake
@@ -2,30 +2,44 @@
return if Rails.env.production?
+require_relative '../../tooling/merge_request_rspec_failure_rake_task'
+
namespace :spec do
desc 'GitLab | RSpec | Run unit tests'
RSpec::Core::RakeTask.new(:unit, :rspec_opts) do |t, args|
- require_dependency 'quality/test_level'
+ require_test_level
t.pattern = Quality::TestLevel.new.pattern(:unit)
t.rspec_opts = args[:rspec_opts]
end
desc 'GitLab | RSpec | Run integration tests'
RSpec::Core::RakeTask.new(:integration, :rspec_opts) do |t, args|
- require_dependency 'quality/test_level'
+ require_test_level
t.pattern = Quality::TestLevel.new.pattern(:integration)
t.rspec_opts = args[:rspec_opts]
end
desc 'GitLab | RSpec | Run system tests'
RSpec::Core::RakeTask.new(:system, :rspec_opts) do |t, args|
- require_dependency 'quality/test_level'
+ require_test_level
t.pattern = Quality::TestLevel.new.pattern(:system)
t.rspec_opts = args[:rspec_opts]
end
+ desc 'GitLab | RSpec | Run merge request RSpec failures'
+ Tooling::MergeRequestRspecFailureRakeTask.new(:merge_request_rspec_failure, :rspec_opts) do |t, args|
+ t.pattern = t.rspec_failures_on_merge_request
+ t.rspec_opts = args[:rspec_opts]
+ end
+
desc 'Run the code examples in spec/requests/api'
RSpec::Core::RakeTask.new(:api) do |t|
t.pattern = 'spec/requests/api/**/*_spec.rb'
end
+
+ private
+
+ def require_test_level
+ require_relative '../../tooling/quality/test_level'
+ end
end
diff --git a/lib/tasks/test.rake b/lib/tasks/test.rake
index b24817468c6..c4eb9450b31 100644
--- a/lib/tasks/test.rake
+++ b/lib/tasks/test.rake
@@ -2,7 +2,16 @@
Rake::Task["test"].clear
-desc "GitLab | Run all tests"
+desc "GitLab | List rake tasks for tests"
task :test do
- Rake::Task["gitlab:test"].invoke
+ puts "Running the full GitLab test suite takes significant time to pass. We recommend using one of the following spec tasks:\n\n"
+
+ spec_tasks = Rake::Task.tasks.select { |t| t.name.start_with?('spec:') }
+ longest_task_name = spec_tasks.map { |t| t.name.size }.max
+
+ spec_tasks.each do |task|
+ puts "#{"%-#{longest_task_name}s" % task.name} | #{task.full_comment}"
+ end
+
+ puts "\nLearn more at https://docs.gitlab.com/ee/development/rake_tasks.html#run-tests."
end