Skip to content

Commit f514089

Browse files
chore: +run_and_publish_e2e_tests_to_slack
1 parent f6d0098 commit f514089

File tree

1 file changed

+59
-8
lines changed

1 file changed

+59
-8
lines changed

kash.sh

+59-8
Original file line numberDiff line numberDiff line change
@@ -1729,15 +1729,17 @@ run_e2e_tests () {
17291729
# Expected args:
17301730
# 1. the app root dir
17311731
# 2. the app name
1732-
# 3. the s3 bucket where to upload artefacts (with a rclone remote, like ovh:e2e-test/blabla)
1733-
# 4. the rclone.conf file to use to upload artefacts
1734-
# 5. the file where the upload report will be written (json)
1732+
# 3. the return code of the testing process
1733+
# 4. the s3 bucket where to upload artefacts (with a rclone remote, like ovh:e2e-test/blabla)
1734+
# 5. the rclone.conf file to use to upload artefacts
1735+
# 6. the file where the upload report will be written (json)
17351736
upload_e2e_tests_artefacts() {
17361737
local ROOT_DIR="$1"
17371738
local APP="$2"
1738-
local S3_BUCKET="$3"
1739-
local RCLONE_CONF="$4"
1740-
local UPLOAD_REPORT_FILE="$5"
1739+
local TESTS_RET_CODE="$3"
1740+
local S3_BUCKET="$4"
1741+
local RCLONE_CONF="$5"
1742+
local UPLOAD_REPORT_FILE="$6"
17411743

17421744
local TIMESTAMP
17431745
TIMESTAMP="$(date +"%d-%m-%Y")"
@@ -1791,7 +1793,7 @@ upload_e2e_tests_artefacts() {
17911793
local LOGS_LINK
17921794
LOGS_LINK="$(rclone --config "$RCLONE_CONF" link "$REMOTE_DIR/logs.txt")"
17931795

1794-
printf '{ "app": "%s", "timestamp": "%s", "artefacts": "%s", "logs": "%s", "num_failed": "%d", "failed": [' "$APP" "$TIMESTAMP" "$ARTEFACTS_LINK" "$LOGS_LINK" "${#FAILED_TESTS[@]}" > "$UPLOAD_REPORT_FILE"
1796+
printf '{ "app": "%s", "timestamp": "%s", "ret_code": "%d", "artefacts": "%s", "logs": "%s", "num_failed": "%d", "failed": [' "$APP" "$TIMESTAMP" "$TESTS_RET_CODE" "$ARTEFACTS_LINK" "$LOGS_LINK" "${#FAILED_TESTS[@]}" > "$UPLOAD_REPORT_FILE"
17951797

17961798
local COMMA=""
17971799
for TEST_NAME in "${FAILED_TESTS[@]}"; do
@@ -1913,6 +1915,26 @@ push_e2e_tests_report_to_git_repo() {
19131915
rm -fR "$WORK_DIR"
19141916
}
19151917

1918+
# Send the e2e tests report to a slack channel.
1919+
# Expected args:
1920+
# 1. the same upload report file as upload_e2e_tests_artefacts
1921+
# 2. the slack channel webhook
1922+
push_e2e_tests_report_to_slack() {
1923+
local UPLOAD_REPORT_FILE="$1"
1924+
local SLACK_WEBHOOK="$2"
1925+
1926+
local APP
1927+
APP=$(get_json_value "$UPLOAD_REPORT_FILE" "app")
1928+
local TESTS_RET_CODE
1929+
TESTS_RET_CODE=$(get_json_value "$UPLOAD_REPORT_FILE" "ret_code")
1930+
local ARTEFACTS_LINK
1931+
ARTEFACTS_LINK=$(get_json_value "$UPLOAD_REPORT_FILE" "artefacts")
1932+
local LOGS_LINK
1933+
LOGS_LINK=$(get_json_value "$UPLOAD_REPORT_FILE" "logs")
1934+
1935+
slack_e2e_report "$APP" "$TESTS_RET_CODE" "$SLACK_WEBHOOK" "$LOGS_LINK" "$ARTEFACTS_LINK"
1936+
}
1937+
19161938
# Take all steps to run e2e test and push results to a git repository. Binary artefacts
19171939
# are uploaded on an s3 bucket.
19181940
# Expected args:
@@ -1931,6 +1953,7 @@ run_and_publish_e2e_tests_to_git_repo() {
19311953
local REPORTS_BASE="$6"
19321954

19331955
run_e2e_tests "$ROOT_DIR" "$APP"
1956+
local TESTS_RET_CODE="$?"
19341957

19351958
local MD_FLAVOR
19361959
[[ "$REPOSITORY_URL" = *gitlab* ]] && MD_FLAVOR="gitlab"
@@ -1940,7 +1963,7 @@ run_and_publish_e2e_tests_to_git_repo() {
19401963
local MD_REPORT_FILE="$TMP_DIR/e2e.md"
19411964

19421965
upload_e2e_tests_artefacts \
1943-
"$ROOT_DIR" "$APP" \
1966+
"$ROOT_DIR" "$APP" "$TESTS_RET_CODE" \
19441967
"$S3_BUCKET" "$RCLONE_CONF" \
19451968
"$UPLOAD_REPORT_FILE"
19461969
generate_e2e_tests_markdown_report \
@@ -1949,3 +1972,31 @@ run_and_publish_e2e_tests_to_git_repo() {
19491972
"$UPLOAD_REPORT_FILE" "$MD_REPORT_FILE" \
19501973
"$REPOSITORY_URL" "$REPORTS_BASE"
19511974
}
1975+
1976+
# Take all steps to run e2e test and push results to a slack channel. Binary artefacts
1977+
# are uploaded on an s3 bucket.
1978+
# Expected args:
1979+
# 1. the app root dir
1980+
# 2. the app name
1981+
# 3. the s3 bucket where to upload binary artefacts
1982+
# 4. the rclone.conf file to use with rclone
1983+
# 5. the slack channel webhook
1984+
run_and_publish_e2e_tests_to_slack() {
1985+
local ROOT_DIR="$1"
1986+
local APP="$2"
1987+
local S3_BUCKET="$3"
1988+
local RCLONE_CONF="$4"
1989+
local SLACK_WEBHOOK="$5"
1990+
1991+
run_e2e_tests "$ROOT_DIR" "$APP"
1992+
local TESTS_RET_CODE="$?"
1993+
1994+
local UPLOAD_REPORT_FILE="$TMP_DIR/e2e-upload-report.json"
1995+
1996+
upload_e2e_tests_artefacts \
1997+
"$ROOT_DIR" "$APP" "$TESTS_RET_CODE" \
1998+
"$S3_BUCKET" "$RCLONE_CONF" \
1999+
"$UPLOAD_REPORT_FILE"
2000+
push_e2e_tests_report_to_slack \
2001+
"$UPLOAD_REPORT_FILE" "$SLACK_WEBHOOK"
2002+
}

0 commit comments

Comments
 (0)