Commit 1f309b69 authored by Robert Speicher's avatar Robert Speicher

Merge branch '41972-make-sure-no-warnings' into 'master'

Fail static-analysis if there's output to stderr

Closes #41972

See merge request gitlab-org/gitlab-ce!16648
parents 7a18675c 02a3f624
...@@ -321,6 +321,7 @@ setup-test-env: ...@@ -321,6 +321,7 @@ setup-test-env:
expire_in: 7d expire_in: 7d
paths: paths:
- tmp/tests - tmp/tests
- config/secrets.yml
rspec-pg 0 27: *rspec-metadata-pg rspec-pg 0 27: *rspec-metadata-pg
rspec-pg 1 27: *rspec-metadata-pg rspec-pg 1 27: *rspec-metadata-pg
......
...@@ -325,7 +325,7 @@ group :development, :test do ...@@ -325,7 +325,7 @@ group :development, :test do
gem 'spinach-rerun-reporter', '~> 0.0.2' gem 'spinach-rerun-reporter', '~> 0.0.2'
gem 'rspec_profiling', '~> 0.0.5' gem 'rspec_profiling', '~> 0.0.5'
gem 'rspec-set', '~> 0.1.3' gem 'rspec-set', '~> 0.1.3'
gem 'rspec-parameterized' gem 'rspec-parameterized', require: false
# Prevent occasions where minitest is not bundled in packaged versions of ruby (see #3826) # Prevent occasions where minitest is not bundled in packaged versions of ruby (see #3826)
gem 'minitest', '~> 5.7.0' gem 'minitest', '~> 5.7.0'
......
...@@ -304,7 +304,7 @@ GEM ...@@ -304,7 +304,7 @@ GEM
mime-types (>= 1.16) mime-types (>= 1.16)
posix-spawn (~> 0.3) posix-spawn (~> 0.3)
gitlab-markup (1.6.3) gitlab-markup (1.6.3)
gitlab-styles (2.3.1) gitlab-styles (2.3.2)
rubocop (~> 0.51) rubocop (~> 0.51)
rubocop-gitlab-security (~> 0.1.0) rubocop-gitlab-security (~> 0.1.0)
rubocop-rspec (~> 1.19) rubocop-rspec (~> 1.19)
......
require_relative "../lib/gitlab/upgrader"
Gitlab::Upgrader.new.execute
...@@ -6,6 +6,7 @@ Bundler.require(:default, Rails.env) ...@@ -6,6 +6,7 @@ Bundler.require(:default, Rails.env)
module Gitlab module Gitlab
class Application < Rails::Application class Application < Rails::Application
require_dependency Rails.root.join('lib/gitlab/redis/wrapper')
require_dependency Rails.root.join('lib/gitlab/redis/cache') require_dependency Rails.root.join('lib/gitlab/redis/cache')
require_dependency Rails.root.join('lib/gitlab/redis/queues') require_dependency Rails.root.join('lib/gitlab/redis/queues')
require_dependency Rails.root.join('lib/gitlab/redis/shared_state') require_dependency Rails.root.join('lib/gitlab/redis/shared_state')
......
...@@ -5,7 +5,17 @@ module Gitlab ...@@ -5,7 +5,17 @@ module Gitlab
module Popen module Popen
extend self extend self
def popen(cmd, path = nil, vars = {}) Result = Struct.new(:cmd, :stdout, :stderr, :status, :duration)
# Returns [stdout + stderr, status]
def popen(cmd, path = nil, vars = {}, &block)
result = popen_with_detail(cmd, path, vars, &block)
[result.stdout << result.stderr, result.status&.exitstatus]
end
# Returns Result
def popen_with_detail(cmd, path = nil, vars = {})
unless cmd.is_a?(Array) unless cmd.is_a?(Array)
raise "System commands must be given as an array of strings" raise "System commands must be given as an array of strings"
end end
...@@ -18,18 +28,21 @@ module Gitlab ...@@ -18,18 +28,21 @@ module Gitlab
FileUtils.mkdir_p(path) FileUtils.mkdir_p(path)
end end
cmd_output = "" cmd_stdout = ''
cmd_status = 0 cmd_stderr = ''
cmd_status = nil
start = Time.now
Open3.popen3(vars, *cmd, options) do |stdin, stdout, stderr, wait_thr| Open3.popen3(vars, *cmd, options) do |stdin, stdout, stderr, wait_thr|
yield(stdin) if block_given? yield(stdin) if block_given?
stdin.close stdin.close
cmd_output << stdout.read cmd_stdout = stdout.read
cmd_output << stderr.read cmd_stderr = stderr.read
cmd_status = wait_thr.value.exitstatus cmd_status = wait_thr.value
end end
[cmd_output, cmd_status] Result.new(cmd, cmd_stdout, cmd_stderr, cmd_status, Time.now - start)
end end
end end
end end
module Gitlab
module Popen
class Runner
attr_reader :results
def initialize
@results = []
end
def run(commands, &block)
commands.each do |cmd|
# yield doesn't support blocks, so we need to use a block variable
block.call(cmd) do # rubocop:disable Performance/RedundantBlockCall
cmd_result = Gitlab::Popen.popen_with_detail(cmd)
results << cmd_result
cmd_result
end
end
end
def all_success_and_clean?
all_success? && all_stderr_empty?
end
def all_success?
results.all? { |result| result.status.success? }
end
def all_stderr_empty?
results.all? { |result| result.stderr.empty? }
end
def failed_results
results.reject { |result| result.status.success? }
end
def warned_results
results.select do |result|
result.status.success? && !result.stderr.empty?
end
end
end
end
end
# please require all dependencies below: # please require all dependencies below:
require_relative 'wrapper' unless defined?(::Gitlab::Redis::Wrapper) require_relative 'wrapper' unless defined?(::Rails) && ::Rails.root.present?
module Gitlab module Gitlab
module Redis module Redis
......
require 'rainbow/ext/string' require 'rainbow/ext/string'
require 'gitlab/utils/strong_memoize' require 'gitlab/utils/strong_memoize'
# rubocop:disable Rails/Output
module Gitlab module Gitlab
TaskFailedError = Class.new(StandardError) TaskFailedError = Class.new(StandardError)
TaskAbortedByUserError = Class.new(StandardError) TaskAbortedByUserError = Class.new(StandardError)
...@@ -96,11 +97,9 @@ module Gitlab ...@@ -96,11 +97,9 @@ module Gitlab
end end
def gid_for(group_name) def gid_for(group_name)
begin Etc.getgrnam(group_name).gid
Etc.getgrnam(group_name).gid rescue ArgumentError # no group
rescue ArgumentError # no group "group #{group_name} doesn't exist"
"group #{group_name} doesn't exist"
end
end end
def gitlab_user def gitlab_user
......
require_relative "popen"
require_relative "version_info"
module Gitlab module Gitlab
class Upgrader class Upgrader
def execute def execute
......
require 'tasks/gitlab/task_helpers'
module SystemCheck module SystemCheck
module Helpers module Helpers
include ::Gitlab::TaskHelpers include ::Gitlab::TaskHelpers
......
desc 'Code duplication analyze via flay' desc 'Code duplication analyze via flay'
task :flay do task :flay do
output = `bundle exec flay --mass 35 app/ lib/gitlab/` output = `bundle exec flay --mass 35 app/ lib/gitlab/ 2> #{File::NULL}`
if output.include? "Similar code found" if output.include? "Similar code found"
puts output puts output
......
...@@ -4,7 +4,7 @@ namespace :gitlab do ...@@ -4,7 +4,7 @@ namespace :gitlab do
namespace :backup do namespace :backup do
# Create backup of GitLab system # Create backup of GitLab system
desc "GitLab | Create a backup of the GitLab system" desc "GitLab | Create a backup of the GitLab system"
task create: :environment do task create: :gitlab_environment do
warn_user_is_not_gitlab warn_user_is_not_gitlab
configure_cron_mode configure_cron_mode
...@@ -25,7 +25,7 @@ namespace :gitlab do ...@@ -25,7 +25,7 @@ namespace :gitlab do
# Restore backup of GitLab system # Restore backup of GitLab system
desc 'GitLab | Restore a previously created backup' desc 'GitLab | Restore a previously created backup'
task restore: :environment do task restore: :gitlab_environment do
warn_user_is_not_gitlab warn_user_is_not_gitlab
configure_cron_mode configure_cron_mode
...@@ -73,7 +73,7 @@ namespace :gitlab do ...@@ -73,7 +73,7 @@ namespace :gitlab do
end end
namespace :repo do namespace :repo do
task create: :environment do task create: :gitlab_environment do
$progress.puts "Dumping repositories ...".color(:blue) $progress.puts "Dumping repositories ...".color(:blue)
if ENV["SKIP"] && ENV["SKIP"].include?("repositories") if ENV["SKIP"] && ENV["SKIP"].include?("repositories")
...@@ -84,7 +84,7 @@ namespace :gitlab do ...@@ -84,7 +84,7 @@ namespace :gitlab do
end end
end end
task restore: :environment do task restore: :gitlab_environment do
$progress.puts "Restoring repositories ...".color(:blue) $progress.puts "Restoring repositories ...".color(:blue)
Backup::Repository.new.restore Backup::Repository.new.restore
$progress.puts "done".color(:green) $progress.puts "done".color(:green)
...@@ -92,7 +92,7 @@ namespace :gitlab do ...@@ -92,7 +92,7 @@ namespace :gitlab do
end end
namespace :db do namespace :db do
task create: :environment do task create: :gitlab_environment do
$progress.puts "Dumping database ... ".color(:blue) $progress.puts "Dumping database ... ".color(:blue)
if ENV["SKIP"] && ENV["SKIP"].include?("db") if ENV["SKIP"] && ENV["SKIP"].include?("db")
...@@ -103,7 +103,7 @@ namespace :gitlab do ...@@ -103,7 +103,7 @@ namespace :gitlab do
end end
end end
task restore: :environment do task restore: :gitlab_environment do
$progress.puts "Restoring database ... ".color(:blue) $progress.puts "Restoring database ... ".color(:blue)
Backup::Database.new.restore Backup::Database.new.restore
$progress.puts "done".color(:green) $progress.puts "done".color(:green)
...@@ -111,7 +111,7 @@ namespace :gitlab do ...@@ -111,7 +111,7 @@ namespace :gitlab do
end end
namespace :builds do namespace :builds do
task create: :environment do task create: :gitlab_environment do
$progress.puts "Dumping builds ... ".color(:blue) $progress.puts "Dumping builds ... ".color(:blue)
if ENV["SKIP"] && ENV["SKIP"].include?("builds") if ENV["SKIP"] && ENV["SKIP"].include?("builds")
...@@ -122,7 +122,7 @@ namespace :gitlab do ...@@ -122,7 +122,7 @@ namespace :gitlab do
end end
end end
task restore: :environment do task restore: :gitlab_environment do
$progress.puts "Restoring builds ... ".color(:blue) $progress.puts "Restoring builds ... ".color(:blue)
Backup::Builds.new.restore Backup::Builds.new.restore
$progress.puts "done".color(:green) $progress.puts "done".color(:green)
...@@ -130,7 +130,7 @@ namespace :gitlab do ...@@ -130,7 +130,7 @@ namespace :gitlab do
end end
namespace :uploads do namespace :uploads do
task create: :environment do task create: :gitlab_environment do
$progress.puts "Dumping uploads ... ".color(:blue) $progress.puts "Dumping uploads ... ".color(:blue)
if ENV["SKIP"] && ENV["SKIP"].include?("uploads") if ENV["SKIP"] && ENV["SKIP"].include?("uploads")
...@@ -141,7 +141,7 @@ namespace :gitlab do ...@@ -141,7 +141,7 @@ namespace :gitlab do
end end
end end
task restore: :environment do task restore: :gitlab_environment do
$progress.puts "Restoring uploads ... ".color(:blue) $progress.puts "Restoring uploads ... ".color(:blue)
Backup::Uploads.new.restore Backup::Uploads.new.restore
$progress.puts "done".color(:green) $progress.puts "done".color(:green)
...@@ -149,7 +149,7 @@ namespace :gitlab do ...@@ -149,7 +149,7 @@ namespace :gitlab do
end end
namespace :artifacts do namespace :artifacts do
task create: :environment do task create: :gitlab_environment do
$progress.puts "Dumping artifacts ... ".color(:blue) $progress.puts "Dumping artifacts ... ".color(:blue)
if ENV["SKIP"] && ENV["SKIP"].include?("artifacts") if ENV["SKIP"] && ENV["SKIP"].include?("artifacts")
...@@ -160,7 +160,7 @@ namespace :gitlab do ...@@ -160,7 +160,7 @@ namespace :gitlab do
end end
end end
task restore: :environment do task restore: :gitlab_environment do
$progress.puts "Restoring artifacts ... ".color(:blue) $progress.puts "Restoring artifacts ... ".color(:blue)
Backup::Artifacts.new.restore Backup::Artifacts.new.restore
$progress.puts "done".color(:green) $progress.puts "done".color(:green)
...@@ -168,7 +168,7 @@ namespace :gitlab do ...@@ -168,7 +168,7 @@ namespace :gitlab do
end end
namespace :pages do namespace :pages do
task create: :environment do task create: :gitlab_environment do
$progress.puts "Dumping pages ... ".color(:blue) $progress.puts "Dumping pages ... ".color(:blue)
if ENV["SKIP"] && ENV["SKIP"].include?("pages") if ENV["SKIP"] && ENV["SKIP"].include?("pages")
...@@ -179,7 +179,7 @@ namespace :gitlab do ...@@ -179,7 +179,7 @@ namespace :gitlab do
end end
end end
task restore: :environment do task restore: :gitlab_environment do
$progress.puts "Restoring pages ... ".color(:blue) $progress.puts "Restoring pages ... ".color(:blue)
Backup::Pages.new.restore Backup::Pages.new.restore
$progress.puts "done".color(:green) $progress.puts "done".color(:green)
...@@ -187,7 +187,7 @@ namespace :gitlab do ...@@ -187,7 +187,7 @@ namespace :gitlab do
end end
namespace :lfs do namespace :lfs do
task create: :environment do task create: :gitlab_environment do
$progress.puts "Dumping lfs objects ... ".color(:blue) $progress.puts "Dumping lfs objects ... ".color(:blue)
if ENV["SKIP"] && ENV["SKIP"].include?("lfs") if ENV["SKIP"] && ENV["SKIP"].include?("lfs")
...@@ -198,7 +198,7 @@ namespace :gitlab do ...@@ -198,7 +198,7 @@ namespace :gitlab do
end end
end end
task restore: :environment do task restore: :gitlab_environment do
$progress.puts "Restoring lfs objects ... ".color(:blue) $progress.puts "Restoring lfs objects ... ".color(:blue)
Backup::Lfs.new.restore Backup::Lfs.new.restore
$progress.puts "done".color(:green) $progress.puts "done".color(:green)
...@@ -206,7 +206,7 @@ namespace :gitlab do ...@@ -206,7 +206,7 @@ namespace :gitlab do
end end
namespace :registry do namespace :registry do
task create: :environment do task create: :gitlab_environment do
$progress.puts "Dumping container registry images ... ".color(:blue) $progress.puts "Dumping container registry images ... ".color(:blue)
if Gitlab.config.registry.enabled if Gitlab.config.registry.enabled
...@@ -221,7 +221,7 @@ namespace :gitlab do ...@@ -221,7 +221,7 @@ namespace :gitlab do
end end
end end
task restore: :environment do task restore: :gitlab_environment do
$progress.puts "Restoring container registry images ... ".color(:blue) $progress.puts "Restoring container registry images ... ".color(:blue)
if Gitlab.config.registry.enabled if Gitlab.config.registry.enabled
......
# Temporary hack, until we migrate all checks to SystemCheck format
require 'system_check'
require 'system_check/helpers'
namespace :gitlab do namespace :gitlab do
desc 'GitLab | Check the configuration of GitLab and its environment' desc 'GitLab | Check the configuration of GitLab and its environment'
task check: %w{gitlab:gitlab_shell:check task check: %w{gitlab:gitlab_shell:check
...@@ -12,7 +8,7 @@ namespace :gitlab do ...@@ -12,7 +8,7 @@ namespace :gitlab do
namespace :app do namespace :app do
desc 'GitLab | Check the configuration of the GitLab Rails app' desc 'GitLab | Check the configuration of the GitLab Rails app'
task check: :environment do task check: :gitlab_environment do
warn_user_is_not_gitlab warn_user_is_not_gitlab
checks = [ checks = [
...@@ -43,7 +39,7 @@ namespace :gitlab do ...@@ -43,7 +39,7 @@ namespace :gitlab do
namespace :gitlab_shell do namespace :gitlab_shell do
desc "GitLab | Check the configuration of GitLab Shell" desc "GitLab | Check the configuration of GitLab Shell"
task check: :environment do task check: :gitlab_environment do
warn_user_is_not_gitlab warn_user_is_not_gitlab
start_checking "GitLab Shell" start_checking "GitLab Shell"
...@@ -251,7 +247,7 @@ namespace :gitlab do ...@@ -251,7 +247,7 @@ namespace :gitlab do
namespace :sidekiq do namespace :sidekiq do
desc "GitLab | Check the configuration of Sidekiq" desc "GitLab | Check the configuration of Sidekiq"
task check: :environment do task check: :gitlab_environment do
warn_user_is_not_gitlab warn_user_is_not_gitlab
start_checking "Sidekiq" start_checking "Sidekiq"
...@@ -310,7 +306,7 @@ namespace :gitlab do ...@@ -310,7 +306,7 @@ namespace :gitlab do
namespace :incoming_email do namespace :incoming_email do
desc "GitLab | Check the configuration of Reply by email" desc "GitLab | Check the configuration of Reply by email"
task check: :environment do task check: :gitlab_environment do
warn_user_is_not_gitlab warn_user_is_not_gitlab
if Gitlab.config.incoming_email.enabled if Gitlab.config.incoming_email.enabled
...@@ -333,7 +329,7 @@ namespace :gitlab do ...@@ -333,7 +329,7 @@ namespace :gitlab do
end end
namespace :ldap do namespace :ldap do
task :check, [:limit] => :environment do |_, args| task :check, [:limit] => :gitlab_environment do |_, args|
# Only show up to 100 results because LDAP directories can be very big. # Only show up to 100 results because LDAP directories can be very big.
# This setting only affects the `rake gitlab:check` script. # This setting only affects the `rake gitlab:check` script.
args.with_defaults(limit: 100) args.with_defaults(limit: 100)
...@@ -389,7 +385,7 @@ namespace :gitlab do ...@@ -389,7 +385,7 @@ namespace :gitlab do
namespace :repo do namespace :repo do
desc "GitLab | Check the integrity of the repositories managed by GitLab" desc "GitLab | Check the integrity of the repositories managed by GitLab"
task check: :environment do task check: :gitlab_environment do
puts "This task is deprecated. Please use gitlab:git:fsck instead".color(:red) puts "This task is deprecated. Please use gitlab:git:fsck instead".color(:red)
Rake::Task["gitlab:git:fsck"].execute Rake::Task["gitlab:git:fsck"].execute
end end
...@@ -397,7 +393,7 @@ namespace :gitlab do ...@@ -397,7 +393,7 @@ namespace :gitlab do
namespace :orphans do namespace :orphans do
desc 'Gitlab | Check for orphaned namespaces and repositories' desc 'Gitlab | Check for orphaned namespaces and repositories'
task check: :environment do task check: :gitlab_environment do
warn_user_is_not_gitlab warn_user_is_not_gitlab
checks = [ checks = [
SystemCheck::Orphans::NamespaceCheck, SystemCheck::Orphans::NamespaceCheck,
...@@ -408,7 +404,7 @@ namespace :gitlab do ...@@ -408,7 +404,7 @@ namespace :gitlab do
end end
desc 'GitLab | Check for orphaned namespaces in the repositories path' desc 'GitLab | Check for orphaned namespaces in the repositories path'
task check_namespaces: :environment do task check_namespaces: :gitlab_environment do
warn_user_is_not_gitlab warn_user_is_not_gitlab
checks = [SystemCheck::Orphans::NamespaceCheck] checks = [SystemCheck::Orphans::NamespaceCheck]
...@@ -416,7 +412,7 @@ namespace :gitlab do ...@@ -416,7 +412,7 @@ namespace :gitlab do
end end
desc 'GitLab | Check for orphaned repositories in the repositories path' desc 'GitLab | Check for orphaned repositories in the repositories path'
task check_repositories: :environment do task check_repositories: :gitlab_environment do
warn_user_is_not_gitlab warn_user_is_not_gitlab
checks = [SystemCheck::Orphans::RepositoryCheck] checks = [SystemCheck::Orphans::RepositoryCheck]
...@@ -426,7 +422,7 @@ namespace :gitlab do ...@@ -426,7 +422,7 @@ namespace :gitlab do
namespace :user do namespace :user do
desc "GitLab | Check the integrity of a specific user's repositories" desc "GitLab | Check the integrity of a specific user's repositories"
task :check_repos, [:username] => :environment do |t, args| task :check_repos, [:username] => :gitlab_environment do |t, args|
username = args[:username] || prompt("Check repository integrity for username? ".color(:blue)) username = args[:username] || prompt("Check repository integrity for username? ".color(:blue))
user = User.find_by(username: username) user = User.find_by(username: username)
if user if user
......
...@@ -5,7 +5,7 @@ namespace :gitlab do ...@@ -5,7 +5,7 @@ namespace :gitlab do
HASHED_REPOSITORY_NAME = '@hashed'.freeze HASHED_REPOSITORY_NAME = '@hashed'.freeze
desc "GitLab | Cleanup | Clean namespaces" desc "GitLab | Cleanup | Clean namespaces"
task dirs: :environment do task dirs: :gitlab_environment do
warn_user_is_not_gitlab warn_user_is_not_gitlab
remove_flag = ENV['REMOVE'] remove_flag = ENV['REMOVE']
...@@ -49,7 +49,7 @@ namespace :gitlab do ...@@ -49,7 +49,7 @@ namespace :gitlab do
end end
desc "GitLab | Cleanup | Clean repositories" desc "GitLab | Cleanup | Clean repositories"
task repos: :environment do task repos: :gitlab_environment do
warn_user_is_not_gitlab warn_user_is_not_gitlab
move_suffix = "+orphaned+#{Time.now.to_i}" move_suffix = "+orphaned+#{Time.now.to_i}"
...@@ -78,7 +78,7 @@ namespace :gitlab do ...@@ -78,7 +78,7 @@ namespace :gitlab do
end end
desc "GitLab | Cleanup | Block users that have been removed in LDAP" desc "GitLab | Cleanup | Block users that have been removed in LDAP"
task block_removed_ldap_users: :environment do task block_removed_ldap_users: :gitlab_environment do
warn_user_is_not_gitlab warn_user_is_not_gitlab
block_flag = ENV['BLOCK'] block_flag = ENV['BLOCK']
...@@ -109,7 +109,7 @@ namespace :gitlab do ...@@ -109,7 +109,7 @@ namespace :gitlab do
# released. So likely this should only be run once on gitlab.com # released. So likely this should only be run once on gitlab.com
# Faulty refs are moved so they are kept around, else some features break. # Faulty refs are moved so they are kept around, else some features break.
desc 'GitLab | Cleanup | Remove faulty deployment refs' desc 'GitLab | Cleanup | Remove faulty deployment refs'
task move_faulty_deployment_refs: :environment do task move_faulty_deployment_refs: :gitlab_environment do
projects = Project.where(id: Deployment.select(:project_id).distinct) projects = Project.where(id: Deployment.select(:project_id).distinct)
projects.find_each do |project| projects.find_each do |project|
......
namespace :gitlab do namespace :gitlab do
namespace :git do namespace :git do
desc "GitLab | Git | Repack" desc "GitLab | Git | Repack"
task repack: :environment do task repack: :gitlab_environment do
failures = perform_git_cmd(%W(#{Gitlab.config.git.bin_path} repack -a --quiet), "Repacking repo") failures = perform_git_cmd(%W(#{Gitlab.config.git.bin_path} repack -a --quiet), "Repacking repo")
if failures.empty? if failures.empty?
puts "Done".color(:green) puts "Done".color(:green)
...@@ -11,7 +11,7 @@ namespace :gitlab do ...@@ -11,7 +11,7 @@ namespace :gitlab do
end end
desc "GitLab | Git | Run garbage collection on all repos" desc "GitLab | Git | Run garbage collection on all repos"
task gc: :environment do task gc: :gitlab_environment do
failures = perform_git_cmd(%W(#{Gitlab.config.git.bin_path} gc --auto --quiet), "Garbage Collecting") failures = perform_git_cmd(%W(#{Gitlab.config.git.bin_path} gc --auto --quiet), "Garbage Collecting")
if failures.empty? if failures.empty?
puts "Done".color(:green) puts "Done".color(:green)
...@@ -21,7 +21,7 @@ namespace :gitlab do ...@@ -21,7 +21,7 @@ namespace :gitlab do
end end
desc "GitLab | Git | Prune all repos" desc "GitLab | Git | Prune all repos"
task prune: :environment do task prune: :gitlab_environment do
failures = perform_git_cmd(%W(#{Gitlab.config.git.bin_path} prune), "Git Prune") failures = perform_git_cmd(%W(#{Gitlab.config.git.bin_path} prune), "Git Prune")
if failures.empty? if failures.empty?
puts "Done".color(:green) puts "Done".color(:green)
...@@ -31,7 +31,7 @@ namespace :gitlab do ...@@ -31,7 +31,7 @@ namespace :gitlab do
end end
desc 'GitLab | Git | Check all repos integrity' desc 'GitLab | Git | Check all repos integrity'
task fsck: :environment do task fsck: :gitlab_environment do
failures = perform_git_cmd(%W(#{Gitlab.config.git.bin_path} fsck --name-objects --no-progress), "Checking integrity") do |repo| failures = perform_git_cmd(%W(#{Gitlab.config.git.bin_path} fsck --name-objects --no-progress), "Checking integrity") do |repo|
check_config_lock(repo) check_config_lock(repo)
check_ref_locks(repo) check_ref_locks(repo)
......
namespace :gitlab do namespace :gitlab do
namespace :gitaly do namespace :gitaly do
desc "GitLab | Install or upgrade gitaly" desc "GitLab | Install or upgrade gitaly"
task :install, [:dir, :repo] => :environment do |t, args| task :install, [:dir, :repo] => :gitlab_environment do |t, args|
require 'toml' require 'toml'
warn_user_is_not_gitlab warn_user_is_not_gitlab
......
require 'tasks/gitlab/task_helpers'
# Prevent StateMachine warnings from outputting during a cron task # Prevent StateMachine warnings from outputting during a cron task
StateMachines::Machine.ignore_method_conflicts = true if ENV['CRON'] StateMachines::Machine.ignore_method_conflicts = true if ENV['CRON']
namespace :gitlab do task gitlab_environment: :environment do
extend SystemCheck::Helpers extend SystemCheck::Helpers
end end
namespace :gitlab do namespace :gitlab do
namespace :env do namespace :env do
desc "GitLab | Show information about GitLab and its environment" desc "GitLab | Show information about GitLab and its environment"
task info: :environment do task info: :gitlab_environment do
# check if there is an RVM environment # check if there is an RVM environment
rvm_version = run_and_match(%w(rvm --version), /[\d\.]+/).try(:to_s) rvm_version = run_and_match(%w(rvm --version), /[\d\.]+/).try(:to_s)
# check Ruby version # check Ruby version
......
namespace :gitlab do namespace :gitlab do
desc "GitLab | Setup production application" desc "GitLab | Setup production application"
task setup: :environment do task setup: :gitlab_environment do
setup_db setup_db
end end
......
namespace :gitlab do namespace :gitlab do
namespace :shell do namespace :shell do
desc "GitLab | Install or upgrade gitlab-shell" desc "GitLab | Install or upgrade gitlab-shell"
task :install, [:repo] => :environment do |t, args| task :install, [:repo] => :gitlab_environment do |t, args|
warn_user_is_not_gitlab warn_user_is_not_gitlab
default_version = Gitlab::Shell.version_required default_version = Gitlab::Shell.version_required
...@@ -58,12 +58,12 @@ namespace :gitlab do ...@@ -58,12 +58,12 @@ namespace :gitlab do
end end
desc "GitLab | Setup gitlab-shell" desc "GitLab | Setup gitlab-shell"
task setup: :environment do task setup: :gitlab_environment do
setup setup
end end
desc "GitLab | Build missing projects" desc "GitLab | Build missing projects"
task build_missing_projects: :environment do task build_missing_projects: :gitlab_environment do
Project.find_each(batch_size: 1000) do |project| Project.find_each(batch_size: 1000) do |project|
path_to_repo = project.repository.path_to_repo path_to_repo = project.repository.path_to_repo
if File.exist?(path_to_repo) if File.exist?(path_to_repo)
...@@ -80,7 +80,7 @@ namespace :gitlab do ...@@ -80,7 +80,7 @@ namespace :gitlab do
end end
desc 'Create or repair repository hooks symlink' desc 'Create or repair repository hooks symlink'
task create_hooks: :environment do task create_hooks: :gitlab_environment do
warn_user_is_not_gitlab warn_user_is_not_gitlab
puts 'Creating/Repairing hooks symlinks for all repositories' puts 'Creating/Repairing hooks symlinks for all repositories'
......
namespace :gitlab do namespace :gitlab do
namespace :workhorse do namespace :workhorse do
desc "GitLab | Install or upgrade gitlab-workhorse" desc "GitLab | Install or upgrade gitlab-workhorse"
task :install, [:dir, :repo] => :environment do |t, args| task :install, [:dir, :repo] => :gitlab_environment do |t, args|
warn_user_is_not_gitlab warn_user_is_not_gitlab
unless args.dir.present? unless args.dir.present?
......
...@@ -2,5 +2,14 @@ unless Rails.env.production? ...@@ -2,5 +2,14 @@ unless Rails.env.production?
require 'haml_lint/rake_task' require 'haml_lint/rake_task'
require 'haml_lint/inline_javascript' require 'haml_lint/inline_javascript'
# Workaround for warnings from parser/current
# TODO: Remove this after we update parser gem
task :haml_lint do
require 'parser'
def Parser.warn(*args)
puts(*args) # static-analysis ignores stdout if status is 0
end
end
HamlLint::RakeTask.new HamlLint::RakeTask.new
end end
require Rails.root.join('lib/gitlab/database')
require Rails.root.join('lib/gitlab/database/migration_helpers')
require Rails.root.join('db/migrate/20151007120511_namespaces_projects_path_lower_indexes')
require Rails.root.join('db/migrate/20151008110232_add_users_lower_username_email_indexes')
require Rails.root.join('db/migrate/20161212142807_add_lower_path_index_to_routes')
require Rails.root.join('db/migrate/20170317203554_index_routes_path_for_like')
require Rails.root.join('db/migrate/20170724214302_add_lower_path_index_to_redirect_routes')
require Rails.root.join('db/migrate/20170503185032_index_redirect_routes_path_for_like')
require Rails.root.join('db/migrate/20171220191323_add_index_on_namespaces_lower_name.rb')
require Rails.root.join('db/migrate/20180113220114_rework_redirect_routes_indexes.rb')
desc 'GitLab | Sets up PostgreSQL' desc 'GitLab | Sets up PostgreSQL'
task setup_postgresql: :environment do task setup_postgresql: :environment do
require Rails.root.join('db/migrate/20151007120511_namespaces_projects_path_lower_indexes')
require Rails.root.join('db/migrate/20151008110232_add_users_lower_username_email_indexes')
require Rails.root.join('db/migrate/20161212142807_add_lower_path_index_to_routes')
require Rails.root.join('db/migrate/20170317203554_index_routes_path_for_like')
require Rails.root.join('db/migrate/20170724214302_add_lower_path_index_to_redirect_routes')
require Rails.root.join('db/migrate/20170503185032_index_redirect_routes_path_for_like')
require Rails.root.join('db/migrate/20171220191323_add_index_on_namespaces_lower_name.rb')
require Rails.root.join('db/migrate/20180113220114_rework_redirect_routes_indexes.rb')
NamespacesProjectsPathLowerIndexes.new.up NamespacesProjectsPathLowerIndexes.new.up
AddUsersLowerUsernameEmailIndexes.new.up AddUsersLowerUsernameEmailIndexes.new.up
AddLowerPathIndexToRoutes.new.up AddLowerPathIndexToRoutes.new.up
......
#!/usr/bin/env ruby #!/usr/bin/env ruby
require ::File.expand_path('../lib/gitlab/popen', __dir__) # We don't have auto-loading here
require_relative '../lib/gitlab/popen'
require_relative '../lib/gitlab/popen/runner'
def emit_warnings(static_analysis)
static_analysis.warned_results.each do |result|
puts
puts "**** #{result.cmd.join(' ')} had the following warnings:"
puts
puts result.stderr
puts
end
end
def emit_errors(static_analysis)
static_analysis.failed_results.each do |result|
puts
puts "**** #{result.cmd.join(' ')} failed with the following error:"
puts
puts result.stdout
puts result.stderr
puts
end
end
tasks = [ tasks = [
%w[bundle exec rake config_lint], %w[bundle exec rake config_lint],
...@@ -17,18 +40,16 @@ tasks = [ ...@@ -17,18 +40,16 @@ tasks = [
%w[scripts/lint-rugged] %w[scripts/lint-rugged]
] ]
failed_tasks = tasks.reduce({}) do |failures, task| static_analysis = Gitlab::Popen::Runner.new
start = Time.now
puts
puts "$ #{task.join(' ')}"
output, status = Gitlab::Popen.popen(task) static_analysis.run(tasks) do |cmd, &run|
puts "==> Finished in #{Time.now - start} seconds"
puts puts
puts "$ #{cmd.join(' ')}"
failures[task.join(' ')] = output unless status.zero? result = run.call
failures puts "==> Finished in #{result.duration} seconds"
puts
end end
puts puts
...@@ -36,17 +57,20 @@ puts '===================================================' ...@@ -36,17 +57,20 @@ puts '==================================================='
puts puts
puts puts
if failed_tasks.empty? if static_analysis.all_success_and_clean?
puts 'All static analyses passed successfully.' puts 'All static analyses passed successfully.'
elsif static_analysis.all_success?
puts 'All static analyses passed successfully, but we have warnings:'
puts
emit_warnings(static_analysis)
exit 2
else else
puts 'Some static analyses failed:' puts 'Some static analyses failed:'
failed_tasks.each do |failed_task, output| emit_warnings(static_analysis)
puts emit_errors(static_analysis)
puts "**** #{failed_task} failed with the following error:"
puts
puts output
end
exit 1 exit 1
end end
require 'spec_helper'
describe Gitlab::Popen::Runner do
subject { described_class.new }
describe '#run' do
it 'runs the command and returns the result' do
run_command
expect(Gitlab::Popen).to have_received(:popen_with_detail)
end
end
describe '#all_success_and_clean?' do
it 'returns true when exit status is 0 and stderr is empty' do
run_command
expect(subject).to be_all_success_and_clean
end
it 'returns false when exit status is not 0' do
run_command(exitstatus: 1)
expect(subject).not_to be_all_success_and_clean
end
it 'returns false when exit stderr has something' do
run_command(stderr: 'stderr')
expect(subject).not_to be_all_success_and_clean
end
end
describe '#all_success?' do
it 'returns true when exit status is 0' do
run_command
expect(subject).to be_all_success
end
it 'returns false when exit status is not 0' do
run_command(exitstatus: 1)
expect(subject).not_to be_all_success
end
it 'returns true' do
run_command(stderr: 'stderr')
expect(subject).to be_all_success
end
end
describe '#all_stderr_empty?' do
it 'returns true when stderr is empty' do
run_command
expect(subject).to be_all_stderr_empty
end
it 'returns true when exit status is not 0' do
run_command(exitstatus: 1)
expect(subject).to be_all_stderr_empty
end
it 'returns false when exit stderr has something' do
run_command(stderr: 'stderr')
expect(subject).not_to be_all_stderr_empty
end
end
describe '#failed_results' do
it 'returns [] when everything is passed' do
run_command
expect(subject.failed_results).to be_empty
end
it 'returns the result when exit status is not 0' do
result = run_command(exitstatus: 1)
expect(subject.failed_results).to contain_exactly(result)
end
it 'returns [] when exit stderr has something' do
run_command(stderr: 'stderr')
expect(subject.failed_results).to be_empty
end
end
describe '#warned_results' do
it 'returns [] when everything is passed' do
run_command
expect(subject.warned_results).to be_empty
end
it 'returns [] when exit status is not 0' do
run_command(exitstatus: 1)
expect(subject.warned_results).to be_empty
end
it 'returns the result when exit stderr has something' do
result = run_command(stderr: 'stderr')
expect(subject.warned_results).to contain_exactly(result)
end
end
def run_command(
command: 'command',
stdout: 'stdout',
stderr: '',
exitstatus: 0,
status: double(exitstatus: exitstatus, success?: exitstatus.zero?),
duration: 0.1)
result =
Gitlab::Popen::Result.new(command, stdout, stderr, status, duration)
allow(Gitlab::Popen)
.to receive(:popen_with_detail)
.and_return(result)
subject.run([command]) do |cmd, &run|
expect(cmd).to eq(command)
cmd_result = run.call
expect(cmd_result).to eq(result)
end
subject.results.first
end
end
require 'spec_helper' require 'spec_helper'
describe 'Gitlab::Popen' do describe Gitlab::Popen do
let(:path) { Rails.root.join('tmp').to_s } let(:path) { Rails.root.join('tmp').to_s }
before do before do
@klass = Class.new(Object) @klass = Class.new(Object)
@klass.send(:include, Gitlab::Popen) @klass.send(:include, described_class)
end
describe '.popen_with_detail' do
subject { @klass.new.popen_with_detail(cmd) }
let(:cmd) { %W[#{Gem.ruby} -e $stdout.puts(1);$stderr.puts(2);exit(3)] }
it { expect(subject.cmd).to eq(cmd) }
it { expect(subject.stdout).to eq("1\n") }
it { expect(subject.stderr).to eq("2\n") }
it { expect(subject.status.exitstatus).to eq(3) }
it { expect(subject.duration).to be_kind_of(Numeric) }
end end
context 'zero status' do context 'zero status' do
......
require 'action_dispatch/testing/test_request' require 'action_dispatch/testing/test_request'
require 'fileutils' require 'fileutils'
require 'gitlab/popen'
module JavaScriptFixturesHelpers module JavaScriptFixturesHelpers
include Gitlab::Popen include Gitlab::Popen
......
require 'spec_helper' require 'spec_helper'
require 'tasks/gitlab/task_helpers'
class TestHelpersTest class TestHelpersTest
include Gitlab::TaskHelpers include Gitlab::TaskHelpers
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment