2017-04-28 11:31:18 -04:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
|
2018-01-23 07:12:51 -05:00
|
|
|
# We don't have auto-loading here
|
2020-03-18 20:09:27 -04:00
|
|
|
require_relative '../lib/gitlab'
|
2018-01-23 07:12:51 -05:00
|
|
|
require_relative '../lib/gitlab/popen'
|
|
|
|
require_relative '../lib/gitlab/popen/runner'
|
|
|
|
|
|
|
|
def emit_warnings(static_analysis)
|
|
|
|
static_analysis.warned_results.each do |result|
|
|
|
|
puts
|
2018-02-12 12:34:07 -05:00
|
|
|
puts "**** #{result.cmd.join(' ')} had the following warning(s):"
|
2018-01-23 07:12:51 -05:00
|
|
|
puts
|
|
|
|
puts result.stderr
|
|
|
|
puts
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def emit_errors(static_analysis)
|
|
|
|
static_analysis.failed_results.each do |result|
|
|
|
|
puts
|
2018-02-12 12:34:07 -05:00
|
|
|
puts "**** #{result.cmd.join(' ')} failed with the following error(s):"
|
2018-01-23 07:12:51 -05:00
|
|
|
puts
|
|
|
|
puts result.stdout
|
|
|
|
puts result.stderr
|
|
|
|
puts
|
|
|
|
end
|
|
|
|
end
|
2017-04-28 11:31:18 -04:00
|
|
|
|
2020-01-05 04:08:10 -05:00
|
|
|
ALLOWED_WARNINGS = [
|
|
|
|
# https://github.com/browserslist/browserslist/blob/d0ec62eb48c41c218478cd3ac28684df051cc865/node.js#L329
|
|
|
|
# warns if caniuse-lite package is older than 6 months. Ignore this
|
|
|
|
# warning message so that GitLab backports don't fail.
|
|
|
|
"Browserslist: caniuse-lite is outdated. Please run next command `yarn upgrade`"
|
|
|
|
].freeze
|
|
|
|
|
|
|
|
def warning_count(static_analysis)
|
|
|
|
static_analysis.warned_results
|
2020-01-05 10:07:58 -05:00
|
|
|
.count { |result| !ALLOWED_WARNINGS.include?(result.stderr.strip) }
|
2020-01-05 04:08:10 -05:00
|
|
|
end
|
|
|
|
|
2019-10-31 17:06:28 -04:00
|
|
|
def jobs_to_run(node_index, node_total)
|
|
|
|
all_tasks = [
|
|
|
|
%w[bin/rake lint:all],
|
|
|
|
%w[bundle exec license_finder],
|
|
|
|
%w[yarn run eslint],
|
|
|
|
%w[yarn run stylelint],
|
|
|
|
%w[yarn run prettier-all],
|
2020-03-02 13:07:42 -05:00
|
|
|
%w[yarn run block-dependencies],
|
2019-10-31 17:06:28 -04:00
|
|
|
%w[bundle exec rubocop --parallel],
|
|
|
|
%w[scripts/lint-conflicts.sh],
|
2019-12-16 13:08:22 -05:00
|
|
|
%w[scripts/lint-rugged],
|
2020-01-10 13:07:43 -05:00
|
|
|
%w[scripts/frontend/check_no_partial_karma_jest.sh],
|
2020-02-26 13:09:24 -05:00
|
|
|
%w[scripts/lint-changelog-filenames],
|
|
|
|
%w[scripts/gemfile_lock_changed.sh]
|
2019-10-31 17:06:28 -04:00
|
|
|
]
|
2017-04-28 11:31:18 -04:00
|
|
|
|
2019-10-31 17:06:28 -04:00
|
|
|
case node_total
|
|
|
|
when 1
|
|
|
|
all_tasks
|
|
|
|
when 2
|
|
|
|
rake_lint_all, *rest_jobs = all_tasks
|
|
|
|
case node_index
|
|
|
|
when 1
|
|
|
|
[rake_lint_all]
|
|
|
|
else
|
|
|
|
rest_jobs
|
|
|
|
end
|
|
|
|
else
|
|
|
|
raise "Parallelization > 2 (currently set to #{node_total}) isn't supported yet!"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
tasks = jobs_to_run((ENV['CI_NODE_INDEX'] || 1).to_i, (ENV['CI_NODE_TOTAL'] || 1).to_i)
|
2018-01-23 07:12:51 -05:00
|
|
|
static_analysis = Gitlab::Popen::Runner.new
|
2017-04-28 11:31:18 -04:00
|
|
|
|
2018-01-23 07:12:51 -05:00
|
|
|
static_analysis.run(tasks) do |cmd, &run|
|
2017-11-03 12:00:49 -04:00
|
|
|
puts
|
2018-01-23 07:12:51 -05:00
|
|
|
puts "$ #{cmd.join(' ')}"
|
2017-04-28 11:31:18 -04:00
|
|
|
|
2018-01-23 07:12:51 -05:00
|
|
|
result = run.call
|
2017-04-28 11:31:18 -04:00
|
|
|
|
2018-01-23 07:12:51 -05:00
|
|
|
puts "==> Finished in #{result.duration} seconds"
|
|
|
|
puts
|
2017-04-28 11:31:18 -04:00
|
|
|
end
|
|
|
|
|
2017-11-03 12:00:49 -04:00
|
|
|
puts
|
|
|
|
puts '==================================================='
|
|
|
|
puts
|
|
|
|
puts
|
|
|
|
|
2018-01-24 08:05:01 -05:00
|
|
|
if static_analysis.all_success_and_clean?
|
2017-04-28 11:31:18 -04:00
|
|
|
puts 'All static analyses passed successfully.'
|
2018-01-24 08:05:01 -05:00
|
|
|
elsif static_analysis.all_success?
|
2018-01-23 07:12:51 -05:00
|
|
|
puts 'All static analyses passed successfully, but we have warnings:'
|
|
|
|
puts
|
|
|
|
|
|
|
|
emit_warnings(static_analysis)
|
|
|
|
|
2020-01-05 04:08:10 -05:00
|
|
|
exit 2 if warning_count(static_analysis).nonzero?
|
2017-04-28 11:31:18 -04:00
|
|
|
else
|
2017-11-03 12:00:49 -04:00
|
|
|
puts 'Some static analyses failed:'
|
2017-04-28 11:31:18 -04:00
|
|
|
|
2018-01-23 07:12:51 -05:00
|
|
|
emit_warnings(static_analysis)
|
|
|
|
emit_errors(static_analysis)
|
2017-04-28 11:31:18 -04:00
|
|
|
|
|
|
|
exit 1
|
|
|
|
end
|