From 54ca8d0d6c4744be53c7044b9bbfa05acc358090 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Tue, 23 Jan 2018 20:12:51 +0800 Subject: Fail static-analysis if there's output to stderr TODO: fix offenders --- scripts/static-analysis | 57 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 16 deletions(-) (limited to 'scripts/static-analysis') 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 -- cgit v1.2.1 From df2c47b9ffb65542bb559262758ad952b7ea48a2 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Tue, 23 Jan 2018 22:45:14 +0800 Subject: Don't print stdout in case we're just printing warnings Otherwise it could be confusing --- scripts/static-analysis | 1 - 1 file changed, 1 deletion(-) (limited to 'scripts/static-analysis') diff --git a/scripts/static-analysis b/scripts/static-analysis index 392dc784945..8986ad825e1 100755 --- a/scripts/static-analysis +++ b/scripts/static-analysis @@ -9,7 +9,6 @@ def emit_warnings(static_analysis) puts puts "**** #{result.cmd.join(' ')} had the following warnings:" puts - puts result.stdout puts result.stderr puts end -- cgit v1.2.1 From a2618310aea7d58e52d2d29ec4871e27717eb0f0 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Wed, 24 Jan 2018 21:05:01 +0800 Subject: Use Process::Status rather than an integer However keep backward compatibility --- scripts/static-analysis | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'scripts/static-analysis') diff --git a/scripts/static-analysis b/scripts/static-analysis index 8986ad825e1..b3895292ab4 100755 --- a/scripts/static-analysis +++ b/scripts/static-analysis @@ -57,9 +57,9 @@ puts '===================================================' puts puts -if static_analysis.all_good? +if static_analysis.all_success_and_clean? puts 'All static analyses passed successfully.' -elsif static_analysis.all_status_zero? +elsif static_analysis.all_success? puts 'All static analyses passed successfully, but we have warnings:' puts -- cgit v1.2.1 From 33ed96229b09c062ec9221b192cf7dd0c214b7a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Coutable?= Date: Tue, 30 Jan 2018 11:08:22 +0100 Subject: Don't run scripts/lint-changelog-yaml in scripts/static-analysis but only in the 'docs lint' job MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rémy Coutable --- scripts/static-analysis | 1 - 1 file changed, 1 deletion(-) (limited to 'scripts/static-analysis') diff --git a/scripts/static-analysis b/scripts/static-analysis index b3895292ab4..bdb88f3cb57 100755 --- a/scripts/static-analysis +++ b/scripts/static-analysis @@ -35,7 +35,6 @@ tasks = [ %w[bundle exec rubocop --parallel], %w[bundle exec rake gettext:lint], %w[bundle exec rake lint:static_verification], - %w[scripts/lint-changelog-yaml], %w[scripts/lint-conflicts.sh], %w[scripts/lint-rugged] ] -- cgit v1.2.1