Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion scripts/ci/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1299,6 +1299,39 @@ __EOM__
slack_mention="_unable to resolve Slack user for GitHub login ${author_login}_"
fi

info "Converting junit failures to slack attachments"

local slack_attachments='
[
{
"color": "#bb2124",
"blocks": [
{
"type": "section",
"text": {
"type": "plain_text",
"text": "Could not parse junit files. Check build logs for more information.
}
}
]
}
]
'
if [[ -n "${ARTIFACT_DIR}" ]]; then
if ! command -v junit-parse >/dev/null 2>&1; then
get_junit_parse_cli || true
fi
if command -v junit-parse >/dev/null 2>&1; then
local junit_file_names
junit_file_names=( "$(find "${ARTIFACT_DIR}" -type f -name '*.xml' -print0 | xargs -0)" ) || true
local check_slack_attachments
check_slack_attachments=$(junit-parse "${junit_file_names[@]}") || exitstatus="$?"
if [[ "$exitstatus" == "0" ]]; then
slack_attachments="$check_slack_attachments"
fi
fi
fi

# shellcheck disable=SC2016
local body='
{
Expand Down Expand Up @@ -1330,7 +1363,8 @@ __EOM__
{
"type": "divider"
}
]
],
"attachments": $slack_attachments
}
'

Expand All @@ -1342,6 +1376,7 @@ __EOM__
--arg author_name "$author_name" \
--arg slack_mention "$slack_mention" \
--arg log_url "$log_url" \
--argjson slack_attachments "$slack_attachments" \
"$body")"
echo -e "About to post:\n$payload"

Expand Down Expand Up @@ -1433,6 +1468,10 @@ EOT
hub-comment -type build -template-file "$tmpfile"
}

get_junit_parse_cli() {
go install github.com/stackrox/junit-parse
}

if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
if [[ "$#" -lt 1 ]]; then
die "When invoked at the command line a method is required."
Expand Down