-
Notifications
You must be signed in to change notification settings - Fork 6
/
test-run
executable file
·57 lines (51 loc) · 2.04 KB
/
test-run
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash
# Run a test in the current directory.
# Execute ./runtest.sh and store the result in ./test-result.txt
# If the test fails for an unknown reason then schedule a rerun.
# Run a test and create ./test-result.txt
set -e
source ${CI}/config
uuid=$(basename $(pwd))
status="none"
# This function will be called at exit to record what happened.
record_result () {
(case $status in # Interpret test script exit code
100) echo "PASSED: Test ran successfully (100)" ;;
101) echo "FAILED: Test failed with cause (101)" ;;
102) echo "SKIPPED: Test intentionally skipped (102)" ;;
103) echo "REVIEW: Test result needs manual review (103)";;
*) echo "HAZARD: Test exited with unrecognized status ($status)";;
esac) > test-result.txt
echo >> test-result.txt
echo "Log: ${CI_URL?}/tests/$(basename $(pwd))" >> test-result.txt
echo >> test-result.txt
[ -f review-comment ] && cat review-comment >> test-result.txt
date=$(date "+%F %T")
echo "${date} ${uuid} DONE $(head -1 test-result.txt)" >> ${CI?}/log/activity.log
# Consider retriggering the same event in case of unexpected error
if head -1 test-result.txt | grep -q HAZARD; then
retries=0
[ -f previous.log ] && retries=$(grep -c . previous.log)
if [ $retries -lt 5 ]; then
newuuid=$(uuidgen)
mkdir ../${newuuid}
cp event.json ../${newuuid}/
[ -f previous.log ] && cp previous.log ../${newuuid}/
echo ${uuid} >> ../${newuuid}/previous.log
echo "${date} ${uuid} RETRY #${retries} ${newuuid}" >> ${CI?}/log/activity.log
else
echo "${date} ${uuid} NOMORE $retries retries" >> ${CI?}/log/activity.log
fi
fi
exit 0
}
trap record_result EXIT
date=$(date "+%F %T")
ref=$(cat event.json | sed -z -e 's/.*"ref": "//' -e 's/".*//')
project=$(cat event.json | sed -z -e 's/.*"project": "//' -e 's/".*//')
echo "${date} ${uuid} TEST ${project} ${ref}" >> ${CI?}/log/activity.log
[ -f event.json ]
( flock -xn 9 || exit 1 ) 9>build.lock
set +e
./runtest.sh
status=$?