Skip to content

Commit 9e686e7

Browse files
committed
upload-to-squad.sh: add support to upload archives to SQUAD
to replace the uploading to archive.vlo Signed-off-by: Yongqin Liu <yongqin.liu@linaro.org>
1 parent d761dae commit 9e686e7

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

automated/utils/upload-to-squad.sh

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/bin/sh
2+
3+
ATTACHMENT=""
4+
ARTIFACTORIAL_URL=""
5+
CURL_VERBOSE_FLAG=""
6+
FAILURE_RETURN_VALUE=0
7+
8+
usage() {
9+
echo "Usage: $0 [-a <attachment>] [-u <artifactorial_url>] [-t <artifactorial_token>] [-v] [-r]" 1>&2
10+
echo " -a attachment Path to the file to upload" 1>&2
11+
echo " -u squad_url SQUAD_URL where the attachment will be uploaded to" 1>&2
12+
echo " This script will try to fetch the SQUAD_ARCHIVE_SUBMIT_TOKEN" 1>&2
13+
echo " token from (lava_test_dir)/secrets or environments for the upload." 1>&2
14+
echo " -v Pass -v (verbose) flag to curl for debugging." 1>&2
15+
echo " -r Report failure. If the upload fails and this flag is set, the script will exit" 1>&2
16+
echo " with return value 1. If the upload is skipped (no URL or no token found)," 1>&2
17+
echo " this script will still return 0." 1>&2
18+
exit 1
19+
}
20+
21+
while getopts ":a:u:t:vr" opt; do
22+
case "${opt}" in
23+
a) ATTACHMENT="${OPTARG}" ;;
24+
u) ARTIFACTORIAL_URL="${OPTARG}" ;;
25+
v) CURL_VERBOSE_FLAG="-v" ;;
26+
r) FAILURE_RETURN_VALUE=1 ;;
27+
*) usage ;;
28+
esac
29+
done
30+
31+
if [ -z "${ARTIFACTORIAL_URL}" ]; then
32+
echo "test-attachment skip"
33+
command -v lava-test-case > /dev/null 2>&1 && lava-test-case "test-attachment" --result "skip"
34+
exit 0
35+
fi
36+
37+
if command -v lava-test-reference > /dev/null 2>&1; then
38+
# The 'ARTIFACTORIAL_TOKEN' needs to be defined in 'secrects' dictionary in job
39+
# definition file, it will be used.
40+
lava_test_dir="$(find /lava-* -maxdepth 0 -type d | grep -E '^/lava-[0-9]+' 2>/dev/null | sort | tail -1)"
41+
if test -f "${lava_test_dir}/secrets"; then
42+
# shellcheck disable=SC1090
43+
. "${lava_test_dir}/secrets"
44+
fi
45+
46+
if [ -z "${SQUAD_ARCHIVE_SUBMIT_TOKEN}" ]; then
47+
echo "WARNING: SQUAD_ARCHIVE_SUBMIT_TOKEN is empty! File uploading skipped."
48+
echo "test-attachment skip"
49+
command -v lava-test-case > /dev/null 2>&1 && lava-test-case "test-attachment" --result "skip"
50+
exit 0
51+
else
52+
# return is the squad testrun id
53+
return=$(curl ${CURL_VERBOSE_FLAG} --header "Auth-Token: ${SQUAD_ARCHIVE_SUBMIT_TOKEN}" --form "attachment=@${ATTACHMENT}" "${ARTIFACTORIAL_URL}")
54+
fi
55+
56+
attachmentBasename="$(basename "${ATTACHMENT}")"
57+
if echo "${return}" | grep -E "^[0-9]+$"; then
58+
url_uploaded="https://qa-reports.linaro.org/api/testruns/${return}/attachments/?filename=${attachmentBasename}"
59+
lava-test-reference "test-attachment" --result "pass" --reference "${url_uploaded}"
60+
else
61+
echo "test-attachment fail"
62+
echo "Expected one SQUAD testrun id returend, but curl returned \"${return}\"."
63+
command -v lava-test-case > /dev/null 2>&1 && lava-test-case "test-attachment" --result "fail"
64+
exit "${FAILURE_RETURN_VALUE}"
65+
fi
66+
else
67+
echo "test-attachment skip"
68+
command -v lava-test-case > /dev/null 2>&1 && lava-test-case "test-attachment" --result "skip"
69+
fi

0 commit comments

Comments
 (0)