From d6a60390b4ce8ea3bd9a995ef54089b3bcf2ed26 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Sat, 10 Aug 2019 18:41:31 +0200 Subject: added a manage-fail-reasons to improve failure detection --- bin/manage-fail-reasons | 68 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100755 bin/manage-fail-reasons (limited to 'bin/manage-fail-reasons') diff --git a/bin/manage-fail-reasons b/bin/manage-fail-reasons new file mode 100755 index 0000000..bc7c5bc --- /dev/null +++ b/bin/manage-fail-reasons @@ -0,0 +1,68 @@ +#!/bin/sh + +# shellcheck source=../lib/load-configuration +. "${0%/*}/../lib/load-configuration" + +# shellcheck disable=SC2016 +usage() { + >&2 echo '' + >&2 echo 'manage-fail-reasons $action [parameters]: manage the list of fail reasons' + >&2 echo '' + >&2 echo 'possible actions:' + >&2 echo ' list list installed fail reasons' + >&2 echo ' check check a build log for fail reasons' + exit 1 +} + +if [ $# -eq 0 ]; then + usage +fi + +case "$1" in + 'list') + # shellcheck disable=SC2016 + fail_reason_identifiers=$( + { + printf 'SELECT `fail_reasons`.`id`,`fail_reasons`.`severity`,replace(to_base64(`fail_reasons`.`identifier`),"\\n","")' + printf ' FROM `fail_reasons` ORDER BY `fail_reasons`.`severity` ASC, `fail_reasons`.id ASC' + } | \ + mysql_run_query + ) + printf '%s\n' "${fail_reason_identifiers}" | \ + while read -r reason_id severity identifier; do + ident=$(printf '%s' "${identifier}" | base64 -d -) + printf "%02s %03s %s\n" "$reason_id" "$severity" "$ident" + done + ;; + 'check') + shift + filelog="$1" + if [ $# -ne 1 ]; then + >&2 printf '"check" expects 1 parameter (a path to a build log), %s were given\n' "$#" + usage + fi + fail_reason_identifiers=$( + { + printf 'SELECT id,severity,replace(to_base64(`fail_reasons`.`identifier`),"\\n","")' + printf ' FROM `fail_reasons` ORDER BY `fail_reasons`.`severity` ASC, `fail_reasons`.id ASC' + } | \ + mysql_run_query + ) + printf '%s\n' "${fail_reason_identifiers}" | \ + while read -r id severity identifier; do + if zgrep -qx "\s*$( + printf '%s' "${identifier}" | \ + base64 -d + )\s*" \ + "$filelog"; then + echo 'match' + ident=$(printf '%s' "${identifier}" | base64 -d -) + printf "$id ($ident) matches with severity $severity\n" + fi + done + ;; + *) + >&2 printf 'unknown action "%s"\n' "$1" + usage + ;; +esac -- cgit v1.2.3