Skip to content

Commit

Permalink
test: improve GA annotations (again).
Browse files Browse the repository at this point in the history
  • Loading branch information
Adirelle committed May 11, 2024
1 parent 1434049 commit e0663db
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 38 deletions.
6 changes: 3 additions & 3 deletions e2e/assert.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
source "$TEST_ROOT/style.sh"

fail() {
err "$*"
title="assertion failed" err "$*"
exit 1
}

Expand Down Expand Up @@ -85,14 +85,14 @@ assert_matches() {

skip_slow_test() {
if [[ -z ${TEST_ALL:-} ]]; then
warn "skipping slow tests"
title="skipped test" warn "slow tests are disabled"
exit 0
fi
}

require_cmd() {
if ! type -p "$1" >/dev/null; then
warn "skipping test: cannot find ""$1"" in PATH ($PATH)"
title="skipped test" warn "the required command '$1' was not found in the PATH ($PATH)"
exit 0
fi
}
2 changes: 1 addition & 1 deletion e2e/run_test
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ run_test() {
remove_isolated_env
STATUS_MSG=":white_check_mark:"
else
err "E2E Test Failed (code: $status)"
title="E2E test failed" err "Test exited with status code $status"
STATUS_MSG=":x:"
fi
if [[ -n "${GITHUB_STEP_SUMMARY:-}" ]]; then
Expand Down
61 changes: 27 additions & 34 deletions e2e/style.sh
Original file line number Diff line number Diff line change
@@ -1,49 +1,42 @@
# shellcheck shell=bash

if [[ -n ${GITHUB_ACTION:-} ]]; then
# Use special GA formatting
# Use ANSI green color for the "ok" message so groups with no errors are kept collapsed
_STYLE_OK=$'\e[92m'
_STYLE_ERR="::error${MISE_TEST_SCRIPT:+ file=${MISE_TEST_SCRIPT#"$ROOT"/}}::"
_STYLE_WARN="::warning${MISE_TEST_SCRIPT:+ file=${MISE_TEST_SCRIPT#"$ROOT"/}}::"
_STYLE_RESET=$'\e[0m'
_GROUP_START='::group::'
_GROUP_END='::endgroup::'
# Output Github action annotations
annotate() {
: "${file:=${TEST_SCRIPT:-}}"
: "${title:=}"
echo "::${type:?}${file:+ file=${file}}${title:+ title=${title}}::$*" >&2
}
err() { type=error annotate "$*"; }
warn() { type=warning annotate "$*"; }
start_group() { echo "::group::$*" >&2; }
end_group() { echo ::endgroup:: >&2; }

# Yet use ANSI green color for the "ok" message
ok() { echo $'\e[92m'"$*"$'\e[0m' >&2; }

elif [[ -t 2 ]]; then
# Use ANSI coloring in terminal
_STYLE_OK=$'\e[92m' # green
_STYLE_ERR=$'\e[91m' # red
_STYLE_WARN=$'\e[93m' # yellow
_STYLE_RESET=$'\e[0m' # full reset
_GROUP_START=$'\e[1m>>> ' # bold
_GROUP_END=
ok() { echo $'\e[92m'"$*"$'\e[0m' >&2; }
err() { echo $'\e[91m'"$*"$'\e[0m' >&2; }
warn() { echo $'\e[93m'"$*"$'\e[0m' >&2; }
start_group() { echo $'\e[1m'">>> $*"$'\e[0m' >&2; }
end_group() { echo >&2; }

else
# No styling
_STYLE_OK='SUCCESS: '
_STYLE_ERR='ERROR: '
_STYLE_WARN='NOTICE: '
_STYLE_RESET=
_GROUP_START='>>> '
_GROUP_END=
ok() { echo "SUCCESS: $*" >&2; }
err() { echo "ERROR: $*" >&2; }
warn() { echo "wARNING: $*" >&2; }
start_group() { echo ">>> $*" >&2; }
end_group() { echo >&2; }
fi

ok() {
echo "${_STYLE_OK}$*${_STYLE_RESET}" >&2
}

err() {
echo "${_STYLE_ERR}$*${_STYLE_RESET}" >&2
}

warn() {
echo "${_STYLE_WARN}$*${_STYLE_RESET}" >&2
}

as_group() {
local status=0
echo "${_GROUP_START}$1${_STYLE_RESET}" >&2
start_group "$1"
shift
"$*" || status=$?
echo "${_GROUP_END}${_STYLE_RESET}" >&2
end_group
return "$status"
}

0 comments on commit e0663db

Please sign in to comment.