-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathci_mon
executable file
·231 lines (200 loc) · 7.99 KB
/
ci_mon
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#!/bin/bash
# SPDX-Identifier: gpl-2.0-or-later
# Copyright (C) 2021, Red Hat, Inc.
#
# Generate and send a test-report email
#
# Licensed under the terms of the GNU General Public License as published
# by the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. You may obtain a copy of the
# license at
#
# https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
[ -f "${HOME}/.pwmon-rc" ] && source "${HOME}/.pwmon-rc"
[ -f "${HOME}/.cimon-rc" ] && source "${HOME}/.cimon-rc"
source $(dirname $0)/series_db_lib.sh
disable_dummy=yes
disable_obs=yes
dummy_token="1111"
#default is to 'quit' the sed script
patch_url_regex='q'
# default report strings
RPT_SUCCESS="SUCCESS"
RPT_FAILURE="FAILURE"
RPT_WARNING="WARNING"
if [ '!' "X" = "X$*" ]; then
while [ $# -gt 0 ];
do
if [ "$1" = "--help" ]; then
echo "$0: monitor supported CI systems"
echo ""
echo "Command to generate test report emails from various CI providers"
echo "and generate / send a report email."
echo ""
echo "USAGE:"
echo " $0 [options]"
echo "Options:"
echo " --help This help message"
echo " --pw-instance Patchwork instance"
echo " --from From email address"
echo " --to To email address**"
echo " --dry-run pass --dry-run to git send-email"
echo " --*-token Set a token for various CI monitors"
echo " --disable-* Skips running the provided CI monitor"
echo " --enable-dummy Runs the 'dummy' module"
echo " --patch-url-filter= Applies a regex filter to the patch URL"
echo " --report-success= String to report as success (default: SUCCESS)"
echo " --report-failure= String to report as success (default: FAILURE)"
echo " --report-warning= String to report as success (default: WARNING)"
exit 0
fi
if [ "X" = "X$pw_cli_instance" ]; then
STRTMP=`echo "$1" | sed 's@.*--pw-instance=@@'`
if [ "$STRTMP" != "$1" ]; then
pw_cli_instance=$STRTMP
fi
fi
if [ "X" = "X$from_addr" ]; then
STRTMP=`echo "$1" | sed 's@.*--from=@@'`
if [ "$STRTMP" != "$1" ]; then
from_addr=$STRTMP
fi
fi
if [ "X" = "X$to_addr" ]; then
STRTMP=`echo "$1" | sed 's@.*--to=@@'`
if [ "$STRTMP" != "$1" ]; then
to_addr=$STRTMP
fi
fi
if [ "X" = "X$dry_run" ]; then
STRTMP=`echo "$1" | sed 's@.*--dry-run@@'`
if [ "$STRTMP" != "$1" ]; then
dry_run="--dry-run"
fi
fi
if [ "X" = "X$pw_project" ]; then
STRTMP=`echo "$1" | sed 's@.*--pw-project=@@'`
if [ "$STRTMP" != "$1" ]; then
pw_project=$STRTMP
fi
fi
if echo $1 | grep ".*--patch-url-filter=" >/dev/null 2>/dev/null; then
STRTMP=`echo "$1" | sed 's@.*--patch-url-filter=@@'`
if [ "$STRTMP" != "$1" ]; then
patch_url_regex="$STRTMP"
fi
fi
if echo $1 | grep ".*--[a-zA-Z]*-token=" >/dev/null 2>/dev/null; then
token_name=`echo $1 | sed -e 's@-token=.*@@' -e 's@^--@@'`
token_name="$token_name"_token
token_val=`echo $1 | sed -e 's@--[a-zA-Z]*-token=@@'`
eval $token_name=\$token_val
fi
if echo $1 | grep ".*--disable-[a-zA-Z]*" >/dev/null 2>/dev/null; then
disable_name=$(echo $1 | sed -e 's@.*--disable-@@')
disable_name=disable_${disable_name}
disable_val=yes
eval $disable_name=\$disable_val
fi
if echo $1 | grep ".*--enable-dummy" >/dev/null 2>/dev/null; then
disable_dummy=no
fi
if echo "$1" | grep -- "--report-success=" >/dev/null 2>/dev/null; then
STRING=`echo "$1" | sed 's@.*--report-success=@@'`
RPT_SUCCESS="$STRING"
fi
if echo "$1" | grep -- "--report-failure=" >/dev/null 2>/dev/null; then
STRING=`echo "$1" | sed 's@.*--report-failure=@@'`
RPT_FAILURE="$STRING"
fi
if echo "$1" | grep -- "--report-warning=" >/dev/null 2>/dev/null; then
STRING=`echo "$1" | sed 's@.*--report-warning=@@'`
RPT_WARNING="$STRING"
fi
shift
done
fi
if [ "X" != "X$pw_cli_instance" ]; then
pw_instance=$pw_cli_instance
fi
if [ "X" = "X$pw_instance" ]; then
echo "ERROR: Patchwork instance is unset."
echo "Please setup ${HOME}/.pwmon-rc and set pw_instance"
echo "(or pass it as an argument)."
echo "Use '--help' option for more information"
exit 1
fi
for I in travis github obs cirrus dummy; do
token=${I}_token
disable=disable_${I}
if [ "X${!disable}" = "Xyes" ]; then
echo "Skiping ${I}"
continue
else
echo "Scanning ${I}"
fi
./${I}_mon $pw_instance ${!token} "$pw_project" | grep "^pw|" | while IFS="|" \
read -r PW pw_chk_instance BUILD series_id SHA shasum result build_url series_name repo_name test_name; do
SERIES_LINE=$(./series_get $pw_instance $series_id)
sid=$(echo $SERIES_LINE | cut -d\| -f1)
proj=$(echo $SERIES_LINE | cut -d\| -f2)
url=$(echo $SERIES_LINE | cut -d\| -f3)
author=$(echo $SERIES_LINE | cut -d\| -f4)
email=$(echo $SERIES_LINE | cut -d\| -f5)
PATCHDATA=$(curl -A "(pw-ci) ci-mon-${PROJECT}" -s $url)
patch_id="$(get_patch_id_by_series_id_and_sha "$series_id" "$shasum" "$pw_chk_instance")"
if [ "X$patch_id" == "X" ]; then
patch_id=$(echo $PATCHDATA | jq -rc '.patches[-1].id')
fi
PATCHDATA="$(echo "$PATCHDATA" | jq ".patches[] | select(.id==$patch_id)")"
patch_url=$(echo $PATCHDATA | jq -rc '.url' | sed -e "$patch_url_regex")
if [ "X$patch_url_regex" != "Xq" ]; then
old_url=$(echo $PATCHDATA | jq -rc '.url')
echo "(patch url '$old_url' transform by '$patch_url_regex' to '$patch_url')"
fi
message_id=$(echo $PATCHDATA | jq -rc '.msgid')
SENDCC=""
if [ "$result" == "passed" ]; then
RESULT="$RPT_SUCCESS"
elif [ "$result" == "failed" ]; then
RESULT="$RPT_FAILURE"
else
RESULT="$RPT_WARNING"
fi
echo "(clear result for series_$series_id with $RESULT at url $build_url on patch $patch_id)"
echo "To: $to_addr" > report.eml
echo "From: $from_addr" >> report.eml
if [ "$result" != "passed" ]; then
echo "Cc: $email" >> report.eml
fi
echo "Subject: |$RESULT| pw$patch_id $series_name" >> report.eml
echo "Date: $(date +"%a, %e %b %Y %T %::z")" >> report.eml
echo "In-Reply-To: $message_id" >> report.eml
echo "References: $message_id" >> report.eml
echo "" >> report.eml
if [ "$test_name" != "" ]; then
TEST_LABEL="${I}-robot: ${test_name}"
else
TEST_LABEL="${I}-robot"
fi
echo "Test-Label: $TEST_LABEL" >> report.eml
echo "Test-Status: $RESULT" >> report.eml
echo "$patch_url" >> report.eml
echo "" >> report.eml
echo "_${I} build: ${result}_" >> report.eml
echo "Build URL: $build_url" >> report.eml
if [ -f ./${I}_get_logs.sh ]; then
./${I}_get_logs.sh "$repo_name" "$series_id" "$shasum" "${!token}" "$test_name" >> report.eml
fi
if [ "$result" != "passed" ]; then
SENDCC="--cc=$email"
fi
git send-email $dry_run --suppress-from --to="$to_addr" $SENDCC report.eml
done
done