-
Notifications
You must be signed in to change notification settings - Fork 0
/
oooci-jobs.sh
executable file
·319 lines (291 loc) · 9.81 KB
/
oooci-jobs.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
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
OOOCI_REPOS_PATH=${OOOCI_REPOS_PATH:-$HOME/Downloads/oooci-jobs}
REFRESH=0
FOREVA=0
OOOCI_BROWSER=${OOOCI_BROWSER:- "firefox"} # change me for different browser
OOOCI_BROWSER_LINKS=""
JOB_REPOS=(
https://github.com/openstack/tripleo-ci.git
https://github.com/rdo-infra/rdo-jobs.git
https://github.com/rdo-infra/ci-config.git
https://github.com/rdo-infra/review.rdoproject.org-config.git
)
DSTREAM=0 # default to not checking code.engineering - see --dstream/-d option
DSTREAM_JOB_REPOS=(
https://code.engineering.redhat.com/gerrit/openstack/tripleo-ci-internal-config.git
https://code.engineering.redhat.com/gerrit/openstack/tripleo-ci-internal-jobs.git
)
DISTROS=(
CentOS-7
CentOS-8
RedHat-8
)
BRANCHES=(
pike
queens
rocky
stein
train
master
)
function purty_print {
echo "$(basename $0): $1"
}
function print_section_line {
echo "**** $(basename $0) ** $(date '+%Y-%m-%d %H:%M:%S') *****************************************************************"
}
function purty_print_section {
echo ""
print_section_line
echo "**** $1 "
echo ""
}
function clean_repo {
local repo_dir=$1
pushd $repo_dir > /dev/null 2>&1
purty_print "PULLING $repo_dir"
git checkout master > /dev/null 2>&1
git pull
popd > /dev/null 2>&1
}
function setup_repos {
purty_print_section "Starting local git clones setup or refresh"
mkdir -p $OOOCI_REPOS_PATH
pushd $OOOCI_REPOS_PATH > /dev/null 2>&1
for repo in ${JOB_REPOS[@]}; do
local local_dir=$(basename $repo .git)
if [[ -d $local_dir ]]; then
clean_repo $local_dir
else
purty_print "CLONING $repo"
git clone $repo
fi
done
popd > /dev/null 2>&1
purty_print "SETUP DONE"
}
function check_voting_and_hound {
local jobname=$1
local repo=$2
local uri=""
local browser_uri=""
local hound_uri=""
case "$repo" in
*tripleo-ci.git)
uri="http://zuul.openstack.org/api/job/$jobname"
browser_uri="http://zuul.openstack.org/job/$jobname"
hound_uri="http://codesearch.openstack.org/?q=$jobname"
;;
*review.rdoproject.org-config.git|*rdo-jobs.git)
uri="https://review.rdoproject.org/zuul/api/job/$jobname"
browser_uri="https://review.rdoproject.org/zuul/job/$jobname"
hound_uri="https://codesearch.rdoproject.org/?q=$jobname"
;;
*tripleo-ci-internal*)
uri="https://sf.hosted.upshift.rdu2.redhat.com/zuul/api/tenant/tripleo-ci-internal/job/$jobname"
browser_uri="https://sf.hosted.upshift.rdu2.redhat.com/zuul/t/tripleo-ci-internal/job/$jobname"
hound_uri="https://sf.hosted.upshift.rdu2.redhat.com/codesearch/?q=$jobname"
;;
esac
purty_print " ... fetching voting info from $uri"
local voting=$(curl -k $uri | jq '.[] | .voting')
purty_print " *** VOTING *** $voting"
purty_print " *** CODE SEARCH *** $hound_uri"
OOOCI_BROWSER_LINKS+=" $browser_uri $hound_uri"
}
function get_job_uri {
local repo=$1
local jobpath=$2
local jobname=$3
local filename=$4
local linenumber=$5
# https://github.com/openstack/tripleo-ci/blob/master/zuul.d/standalone-jobs.yaml#L87
# https://code.engineering.redhat.com/gerrit/gitweb?p=openstack/tripleo-ci-internal-jobs.git;a=blob;f=zuul.d/standalone-jobs.yaml#l80
case "$repo" in
*tripleo-ci-internal*)
local internal_base_uri="https://code.engineering.redhat.com/gerrit/gitweb?p=openstack"
local job_uri="$internal_base_uri/$(basename $repo);a=blob;f=$jobpath#l$linenumber"
;;
*)
local job_uri="${repo::-4}/blob/master/$jobpath#L$linenumber"
esac
purty_print " *** DEFINITION *** $job_uri"
OOOCI_BROWSER_LINKS+=" $job_uri"
}
function get_zuul_builds_uri {
local jobname=$1
local repo=$2
case "$repo" in
*tripleo-ci.git)
local zuul_builds="http://zuul.openstack.org/builds?job_name=$jobname"
;;
*rdo-jobs.git|*review.rdoproject.org-config.git)
local zuul_builds="https://review.rdoproject.org/zuul/builds?job_name=$jobname"
;;
*tripleo-ci-internal*)
local zuul_builds="https://sf.hosted.upshift.rdu2.redhat.com/zuul/t/tripleo-ci-internal/builds?job_name=$jobname"
;;
esac
purty_print " *** ZUUL BUILDS *** $zuul_builds"
OOOCI_BROWSER_LINKS+=" $zuul_builds"
}
function get_job_promotion_status {
local jobname=$1
local res=" *** PROMOTION CRITERIA *** "
for distro in ${DISTROS[@]}; do
local promotion_file_path="$OOOCI_REPOS_PATH/ci-config/ci-scripts/dlrnapi_promoter/config/$distro"
local promotion_file_uri="https://github.com/rdo-infra/ci-config/blob/master/ci-scripts/dlrnapi_promoter/config/$distro"
for branch in ${BRANCHES[@]}; do
if [[ -f $promotion_file_path/$branch.ini ]]; then
if grep -rni "^$jobname$" $promotion_file_path/$branch.ini ; then
local res+=" ** INTEGRATION $branch ** $promotion_file_uri/$branch.ini "
OOOCI_BROWSER_LINKS+=" $promotion_file_uri/$branch.ini"
fi
fi
if [[ -f $promotion_file_path/component/$branch.yaml ]]; then
if grep -rni "$jobname$" $promotion_file_path/component/$branch.yaml ; then
local res+=" ** COMPONENT $branch ** $promotion_file_uri/component/$branch.yaml "$
OOOCI_BROWSER_LINKS+=" $promotion_file_uri/component/$branch.yaml"
fi
fi
done
done
purty_print "$res"
}
function check_open_in_browser {
local open_in_browser=""
purty_print " *** COLLECTED URLs *** $OOOCI_BROWSER_LINKS "
echo -n "$0: *** Open URLs with $OOOCI_BROWSER? *** type y or yes - anything else for no > "
read -t 3 -n 1 open_in_browser || true
if [[ "$open_in_browser" == "y" ]] || [[ "$open_in_browser" = "yes" ]]; then
purty_print "see $OOOCI_BROWSER"
$OOOCI_BROWSER $OOOCI_BROWSER_LINKS
fi
}
# Process job find definition/voting/promotion/zuul builds
# Prompt whether to open results in browser
function process_job_definition {
local jobname=$1
OOOCI_BROWSER_LINKS=""
purty_print_section "Processing job: $jobname"
for repo in ${JOB_REPOS[@]}; do
local local_dir=$(basename $repo .git)
if [[ ! -d $OOOCI_REPOS_PATH/$local_dir ]]; then
purty_print "ERROR: $repo local checkout not found at $OOOCI_REPOS_PATH/$local_dir"
purty_print "Run $0 --refresh $jobname to setup local repos required for job query"
exit 2
fi
local res=$(grep -rni "name\: $jobname$" $OOOCI_REPOS_PATH/$local_dir)
if [[ -n "$res" ]]; then
local filename=$(echo $res | awk -F ":" '{print $1}')
local linenumber=$(echo $res | awk -F ":" '{print $2}')
check_voting_and_hound $jobname $repo
case "$repo" in
*tripleo-ci.git)
local jobpath=$(echo $filename | awk -F "/tripleo-ci/" '{print $2}')
;;
*rdo-jobs.git)
local jobpath=$(echo $filename | awk -F "/rdo-jobs/" '{print $2}')
;;
*review.rdoproject.org-config.git)
local jobpath=$(echo $filename | awk -F "/review.rdoproject.org-config/" '{print $2}')
;;
*ci-config*)
local jobpath=$(echo $filename | awk -F "/ci-config/" '{print $2}')
;;
*tripleo-ci-internal-config.git)
local jobpath=$(echo $filename | awk -F "/tripleo-ci-internal-config/" '{print $2}')
;;
*tripleo-ci-internal-jobs.git)
local jobpath=$(echo $filename | awk -F "/tripleo-ci-internal-jobs/" '{print $2}')
;;
esac
get_job_uri $repo $jobpath $jobname $filename $linenumber
get_zuul_builds_uri $jobname $repo
if [[ $jobname =~ "periodic" ]] ; then
get_job_promotion_status $jobname
fi
check_open_in_browser
purty_print "END $jobname"
fi
unset res
done
}
oooci_jobs_usage () {
echo "Usage: $0 [options] jobname"
echo "unless you specify --foreva jobname is REQUIRED"
echo ""
echo "Options:"
echo ""
echo " -d, --dstream Include code.engineering repos if you have"
echo " access to those. The default is to not include"
echo " the downstream repos."
echo ""
echo " -f, --foreva Runs in a loop for multiple queries. It will"
echo " first also refresh repos."
echo ""
echo " -p, --path Sets the local path for git cloning repos into."
echo " Defaults to $OOOCI_REPOS_PATH."
echo ""
echo " -r, --refresh Create git clone of any missing jobs repos into"
echo " $OOOCI_REPOS_PATH and fetch changes from master"
echo ""
echo " -h, --help print this help and exit"
echo ""
echo " https://github.com/marios/tripleo_ruck_job_tool"
echo ""
}
set -e
while [ "x$1" != "x" ]; do
case "$1" in
--refresh|-r)
REFRESH=1
;;
--path|-p)
OOOCI_REPOS_PATH=$2
shift
;;
--foreva|-f)
FOREVA=1
;;
--dstream|-d)
DSTREAM=1
;;
--help|-h)
oooci_jobs_usage
exit
;;
--) shift
break
;;
-*) echo "ERROR: unknown option: $1" >&2
oooci_jobs_usage >&2
exit 2
;;
*) break
;;
esac
shift
done
if [[ "$DSTREAM" == "1" ]] ; then
# include downstream repos
JOB_REPOS=("${JOB_REPOS[@]}" "${DSTREAM_JOB_REPOS[@]}")
purty_print "Enabling code.engineering repos in job search"
fi
if [[ "$REFRESH" == "1" ]] || [[ "$FOREVA" == "1" ]]; then
setup_repos
fi
if [[ "$FOREVA" == "1" ]]; then
while [[ $jobname != "exit" ]] ; do
purty_print_section "main loop - ctrl-c or 'exit' to exit"
echo -n "$(basename $0): it puts the job name here > "
read jobname
process_job_definition $jobname
done
elif [[ $# != 1 ]] ; then
if [[ "$REFRESH" == "1" ]]; then exit 0; fi # ok if refresh
purty_print "ERROR: you must either specify a job name or pass --foreva"
oooci_jobs_usage
exit 2
else
process_job_definition $1
fi