Skip to content

Commit a21beff

Browse files
[tests-only][full-ci] send build notification to matrix channel (#12173)
send build notification to matrix channel (ownCloud Infinite Scale Alerts)
1 parent be7e3fb commit a21beff

File tree

2 files changed

+54
-43
lines changed

2 files changed

+54
-43
lines changed

.drone.star

Lines changed: 13 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ OC_CI_SQUISH = "owncloudci/squish:fedora-39-8.0.0-qt67x-linux64"
2727

2828
PLUGINS_GIT_ACTION = "plugins/git-action:1"
2929
PLUGINS_S3 = "plugins/s3:1.4.0"
30-
PLUGINS_SLACK = "plugins/slack"
3130
TOOLHIPPIE_CALENS = "toolhippie/calens:0.4.0"
3231

3332
# npm packages to install
@@ -43,7 +42,6 @@ secrets = {
4342
"GITHUB_TOKEN": "github_token", # not available for PRs
4443
"AWS_ACCESS_KEY_ID": "cache_public_s3_access_key",
4544
"AWS_SECRET_ACCESS_KEY": "cache_public_s3_secret_key",
46-
"ROCKETCHAT_WEBHOOK": "rocketchat_talk_webhook",
4745
}
4846

4947
dir = {
@@ -56,12 +54,6 @@ dir = {
5654
"pythonModules64": "/usr/local/lib64/python3.10/site-packages",
5755
}
5856

59-
notify_channels = {
60-
"desktop-ci": {
61-
"type": "channel",
62-
},
63-
}
64-
6557
branch_ref = [
6658
"refs/heads/master",
6759
"refs/heads/5**",
@@ -414,35 +406,20 @@ def changelog(ctx):
414406
}]
415407

416408
def notification():
417-
steps = [{
418-
"name": "create-template",
419-
"image": OC_CI_ALPINE,
420-
"environment": {
421-
"CACHE_ENDPOINT": S3_PUBLIC_CACHE_SERVER,
422-
"CACHE_BUCKET": S3_PUBLIC_CACHE_BUCKET,
423-
},
424-
"commands": [
425-
"bash %s/drone/notification_template.sh %s" % (dir["guiTest"], dir["base"]),
426-
],
427-
}]
428-
429-
for channel, params in notify_channels.items():
430-
settings = {
431-
"webhook": from_secret("ROCKETCHAT_WEBHOOK"),
432-
"template": "file:%s/template.md" % dir["base"],
433-
}
434-
if params["type"] == "user":
435-
settings["recipient"] = channel
436-
else:
437-
settings["channel"] = channel
438-
439-
steps.append(
440-
{
441-
"name": "notification-%s" % channel,
442-
"image": PLUGINS_SLACK,
443-
"settings": settings,
409+
steps = [
410+
{
411+
"name": "notify-matrix",
412+
"image": OC_CI_ALPINE,
413+
"environment": {
414+
"MATRIX_TOKEN": {
415+
"from_secret": "matrix_token",
416+
},
444417
},
445-
)
418+
"commands": [
419+
"bash %s/drone/notification_template.sh %s" % (dir["guiTest"], dir["base"]),
420+
],
421+
},
422+
]
446423

447424
return [{
448425
"kind": "pipeline",

test/gui/drone/notification_template.sh

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66

77
COMMIT_SHA_SHORT=${DRONE_COMMIT:0:8}
88
SERVERS=("oc10" "ocis")
9-
BUILD_STATUS=":white_check_mark:**Success**"
9+
BUILD_STATUS="Success"
1010
TEST_LOGS=""
1111
BRANCH_NAME="${DRONE_BRANCH}"
12+
ROOMID="!rnWsCVUmDHDJbiSPMM:matrix.org"
1213

1314
if [ "${DRONE_BUILD_STATUS}" == "failure" ]; then
14-
BUILD_STATUS=":x:**Failure**"
15+
BUILD_STATUS="❌️ Failure"
1516
fi
1617

1718
for server in "${SERVERS[@]}"; do
@@ -24,7 +25,7 @@ for server in "${SERVERS[@]}"; do
2425
GUI_STATUS_CODE=$($CURL "$GUI_LOG")
2526

2627
if [[ "$GUI_STATUS_CODE" == "200" ]]; then
27-
LOGS+=": [Squish Report]($GUI_LOG)"
28+
LOGS+=': <a href='"${GUI_LOG}"'>Squish Report</a>'
2829
fi
2930

3031
if [ "${DRONE_BUILD_STATUS}" == "failure" ]; then
@@ -35,15 +36,15 @@ for server in "${SERVERS[@]}"; do
3536
STACKTRACE_STATUS_CODE=$($CURL "$STACKTRACE")
3637

3738
if [[ "$SERVER_STATUS_CODE" == "200" ]]; then
38-
LOGS+="\n> [Server log]($SERVER_LOG) " # 2 spaces at the end act as line-break
39+
LOGS+='<br> <a href='"${SERVER_LOG}"'>Server Log</a> <br>'
3940
fi
4041
if [[ "$STACKTRACE_STATUS_CODE" == "200" ]]; then
41-
LOGS+="\n> [Stacktrace]($STACKTRACE)"
42+
LOGS+='<br> <a href='"${STACKTRACE}"'>Stacktrace</a>'
4243
fi
4344
fi
4445

4546
if [[ -n "${LOGS}" ]]; then
46-
LOGS="\n${server}${LOGS}"
47+
LOGS="${server}${LOGS}"
4748
TEST_LOGS+="${LOGS}"
4849
fi
4950
done
@@ -52,4 +53,37 @@ if [ "${DRONE_BUILD_EVENT}" == "tag" ]; then
5253
BRANCH_NAME="Tag: \`${DRONE_TAG}\`"
5354
fi
5455

55-
echo -e "$BUILD_STATUS [${DRONE_REPO}#${COMMIT_SHA_SHORT}](${DRONE_BUILD_LINK}) (${BRANCH_NAME}) by **${DRONE_COMMIT_AUTHOR}** $TEST_LOGS" >"$1"/template.md
56+
# helper functions
57+
log_error() {
58+
echo -e "\e[31m$1\e[0m"
59+
}
60+
61+
log_info() {
62+
echo -e "\e[37m$1\e[0m"
63+
}
64+
65+
log_success() {
66+
echo -e "\e[32m$1\e[0m"
67+
}
68+
69+
message_html='<b>'$BUILD_STATUS'</b> <a href="'${DRONE_BUILD_LINK}'">'${DRONE_REPO}'#'$COMMIT_SHA_SHORT'</a> ('${BRANCH_NAME}') by <b>'${DRONE_COMMIT_AUTHOR}'</b> <br> <b>'"${TEST_LOGS}"'</b>'
70+
message_html=$(echo "$message_html" | sed 's/\\/\\\\/g' | sed 's/"/\\"/g')
71+
72+
log_info "Sending report to the element chat..."
73+
74+
response=$(curl -s -o /dev/null -X PUT -w "%{http_code}" 'https://matrix.org/_matrix/client/v3/rooms/'$ROOMID'/send/m.room.message/'$(date +%s) \
75+
-H "Authorization: Bearer "$MATRIX_TOKEN \
76+
-H 'Content-Type: application/json' \
77+
-d '{
78+
"msgtype": "m.text",
79+
"body": "'"$message_html"'",
80+
"format": "org.matrix.custom.html",
81+
"formatted_body": "'"$message_html"'"
82+
}')
83+
84+
if [[ "$response" != "200" ]]; then
85+
log_error "❌ Error: Failed to send notification to element. Expected status code 200, but got $response."
86+
exit 1
87+
fi
88+
89+
log_success "✅ Notification successfully sent to Element chat (ownCloud Infinite Scale Alerts)"

0 commit comments

Comments
 (0)