summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorLin Jen-Shin <godfat@godfat.org>2018-01-23 20:12:51 +0800
committerLin Jen-Shin <godfat@godfat.org>2018-01-26 19:42:48 +0800
commit54ca8d0d6c4744be53c7044b9bbfa05acc358090 (patch)
treeb4258bc91245eca92b2ef5321f18e67ee524c61c /scripts
parenta0d57ee2b35f0e232aff930a94dfbcabe2860158 (diff)
downloadgitlab-ce-54ca8d0d6c4744be53c7044b9bbfa05acc358090.tar.gz
Fail static-analysis if there's output to stderr
TODO: fix offenders
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/static-analysis57
1 files changed, 41 insertions, 16 deletions
diff --git a/scripts/static-analysis b/scripts/static-analysis
index 96d08287ded..392dc784945 100755
--- a/scripts/static-analysis
+++ b/scripts/static-analysis
@@ -1,6 +1,30 @@
#!/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.stdout
+ 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 = [
%w[bundle exec rake config_lint],
@@ -17,18 +41,16 @@ tasks = [
%w[scripts/lint-rugged]
]
-failed_tasks = tasks.reduce({}) do |failures, task|
- start = Time.now
- puts
- puts "$ #{task.join(' ')}"
+static_analysis = Gitlab::Popen::Runner.new
- output, status = Gitlab::Popen.popen(task)
- puts "==> Finished in #{Time.now - start} seconds"
+static_analysis.run(tasks) do |cmd, &run|
puts
+ puts "$ #{cmd.join(' ')}"
- failures[task.join(' ')] = output unless status.zero?
+ result = run.call
- failures
+ puts "==> Finished in #{result.duration} seconds"
+ puts
end
puts
@@ -36,17 +58,20 @@ puts '==================================================='
puts
puts
-if failed_tasks.empty?
+if static_analysis.all_good?
puts 'All static analyses passed successfully.'
+elsif static_analysis.all_status_zero?
+ puts 'All static analyses passed successfully, but we have warnings:'
+ puts
+
+ emit_warnings(static_analysis)
+
+ exit 2
else
puts 'Some static analyses failed:'
- failed_tasks.each do |failed_task, output|
- puts
- puts "**** #{failed_task} failed with the following error:"
- puts
- puts output
- end
+ emit_warnings(static_analysis)
+ emit_errors(static_analysis)
exit 1
end