static-analysis 1.41 KB
Newer Older
1 2
#!/usr/bin/env ruby

3 4 5 6 7 8 9
# 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
10
    puts "**** #{result.cmd.join(' ')} had the following warning(s):"
11 12 13 14 15 16 17 18 19
    puts
    puts result.stderr
    puts
  end
end

def emit_errors(static_analysis)
  static_analysis.failed_results.each do |result|
    puts
20
    puts "**** #{result.cmd.join(' ')} failed with the following error(s):"
21 22 23 24 25 26
    puts
    puts result.stdout
    puts result.stderr
    puts
  end
end
27 28

tasks = [
29
  %w[bin/rake lint:all],
30 31
  %w[bundle exec license_finder],
  %w[yarn run eslint],
32
  %w[bundle exec rubocop --parallel],
33 34
  %w[scripts/lint-conflicts.sh],
  %w[scripts/lint-rugged]
35 36
]

37
static_analysis = Gitlab::Popen::Runner.new
38

39
static_analysis.run(tasks) do |cmd, &run|
40
  puts
41
  puts "$ #{cmd.join(' ')}"
42

43
  result = run.call
44

45 46
  puts "==> Finished in #{result.duration} seconds"
  puts
47 48
end

49 50 51 52 53
puts
puts '==================================================='
puts
puts

54
if static_analysis.all_success_and_clean?
55
  puts 'All static analyses passed successfully.'
56
elsif static_analysis.all_success?
57 58 59 60 61 62
  puts 'All static analyses passed successfully, but we have warnings:'
  puts

  emit_warnings(static_analysis)

  exit 2
63
else
64
  puts 'Some static analyses failed:'
65

66 67
  emit_warnings(static_analysis)
  emit_errors(static_analysis)
68 69 70

  exit 1
end