-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.sh
108 lines (97 loc) · 2.6 KB
/
run.sh
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/bin/bash
# "pipeline" or "local"
run_on=$1
# name of test script
testcase=$2
# notification config "teams" or "discord"
notification=$3
# discord notification token
discord_token=$4
discord_webhookid=$5
date=$(date "+%Y%m%d_%H%M%S")
run_counter=0
function send_notif () {
if [ $run_counter != 1 ]
then
start_time=$(date "+%d %h %Y, %H:%M:%S")
title="Testing Start"
message="Running $testcase on $start_time"
cd /app/go/bin
./shoutrrr send --url "discord://$discord_token@$discord_webhookid" --title "$title" --message "$message"
else
end_time=$(date "+%d %h %Y, %H:%M:%S")
title="Testing Completed"
message="Test run ($testcase) is completed on $end_time"
cd /app/go/bin
./shoutrrr send --url "discord://$discord_token@$discord_webhookid" --title "$title" --message "$message"
fi
}
function help () {
echo "format: ./run.sh [local / pipeline] [test script] [teams / discord] [token] [webhookid]"
echo " "
echo "sample:"
echo "local -> ./run.sh local test.js"
echo "pipeline -> ./run.sh pipeline test.js discord 12345 67890"
}
function check_local () {
if [ ! -z "$testcase" ] && [ -z "$notification" ] && [ -z "$discord_token" ] && [ -z "$discord_webhookid" ]
then
result=0
else
result=1
fi
}
function check_pipeline () {
if [ ! -z "$testcase" ] && [ ! -z "$notification" ] && [ ! -z "$discord_token" ] && [ ! -z "$discord_webhookid" ]
then
result=0
fi
if [ -z "$testcase" ]
then
result=1
fi
if [ -z "$notification" ]
then
result=1
fi
if [ -z "$discord_token" ]
then
result=1
fi
if [ -z "$discord_webhookid" ]
then
result=1
fi
}
function run_k6 () {
if [ "$run_on" == "local" ]
then
check_local
if [ $result -eq 0 ]
then
cd /app
k6 run $testcase -c ./config.json --log-output file=reports/k6_$date.log --log-format json --summary-export ./reports/report_$date.json
else
echo "invalid command"
help
fi
elif [ "$run_on" == "pipeline" ]
then
check_pipeline
if [ $result -eq 0 ]
then
send_notif
cd /app
k6 run $testcase -c ./config.json --log-output file=reports/k6_$date.log --log-format json --summary-export ./reports/report_$date.json -q
run_counter=1
send_notif
else
echo "invalid command"
help
fi
else
echo "invalid command"
help
fi
}
run_k6