From aaf158bcb57386a043d8cb7dc491a2f306a4ac13 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Thu, 22 Dec 2022 15:09:14 +0000 Subject: Add latest changes from gitlab-org/gitlab@master --- scripts/allowed_warnings.txt | 11 +++++++++++ scripts/static-analysis | 28 ++++++++-------------------- scripts/utils.sh | 31 +++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 20 deletions(-) create mode 100644 scripts/allowed_warnings.txt (limited to 'scripts') diff --git a/scripts/allowed_warnings.txt b/scripts/allowed_warnings.txt new file mode 100644 index 00000000000..8162f45f760 --- /dev/null +++ b/scripts/allowed_warnings.txt @@ -0,0 +1,11 @@ +# List of ignored warnings used by `fail_on_warnings` in `scripts/utils.sh`. +# Each line represents a match used by `grep --invert-match --file`. +# Comments and empty lines are ignored. + +# 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` + +# https://github.com/mime-types/mime-types-data/pull/50#issuecomment-1060908930 +Type application/netcdf is already registered as a variant of application/netcdf. diff --git a/scripts/static-analysis b/scripts/static-analysis index 9a0057d8f4d..0d03dd42c73 100755 --- a/scripts/static-analysis +++ b/scripts/static-analysis @@ -7,14 +7,7 @@ require_relative '../lib/gitlab/popen' require_relative '../lib/gitlab/popen/runner' class StaticAnalysis - 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`", - # https://github.com/mime-types/mime-types-data/pull/50#issuecomment-1060908930 - "Type application/netcdf is already registered as a variant of application/netcdf." - ].freeze + # `ALLOWED_WARNINGS` moved to scripts/allowed_warnings.txt Task = Struct.new(:command, :duration) do def cmd @@ -94,12 +87,12 @@ class StaticAnalysis if static_analysis.all_success_and_clean? puts 'All static analyses passed successfully.' elsif static_analysis.all_success? - puts 'All static analyses passed successfully, but we have warnings:' + puts 'All static analyses passed successfully with warnings.' puts emit_warnings(static_analysis) - exit 2 if warning_count(static_analysis).nonzero? + # We used to exit 2 on warnings but `fail_on_warnings` takes care of it now. else puts 'Some static analyses failed:' @@ -112,11 +105,11 @@ class StaticAnalysis def emit_warnings(static_analysis) static_analysis.warned_results.each do |result| - puts - puts "**** #{result.cmd.join(' ')} had the following warning(s):" - puts - puts result.stderr - puts + warn + warn "**** #{result.cmd.join(' ')} had the following warning(s):" + warn + warn result.stderr + warn end end @@ -131,11 +124,6 @@ class StaticAnalysis end end - def warning_count(static_analysis) - static_analysis.warned_results - .count { |result| !ALLOWED_WARNINGS.include?(result.stderr.strip) } # rubocop:disable Rails/NegateInclude - end - def tasks_to_run(node_total) total_time = TASKS_WITH_DURATIONS_SECONDS.sum(&:duration).to_f ideal_time_per_node = total_time / node_total diff --git a/scripts/utils.sh b/scripts/utils.sh index c9e4a6a487d..2bbe7e10de8 100644 --- a/scripts/utils.sh +++ b/scripts/utils.sh @@ -107,6 +107,37 @@ function install_junit_merge_gem() { run_timed_command "gem install junit_merge --no-document --version 0.1.2" } +function fail_on_warnings() { + local cmd="$*" + local warning_file + warning_file="$(mktemp)" + + local allowed_warning_file + allowed_warning_file="$(mktemp)" + + eval "$cmd 2>$warning_file" + local ret=$? + + # Filter out comments and empty lines from allowed warnings file. + grep --invert-match --extended-regexp "^#|^$" scripts/allowed_warnings.txt > "$allowed_warning_file" + + local warnings + # Filter out allowed warnings from stderr. + # Turn grep errors into warnings so we fail later. + warnings=$(grep --invert-match --file "$allowed_warning_file" "$warning_file" 2>&1 || true) + + rm -f "$warning_file" "$allowed_warning_file" + + if [ "$warnings" != "" ] + then + echoerr "There were warnings:" + echoerr "$warnings" + return 1 + fi + + return $ret +} + function run_timed_command() { local cmd="${1}" local metric_name="${2:-no}" -- cgit v1.2.1