-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
82 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -141,11 +141,10 @@ function calcRetcode() { | |
# Print error message. | ||
# Parameters: $* - error message to be displayed | ||
function error() { | ||
gum_style \ | ||
--foreground '#D00' \ | ||
gum_banner \ | ||
--color '#D00' \ | ||
--padding '1 3' \ | ||
--border double \ | ||
--border-foreground '#D00' \ | ||
"ERROR: $*" | ||
} | ||
|
||
|
@@ -158,37 +157,22 @@ function abort() { | |
exit "$abort_retcode" | ||
} | ||
|
||
# Display a box banner. | ||
# Parameters: $1 - character to use for the box. | ||
# $2 - banner message. | ||
# Deprecated: Use `gum_style` instead. | ||
function make_banner() { | ||
local msg="$1$1$1$1 $2 $1$1$1$1" | ||
local border="${msg//[^$1]/$1}" | ||
echo -e "${border}\n${msg}\n${border}" | ||
# TODO(adrcunha): Remove once logs have timestamps on Prow | ||
# For details, see https://github.com/kubernetes/test-infra/issues/10100 | ||
if (( IS_PROW )); then | ||
echo -e "$1$1$1$1 $(TZ='UTC' date --rfc-3339=ns)\n${border}" | ||
fi | ||
} | ||
|
||
# Simple header for logging purposes. | ||
function header() { | ||
local upper | ||
upper="$(echo "$*" | tr '[:lower:]' '[:upper:]')" | ||
gum_style \ | ||
--padding '1 3' \ | ||
gum_banner \ | ||
--border double \ | ||
--color 44 \ | ||
--padding '1 3' \ | ||
"$upper" | ||
} | ||
|
||
# Simple subheader for logging purposes. | ||
function subheader() { | ||
gum_style \ | ||
--padding '1 3' \ | ||
--border rounded \ | ||
"$*" | ||
gum_banner \ | ||
--color 45 \ | ||
"$*" | ||
} | ||
|
||
# Simple log step for logging purposes. | ||
|
@@ -203,22 +187,84 @@ function log() { | |
|
||
# Simple warning banner for logging purposes. | ||
function warning() { | ||
gum_style \ | ||
--foreground '#DD0' \ | ||
gum_banner \ | ||
--color '#DD0' \ | ||
--padding '1 3' \ | ||
--border rounded \ | ||
--border-foreground '#DD0' \ | ||
"WARN: $*" | ||
} | ||
|
||
# Display a box banner. | ||
# Parameters: $1 - character to use for the box. | ||
# $2 - banner message. | ||
# Deprecated: Use `gum_banner` instead. | ||
function make_banner() { | ||
local msg="$1$1$1$1 $2 $1$1$1$1" | ||
local border="${msg//[^$1]/$1}" | ||
echo -e "${border}\n${msg}\n${border}" | ||
# TODO(adrcunha): Remove once logs have timestamps on Prow | ||
# For details, see https://github.com/kubernetes/test-infra/issues/10100 | ||
if (( IS_PROW )); then | ||
echo -e "$1$1$1$1 $(TZ='UTC' date --rfc-3339=ns)\n${border}" | ||
fi | ||
} | ||
|
||
# Display a fancy box banner. | ||
# Parameters: | ||
# [--border <type>] - a gum border type for the box, defaults to 'rounded' | ||
# [--color <color>] - a gum color for the box, defaults to '0'' | ||
# [--padding <padding>] - a gum padding for the box, defaults to '0 1' | ||
# $* - banner message. | ||
function gum_banner() { | ||
local border='rounded' | ||
local color='0' | ||
local padding='0 1' | ||
while [[ $# -gt 0 ]]; do | ||
case "$1" in | ||
--border) | ||
border="$2" | ||
shift 2 | ||
;; | ||
--color) | ||
color="$2" | ||
shift 2 | ||
;; | ||
--padding) | ||
padding="$2" | ||
shift 2 | ||
;; | ||
*) | ||
break | ||
;; | ||
esac | ||
done | ||
local args=( | ||
--align center | ||
--border "$border" | ||
--foreground "$color" | ||
--border-foreground "$color" | ||
--padding "$padding" | ||
"$*" | ||
) | ||
# TODO: Remove once logs have timestamps on Prow, details see: | ||
# https://github.com/kubernetes/test-infra/issues/10100 | ||
if (( IS_PROW )); then | ||
local dt | ||
# RFC3339Nano format with 3 digits of ns without timezone offset | ||
dt="$(TZ='UTC' date --rfc-3339=ns | sed -E 's/\.([0-9]{3})[0-9]+.+$/.\1/')" | ||
args+=('' "at $dt") | ||
fi | ||
gum_style "${args[@]}" | ||
} | ||
|
||
# Simple info banner for logging purposes. | ||
function gum_style() { | ||
go_run github.com/charmbracelet/[email protected] style "$@" > /dev/stderr | ||
} | ||
|
||
# Checks whether the given function exists. | ||
function function_exists() { | ||
[[ "$(type -t $1)" == "function" ]] | ||
[[ "$(type -t "$1")" == "function" ]] | ||
} | ||
|
||
# GitHub Actions aware output grouping. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters