static-analysis 1.47 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],
Tim Zallmann's avatar
Tim Zallmann committed
32
  %w[yarn run stylelint],
33
  %w[yarn run prettier-all],
34
  %w[bundle exec rubocop --parallel],
35 36
  %w[scripts/lint-conflicts.sh],
  %w[scripts/lint-rugged]
37 38
]

39
static_analysis = Gitlab::Popen::Runner.new
40

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

45
  result = run.call
46

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

51 52 53 54 55
puts
puts '==================================================='
puts
puts

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

  emit_warnings(static_analysis)

  exit 2
65
else
66
  puts 'Some static analyses failed:'
67

68 69
  emit_warnings(static_analysis)
  emit_errors(static_analysis)
70 71 72

  exit 1
end