2 #set -x # uncomment for bash script debugging
4 ### ============================================================================
5 ### Licensed under the Apache License, Version 2.0 (the "License");
6 ### you may not use this file except in compliance with the License.
7 ### You may obtain a copy of the License at
9 ### http://www.apache.org/licenses/LICENSE-2.0
11 ### Unless required by applicable law or agreed to in writing, software
12 ### distributed under the License is distributed on an "AS IS" BASIS,
13 ### WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 ### See the License for the specific language governing permissions and
15 ### limitations under the License.
16 ### ============LICENSE_END=====================================================
22 ### Thomas Kulik, Deutsche Telekom AG, 2020
25 ### Retrieves a full list of ONAP repos from gerrit inluding their state.
26 ### Clones all active repos of the ONAP master branch plus other requested ONAP
27 ### branches. Then the script does some docs related analyses depending on the
28 ### clone results. It creates logfiles containing filtered results. In addition
29 ### a table.csv is created which can be used to import it in a spreadsheed.
30 ### Also a zip-file is created which contains all the results.
33 ### - in the output, repo names are shown in square brackets for readability
34 ### e.g [aai/aai-common]/docs/release-notes.rst
35 ### - in the table.csv file you see data for the requested branch if available.
36 ### if not available, data is retrieved from the master branch. it will be
37 ### denoted in round brackets, e.g. (3) (tox.ini)
45 ### SOME HELPING COMMANDS TO PROCESS LOG FILES:
47 ### curl -s https://git.onap.org/ | grep "^<tr><td class='toplevel-repo'><a title='" | sed -r "s:^<tr><td class='toplevel-repo'><a title='::" | sed -r "s:'.*::"
49 ### remove branchname from the line
50 ### cat frankfurt_gerritclone.log | sed 's:frankfurt|::'
52 ### list only image names
53 ### cat master_dockerimagesfull.log | grep image | sed -r 's:image\:::' | sed -r 's:^ +::' | sed '/^[[:space:]]*$/d'
55 ### more interesting stuff ...
56 ### curl https://gerrit.onap.org/r/projects/?d
57 ### LONG: curl -s 'https://gerrit.onap.org/r/projects/?d' | awk '{if(NR>1)print}' | jq -c '.[] | {id, state}' | sed -r 's:%2F:/:g' | sed -r 's:["{}]::g' | sed -r 's:id\:::' | sed -r 's:,state\::|:' | sed '/All-Projects/d' | sed '/All-Users/d'
58 ### SHORT: curl -s 'https://gerrit.onap.org/r/projects/?d' | awk '{if(NR>1)print}' | jq -c '.[] | {id, state}' | sed -r 's:%2F:/:g; s:["{}]::g; s:id\:::; s:,state\::|:; /All-Projects/d; /All-Users/d'
61 script_version="1.0 (2020-11-16)"
63 # save command for the restart with logging enabled
66 fullcommand="${command} ${arguments}"
76 echo " ./checkdocs.sh "
79 echo " -u|--user username "
80 echo " linux foundation username used to clone ONAP Gerrit repos"
82 echo " -b|--branches branch1,branch2,branch3 "
83 echo " list of branches to be cloned. master is automatically "
84 echo " added to the list. do not add manually! "
87 echo " development-mode - limits number of repos to be cloned "
93 echo "*******************************************************************************"
96 # remove lockfile in case script is interrupted
97 trap InterruptedScript SIGINT SIGTERM SIGHUP SIGKILL SIGSTOP
98 function InterruptedScript {
100 echo "Script was interrupted."
101 if [ -f $lockfile ] ; then
108 ### arguments handling
120 if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then
124 echo "Error: Argument for $1 is missing" >&2
130 if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then
134 echo "Error: Argument for $1 is missing" >&2
139 -*|--*=) # unsupported flags
140 echo "Error: Unsupported argument $1" >&2
144 *) # preserve positional arguments
151 # set positional arguments in their proper place
152 eval set -- "$PARAMS"
154 # old: declare -a branches=("master" "frankfurt" "guilin")
155 if [[ $branches_csv == "" || $lfusername == "" ]]; then
160 # master branch is automatically added and must not part of the user arguments
161 if [[ $branches_csv == *"master"* ]]; then
165 # clone master first, the the other branches
166 branches_csv="master,${branches_csv}"
168 # create the branches array by readinging in the values from the variable
169 IFS=',' read -r -a branches <<< "${branches_csv}"
171 #echo "DBUG: devmode = \"${devmode}\""
172 #echo "DBUG: branches_csv = \"${branches_csv}\""
173 #echo "DBUG: lfusername = \"${lfusername}\""
174 #echo "DBUG: branches = \"${branches[@]}\""
176 # restart script with logging enabled
177 lockfile="checkdocs-runtime-lockfile"
178 if [ ! -f $lockfile ] ; then
180 echo "Restarting script with logging enabled."
181 ${fullcommand} 2>&1 | tee checkdocs.log
187 echo "checkdocs.sh Version ${script_version}"
190 # curl must be installed
191 if ! command -v curl &> /dev/null
193 echo "ERROR: curl command could not be found"
197 today=$(date '+%Y-%m-%d');
198 repolist="gerrit-repos-master-"$today".txt";
200 echo "Retrieving a full list of ONAP repositories (master) from gerrit.onap.org."
202 # retrieve the full repolist from gerrit
203 # workaround because of the (wrong?) response of gerrit.onap.org which makes jq command fail
204 # "| awk '{if(NR>1)print}'" filters the first line of the response so that jq will work again (thx marek)
205 curl -s 'https://gerrit.onap.org/r/projects/?d' | awk '{if(NR>1)print}' | jq -c '.[] | {id, state}' | sed -r 's:%2F:/:g; s:["{}]::g; s:id\:::; s:,state\::|:; /All-Projects/d; /All-Users/d' >./$repolist
207 # process the created repolist
208 # only active projects will be cloned in case the requested branch of the project exists
209 echo "Accessing gerrit.onap.org with username \"${lfusername}\"."
210 echo "Start cloning of repositories."
212 for branch in "${branches[@]}"
221 branch_upper=$(echo "${branch}" | tr '[:lower:]' '[:upper:]')
233 if [[ $devmode == "TRUE" ]]; then
234 devcounter=$((devcounter+1))
237 if [[ $devcounter -lt "11" ]]; then
239 if [[ $devmode == "TRUE" ]]; then
240 echo "INFO: devmode! counter=${devcounter}"
244 reponame=$(echo $line | awk -F "|" '{print $1}');
245 repostate=$(echo $line | awk -F "|" '{print $2}');
249 if [[ $repostate == "ACTIVE" ]]; then
250 echo "Cloning \"${branch}\" branch of ACTIVE project ${reponame}..."
252 git clone --branch ${branch} --recurse-submodules ssh://${lfusername}@gerrit.onap.org:29418/$reponame ./$reponame
255 if [[ ! ${gitexitcode} == "0" ]]; then
256 errormsg=$(tail -1 ../checkdocs.log)
261 # gerritclone.log format: $1=gitexitcode|$2=reponame|$3=repostate|$4=errormsg
262 echo "${gitexitcode}|${reponame}|${repostate}|${errormsg}" | tee -a ${branch}_gerritclone.log
264 elif [[ $repostate == "READ_ONLY" ]]; then
265 echo "-|${reponame}|${repostate}|ignored" | tee -a ${branch}_gerritclone.log
267 echo "-|${reponame}|unknown repo state \"${repostate}\"|-" | tee -a ${branch}_gerritclone.log
271 if [[ ${gitexitcode} == "0" ]]; then
273 printf "\ndocs directories:\n"
274 find ./$reponame -type d -name docs | sed -r 's:./::' | sed -r s:${reponame}:[${reponame}]: | tee -a ${branch}_docs.log
276 printf "\nrst files:\n"
277 find ./$reponame -type f -name *.rst | sed -r 's:./::' | sed -r s:${reponame}:[${reponame}]: | tee -a ${branch}_rstfiles.log
279 printf "\nrelease notes rst:\n"
280 find ./$reponame -type f | grep 'release.*note.*.rst' | sed -r 's:./::' | sed -r s:${reponame}:[${reponame}]: | tee -a ${branch}_releasenotes.log
282 printf "\ntox.ini files:\n"
283 find ./$reponame -type f -name tox.ini | sed -r 's:./::' | sed -r s:${reponame}:[${reponame}]: | tee -a ${branch}_toxini.log
285 printf "\nconf.py files:\n"
286 find ./$reponame -type f -name conf.py | sed -r 's:./::' | sed -r s:${reponame}:[${reponame}]: | tee -a ${branch}_confpy.log
288 printf "\nindex.rst files:\n"
289 find ./$reponame -type f -name index.rst | sed -r 's:./::' | sed -r s:${reponame}:[${reponame}]: | tee -a ${branch}_indexrst.log
293 # end defcounter loop
302 find . -type f -name values.yaml -print -exec grep "image:" {} \; | sed -r 's:^ +::' | tee ${branch}_dockerimagesfull.log
304 ls --format single-column -d */ | sed 's:/$::' | tee ${branch}_directories.log
306 cat ${branch}_dockerimagesfull.log | grep image | sed -r 's:image\:::' | sed -r 's:^ +::' | sed '/^[[:space:]]*$/d' >${branch}_dockerimages.log
308 ls --format single-column -d oom/kubernetes/*/ | tee ${branch}_oomkubernetes.log
312 readarray -t docs_array < ./${branch}_docs.log;
314 for line in "${docs_array[@]}"
317 echo $line | tee -a ${branch}_docsconfig.log
319 # remove [ and ] which are distinguish the project name in the output
320 line=$(echo $line | sed -r 's:\[:: ; s:\]::')
322 if [ -f ./${line}/conf.py ] ; then
323 echo " conf.py ..... found" | tee -a ${branch}_docsconfig.log
325 echo " conf.py ..... NOT FOUND" | tee -a ${branch}_docsconfig.log
328 if [ -f ./${line}/index.rst ] ; then
329 echo " index.rst ... found" | tee -a ${branch}_docsconfig.log
331 echo " index.rst ... NOT FOUND" | tee -a ${branch}_docsconfig.log
334 if [ -f ./${line}/tox.ini ] ; then
335 echo " tox.ini ..... found" | tee -a ${branch}_docsconfig.log
337 echo " tox.ini ..... NOT FOUND" | tee -a ${branch}_docsconfig.log
340 echo " " | tee -a ${branch}_docsconfig.log
348 ### build a csv table that combines results
352 # csv column #1: project name
355 readarray -t array < ./${repolist};
359 for line in "${array[@]}"
361 reponame=$(echo $line | awk -F "|" '{print $1}');
362 project=$(echo $reponame | sed 's:/.*$::')
363 #echo "DBUG: reponame=${reponame}"
364 #echo "DBUG: project=${project}"
375 # csv column #2: repo name
378 readarray -t array < ./${repolist};
380 csv[i]="${csv[i]},MASTER repo name"
382 for line in "${array[@]}"
384 reponame=$(echo $line | awk -F "|" '{print $1}');
385 csv[i]="${csv[i]},${reponame}"
393 # csv column #3: repo state
396 readarray -t array < ./${repolist};
398 csv[i]="${csv[i]},MASTER repo state"
400 for line in "${array[@]}"
402 repostate=$(echo $line | awk -F "|" '{print $2}');
403 csv[i]="${csv[i]},${repostate}"
411 # csv column #4: clone message
414 readarray -t array < ./${branch}_gerritclone.log;
416 csv[i]="${csv[i]},${branch_upper} clone message"
418 for line in "${array[@]}"
420 # gerritclone.log format: $1=gitexitcode|$2=reponame|$3=repostate|$4=errormsg
421 errormsg=$(echo $line | awk -F "|" '{print $4}');
422 csv[i]="${csv[i]},${errormsg}"
430 # csv column #5: RELEASE component (yes|no|maybe)
431 # to be filled with values of the planned release config file maintained by
432 # the onap release manager
435 # gerritclone.log format: $1=gitexitcode|$2=reponame|$3=repostate|$4=errormsg
436 readarray -t array < ./${branch}_gerritclone.log;
438 csv[i]="${csv[i]},${branch_upper} component"
440 for line in "${array[@]}"
443 # gerritclone.log format: $1=gitexitcode|$2=reponame|$3=repostate|$4=errormsg
444 gitexitcode=$(echo $line | awk -F "|" '{print $1}');
445 reponame=$(echo $line | awk -F "|" '{print $2}');
446 repostate=$(echo $line | awk -F "|" '{print $3}');
447 errormsg=$(echo $line | awk -F "|" '{print $4}');
449 if [[ ${repostate} == "ACTIVE" && ${gitexitcode} == "0" ]]; then
450 releasecomponent="yes"
451 elif [[ ${repostate} == "ACTIVE" && ${gitexitcode} == "128" ]]; then
452 releasecomponent="maybe"
453 elif [ ${repostate} == "READ_ONLY" ]; then
454 releasecomponent="no"
456 releasecomponent="unknown"
459 csv[i]="${csv[i]},${releasecomponent}"
468 unset releasecomponent
471 # csv column #6: docs (at repo root directory only; no recursive search!)
472 # csv column #7: conf.py
473 # csv column #8: tox.ini
474 # csv column #9: index.rst
476 # columns are filled with values from requested branch.
477 # if data is not available values from master branch are used.
478 # to identify master branch values, data is put into brackets "(...)"
481 readarray -t array < ./${repolist};
483 csv[$i]="${csv[i]},docs,conf.py,tox.ini,index.rst"
485 for line in "${array[@]}"
487 line=$(echo $line | sed 's:|.*$::')
488 #echo "DBUG: line=${line}"
492 if [ -d ./${line}/docs ] ; then
494 elif [ -d ../master/${line}/docs ] ; then
501 if [ -f ./${line}/docs/conf.py ] ; then
502 docs="${docs},conf.py"
503 elif [ -f ../master/${line}/docs/conf.py ] ; then
504 docs="${docs},(conf.py)"
510 if [ -f ./${line}/docs/tox.ini ] ; then
511 docs="${docs},tox.ini"
512 elif [ -f ../master/${line}/docs/tox.ini ] ; then
513 docs="${docs},(tox.ini)"
519 if [ -f ./${line}/docs/index.rst ] ; then
520 docs="${docs},index.rst"
521 elif [ -f ../master/${line}/docs/index.rst ] ; then
522 docs="${docs},(index.rst)"
527 #echo "DBUG: docs=${docs}"
528 line="${csv[i]},${docs}"
537 # csv column #10: index.html@RTD accessibility check
538 # csv column #11: index.html url
541 readarray -t array < ./${branch}_gerritclone.log;
543 csv[i]="${csv[i]},index.html@RTD,index.html url"
545 for line in "${array[@]}"
547 # gerritclone.log format: $1=gitexitcode|$2=reponame|$3=repostate|$4=errormsg
548 gitexitcode=$(echo $line | awk -F "|" '{print $1}');
549 reponame=$(echo $line | awk -F "|" '{print $2}');
550 repostate=$(echo $line | awk -F "|" '{print $3}');
551 errormsg=$(echo $line | awk -F "|" '{print $4}');
556 # this routine works only with release "frankfurt" and later because
557 # earlier releases are using submodule structure for documentation files
558 if echo "$branch" | grep -q '^[abcde]'; then
559 curl_result="unsupported release"
563 # we are working on "frankfurt" branch or later ...
564 # only if repostate IS ACTIVE a curl test is required
565 if [[ ${repostate} == "ACTIVE" ]]; then
567 # OPTIONAL: USE ALSO GITEXITCODE AS A FILTER CRITERIA ???
570 url_start="https://docs.onap.org/projects/onap"
574 # "master" branch documentation is available as "latest" in RTD
575 if [[ ${url_branch} == "master" ]]; then
579 # replace all / characters in repo name with - charachter
580 url_repo=$(echo ${reponame} | sed -r 's/\//-/g')
581 url_file="index.html"
584 url="${url_start}-${url_repo}/${url_lang}/${url_branch}/${url_file}"
585 #echo "DBUG: url=$url"
587 # test accessibility of url
588 curl --head --silent --fail "${url}" >/dev/null
591 # convert numeric results to text
592 if [ "${curl_result}" = "0" ]; then
593 curl_result="accessible"
594 elif [ "${curl_result}" = "22" ]; then
595 curl_result="does not exist"
597 curl_result="ERROR:${curl_result}"
600 # url does not exist for this branch.
601 # in case the requested url is not already for "master" branch,
602 # we try to access the url of the master branch and denote the
603 # result by using round brackets (result)
604 if [[ ${curl_result} == "does not exist" && ! $branch == "master" ]]; then
606 # build the full (master/latest) url
607 url="${url_start}-${url_repo}/${url_lang}/latest/${url_file}"
608 #echo "DBUG: url=$url"
610 # test accessibility of url in "master branch" (latest)
611 curl --head --silent --fail "${url}" >/dev/null
613 # denote result as a value from "master" branch (latest)
616 # convert numeric results to text
617 if [ "${curl_result}" = "0" ]; then
618 curl_result="(accessible)"
619 elif [ "${curl_result}" = "22" ]; then
620 curl_result="(does not exist)"
622 curl_result="(ERROR:${curl_result})"
627 # repostate IS NOT ACTIVE - no curl test required
633 echo "$url ... $curl_result"
634 csv[i]="${csv[i]},${curl_result},${url}"
635 #echo "DBUG: csv line=${csv[i]}"
641 # csv column #12: release notes
644 readarray -t array < ../${repolist};
646 csv[i]="${csv[i]},release notes"
648 for line in "${array[@]}"
650 line=$(echo $line | sed 's:|.*$::')
651 #echo "DBUG: line=\"${line}\""
655 # put repo name in square brackets for increased grep hit rate
656 # escape minus and bracket characters to avoid problems with the grep command
657 #repo_grepable=$(echo ${line} | sed -r s:${line}:[${line}]: | sed -r 's/-/\\-/g' | sed -r 's/\[/\\[/g' | sed -r 's/\]/\\]/g')
658 #echo "DBUG: repo_grepable=\"${repo_grepable}\""
660 # check if repo dir exists in this branch
661 if [ -d ./${line} ] ; then
662 # if yes, check if repo name appears in the branch releasenotes.log
663 relnote=$(find "./${line}" -type f | grep 'release.*note.*.rst' | wc -l);
664 # repo dir DOES NOT exist in this branch - so check if repo dir exists in MASTER branch
665 elif [ -d ../master/${line} ] ; then
666 # if yes, check if repo name appears in the MASTER releasenotes.log
667 # count release notes files in MASTER branch (in repo root and its subdirectories)
668 relnote=$(find "../master/${line}" -type f | grep 'release.*note.*.rst' | wc -l);
669 # put results in round brackets to show that this is MASTER data
670 relnote=$(echo ${relnote} | sed -r s:${relnote}:\(${relnote}\):)
675 line="${csv[i]},${relnote}"
686 # build the table.csv file
691 echo "$i" | tee -a ./${branch}_table.csv
695 # create data package for this branch and zip it
698 datadir=${branch}_data
700 cp $repolist $datadir
701 cp ${branch}_table.csv $datadir
702 cp ${branch}_*.log $datadir
703 zip -r ${datadir}.zip $datadir
705 # return from the branch directory
708 # return and work on the next requested branch ... or exit