Merge "Update doc/tools"
[doc.git] / tools / checkdocs.sh
1 #!/bin/bash
2 #set -x # uncomment for bash script debugging
3
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
8 ###
9 ###       http://www.apache.org/licenses/LICENSE-2.0
10 ###
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=====================================================
17
18 ###
19 ### checkdocs.sh
20 ###
21 ### AUTHOR(S):
22 ### Thomas Kulik, Deutsche Telekom AG, 2020 - 2021
23 ###
24 ### DESCRIPTION:
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.
31 ###
32 ### IMPORTANT:
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)
38 ###
39 ### REQUIREMENTS:
40 ### curl
41 ### jq
42 ###
43
44 ###
45 ### SOME HELPING COMMANDS TO PROCESS LOG FILES:
46 ### create repo list
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:'.*::"
48 ###
49 ### remove branchname from the line:
50 ### cat frankfurt_repoclone.log | sed 's:frankfurt|::'
51 ###
52 ### list only image names
53 ### cat master_dockerimagesfull.log | grep image | sed -r 's:image\:::' | sed -r 's:^ +::' | sed '/^[[:space:]]*$/d'
54 ###
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'
59 ###
60
61 script_version="1.9 (2021-05-31)"
62
63 # save command for the restart with logging enabled
64 command=$0
65 arguments=$@
66 fullcommand="${command} ${arguments}"
67
68 ###
69 ### functions
70 ###
71
72 # print usage
73 function usage() {
74   echo "                                                           "
75   echo " checkdocs.sh Version ${script_version}"
76   echo "                                                           "
77   echo " USAGE:                                                    "
78   echo "  ./checkdocs.sh <arguments>                               "
79   echo "                                                           "
80   echo " ARGUMENTS:                                                "
81   echo "  -u|--user username                                       "
82   echo "  linux foundation username used to clone ONAP repositories"
83   echo "                                                           "
84   echo "  -b|--branches branch1,branch2,branch3                    "
85   echo "  list of branches to be cloned. master is automatically   "
86   echo "  added to the list. do not add manually!                  "
87   echo "                                                           "
88   echo "  -d|--dev                                                 "
89   echo "  development-mode - limits number of repos to be cloned   "
90   echo "                                                           "
91 }
92
93 # draw a simple line
94 function drawline {
95   echo "*******************************************************************************"
96 }
97
98 # remove lockfile in case script is interrupted
99 trap InterruptedScript SIGINT SIGTERM SIGHUP SIGKILL SIGSTOP
100 function InterruptedScript {
101   echo " "
102   echo "Script was interrupted."
103   if [ -f $lockfile ] ; then
104     rm $lockfile
105   fi
106   exit 0
107 }
108
109 # function to parse wiki (project) lifecycle state information
110 # call:   getwikilifecyclestate "projectname"
111 # result: $return_from_getwikilifecyclestate
112 # because bash supports only returning numeric values a variable $return_from_getwikilifecyclestate is used
113
114 function getwikilifecyclestate {
115
116   local requested=$1
117   local wikiline=""
118   local wikirepo=""
119   local wikistate=""
120
121   return_from_getwikilifecyclestate=""
122    
123   for wikiline in "${wikiplsarray[@]}"
124   do
125   
126      wikirepo=$(echo $wikiline | awk -F ";" '{print $1}');
127     wikistate=$(echo $wikiline | awk -F ";" '{print $2}');
128     
129     #echo "DBUG: getwikilifecyclestate  wikiline = \"${wikiline}\"";
130     #echo "DBUG: getwikilifecyclestate  wikirepo = \"${wikirepo}\""
131     #echo "DBUG: getwikilifecyclestate wikistate = \"${wikistate}\""
132
133     if [[ ${wikirepo} == ${requested} ]]; then
134       return_from_getwikilifecyclestate=${wikistate}
135       #echo "DBUG: getwikilifecyclestate     wikirepo = \"${wikirepo}\""
136       #echo "DBUG: getwikilifecyclestate    requested = \"${requested}\""
137       #echo "DBUG: return_from_getwikilifecyclestate  = \"${return_from_getwikilifecyclestate}\"";
138       return 0;
139     fi
140
141   done
142
143   #echo "DBUG: getwikilifecyclestate requested \"${requested}\" NOT FOUND in list"
144   return_from_getwikilifecyclestate=""
145
146 }
147
148 ###
149 ### arguments handling
150 ###
151
152 PARAMS=""
153
154 while (( "$#" )); do
155   case "$1" in
156     -d|--dev)
157       devmode="TRUE"
158       shift
159       ;;
160     -b|--branches)
161       if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then
162         branches_csv=$2
163         shift 2
164       else
165         echo "Error: Argument for $1 is missing" >&2
166         usage
167         exit 1
168       fi
169       ;;
170     -u|--user)
171       if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then
172         lfusername=$2
173         shift 2
174       else
175         echo "Error: Argument for $1 is missing" >&2
176         usage
177         exit 1
178       fi
179         ;;
180     -*|--*=) # unsupported flags
181       echo "Error: Unsupported argument $1" >&2
182       usage
183       exit 1
184       ;;
185     *) # preserve positional arguments
186       PARAMS="$PARAMS $1"
187       shift
188       ;;
189   esac
190 done
191
192 # set positional arguments in their proper place
193 eval set -- "$PARAMS"
194
195 # old: declare -a branches=("master" "frankfurt" "guilin")
196 if [[ $branches_csv == "" || $lfusername == "" ]]; then
197   usage
198   exit -1
199 fi
200
201 # master branch is automatically added and must not part of the user arguments
202 if [[ $branches_csv == *"master"* ]]; then
203   usage
204   exit -1
205 fi
206 # clone master first, then the other branches
207 branches_csv="master,${branches_csv}"
208
209 # create the branches array by readinging in the values from the variable
210 IFS=',' read -r -a branches <<< "${branches_csv}"
211
212 #echo "DBUG: devmode      = \"${devmode}\""
213 #echo "DBUG: branches_csv = \"${branches_csv}\""
214 #echo "DBUG: lfusername   = \"${lfusername}\""
215 #echo "DBUG: branches     = \"${branches[@]}\""
216
217 # restart script with logging enabled
218 lockfile="checkdocs-runtime-lockfile"
219 if [ ! -f $lockfile ] ; then
220   touch $lockfile
221   echo "Restarting script with logging enabled."
222   ${fullcommand} 2>&1 | tee checkdocs.log
223   rm $lockfile
224   exit
225 fi
226
227 echo " "
228 echo "checkdocs.sh Version ${script_version}"
229 echo " "
230
231 #
232 # read in wiki (project) lifecycle state
233 # always use the lastest available file (derived from date in filename e.g. wiki_lifecycle_state_210409.txt)
234 # format is <reponame abbrev>;<state>;<reponame full>
235 #
236
237 wikiplsfile=$(ls | sed -nr '/wiki_lifecycle_state_[0-9]{6}.txt/Ip' | tail -1);
238
239 if [[ $wikiplsfile == "" ]]; then
240   echo "ERROR: wiki_lifecycle_state_yymmdd.txt missing"
241   exit -1
242 fi
243
244 echo "Using \"${wikiplsfile}\" as the source for wiki (project) lifecycle state information."
245
246 readarray -t wikiplsarray < ./${wikiplsfile};
247 i=0
248 ((i++))
249 for line in "${wikiplsarray[@]}"
250 do
251    wikiplsrepo=$(echo $line | awk -F ";" '{print $1}');
252   wikiplsstate=$(echo $line | awk -F ";" '{print $2}');
253   #echo "DBUG: wikipls line=\"${line}\"";
254   #echo "DBUG: wikipls ${wikiplsrepo}=${wikiplsstate}"
255   ((i++))
256 done
257 unset i
258 unset wikiplsrepo
259 unset wikiplsstate
260
261 #
262 # curl must be installed
263 #
264
265 if ! command -v curl &> /dev/null
266 then
267   echo "ERROR: curl command could not be found"
268   exit -1
269 fi
270
271 today=$(date '+%Y-%m-%d');
272 repolist="gerrit-repos-master-"$today".txt";
273 unique=$(date +%s)
274
275 echo "Retrieving a full list of ONAP repositories (master) from gerrit.onap.org."
276
277 #
278 # retrieve the full repolist from gerrit
279 # workaround because of the (wrong?) response of gerrit.onap.org which makes jq command fail
280 # "| awk '{if(NR>1)print}'" filters the first line of the response so that jq will work again (thx marek)
281 #
282
283 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
284
285 # process the created repolist and try to clone the projects from the mirror
286
287 source="git://cloud.onap.org/mirror"
288 echo "Using \"${source}\" as the source and username \"${lfusername}\" for cloning the repositories."
289 echo "Start cloning of repositories ..."
290
291 for branch in "${branches[@]}"
292 do
293
294   echo " "
295   echo "###"
296   echo "### ${branch}"
297   echo "###"
298   echo " "
299
300   branch_upper=$(echo "${branch}" | tr '[:lower:]' '[:upper:]')
301
302   mkdir $branch
303   cp $repolist $branch
304   cd $branch
305
306   devcounter=0
307
308   # process repolist
309   while read line
310   do
311
312   if [[ $devmode == "TRUE" ]]; then
313     devcounter=$((devcounter+1))
314   fi
315
316   if [[ $devcounter -lt "50" ]]; then
317
318       if [[ $devmode == "TRUE" ]]; then
319         echo "INFO: devmode! counter=${devcounter}"
320       fi
321
322       drawline
323       reponame=$(echo $line | awk -F "|" '{print $1}');
324       repostate=$(echo $line | awk -F "|" '{print $2}');
325       echo $reponame
326       echo $repostate
327
328       if [[ $repostate == "ACTIVE" ]] || [[ $repostate == "READ_ONLY" ]]; then
329         echo "Cloning \"${branch}\" branch of \"${repostate}\" project ${reponame}..."
330
331         # previously used:   git clone --branch ${branch} --recurse-submodules ssh://${lfusername}@gerrit.onap.org:29418/$reponame ./$reponame
332         # clone script Jess: git clone "git://cloud.onap.org/mirror/${i}" "${LOCALNAME}"
333         git clone --branch ${branch} --recurse-submodules ${source}/${reponame} ./${reponame}
334         gitexitcode=$?
335
336         if [[ ! ${gitexitcode} == "0" ]]; then
337           errormsg=$(tail -1 ../checkdocs.log)
338         else
339           errormsg="cloned"
340         fi
341
342         # repoclone.log format:  $1=gitexitcode|$2=reponame|$3=repostate|$4=errormsg
343         echo "${gitexitcode}|${reponame}|${repostate}|${errormsg}" | tee -a ${branch}_repoclone.log
344
345       #elif [[ $repostate == "READ_ONLY" ]]; then
346         #echo "-|${reponame}|${repostate}|ignored" | tee -a ${branch}_repoclone.log
347       else
348         echo "-|${reponame}|unknown repo state \"${repostate}\"|-" | tee -a ${branch}_repoclone.log
349       fi
350
351       # examine repo
352       if [[ ${gitexitcode} == "0" ]]; then
353
354         printf "\ndocs directories:\n"
355         find ./$reponame -type d -name docs | sed -r 's:./::' | sed -r s:${reponame}:[${reponame}]: | tee -a ${branch}_docs.log
356
357         printf "\nrst files:\n"
358         find ./$reponame -type f -name *.rst | sed -r 's:./::' | sed -r s:${reponame}:[${reponame}]: | tee -a ${branch}_rstfiles.log
359
360         printf "\nrelease notes rst:\n"
361         find ./$reponame -type f | grep 'release.*note.*.rst' | sed -r 's:./::' | sed -r s:${reponame}:[${reponame}]: | tee -a ${branch}_releasenotes.log
362
363         printf "\ntox.ini files:\n"
364         find ./$reponame -type f -name tox.ini | sed -r 's:./::' | sed -r s:${reponame}:[${reponame}]: | tee -a ${branch}_toxini.log
365
366         printf "\nconf.py files:\n"
367         find ./$reponame -type f -name conf.py | sed -r 's:./::' | sed -r s:${reponame}:[${reponame}]: | tee -a ${branch}_confpy.log
368
369         printf "\nindex.rst files (all):\n"
370         find ./$reponame -type f -name index.rst | sed -r 's:./::' | sed -r s:${reponame}:[${reponame}]: | tee -a ${branch}_indexrst_all.log
371
372         printf "\nindex.rst files (docs root directory):\n"
373         find ./$reponame -type f -name index.rst | sed -r 's:./::' | sed -r s:${reponame}:[${reponame}]: | grep ']/docs/index.rst' | tee -a ${branch}_indexrst_docs_root.log
374
375         printf "\nINFO.yaml files:\n"
376         find ./$reponame -type f -name INFO.yaml | sed -r 's:./::' | sed -r s:${reponame}:[${reponame}]: | tee -a ${branch}_infoyaml.log
377
378       fi
379
380     # end defcounter loop
381     fi
382
383     gitexitcode=""
384
385   done <${repolist}
386
387   # get (first) title for a rst file
388   drawline
389   python3 ../getrsttitle.py ${branch}_rstfiles.log | tee ${branch}_rstfiles_titles.log
390   drawline
391   python3 ../getrsttitle.py ${branch}_indexrst_docs_root.log | tee ${branch}_indexrst_docs_root_titles.log
392
393   # examine repos
394   drawline
395   find . -type f -name values.yaml -print -exec grep "image:" {} \; | sed -r 's:^ +::' | tee ${branch}_dockerimagesfull.log
396   drawline
397   ls --format single-column -d */ | sed 's:/$::' | tee ${branch}_directories.log
398   drawline
399   cat ${branch}_dockerimagesfull.log | grep image | sed -r 's:image\:::' | sed -r 's:^ +::' | sed '/^[[:space:]]*$/d' >${branch}_dockerimages.log
400   drawline
401   ls --format single-column -d oom/kubernetes/*/ | tee ${branch}_oomkubernetes.log
402   drawline
403
404   # examine docs
405   readarray -t docs_array < ./${branch}_docs.log;
406
407   for line in "${docs_array[@]}"
408   do
409
410     echo $line | tee -a ${branch}_docsconfig.log
411
412     # remove [ and ] which are distinguish the project name in the output
413     line=$(echo $line | sed -r 's:\[:: ; s:\]::')
414
415     if [ -f ./${line}/conf.py ] ; then
416       echo "  conf.py ..... found" | tee -a ${branch}_docsconfig.log
417     else
418       echo "  conf.py ..... NOT FOUND" | tee -a ${branch}_docsconfig.log
419     fi
420
421     if [ -f ./${line}/index.rst ] ; then
422       echo "  index.rst ... found" | tee -a ${branch}_docsconfig.log
423     else
424       echo "  index.rst ... NOT FOUND" | tee -a ${branch}_docsconfig.log
425     fi
426
427     if [ -f ./${line}/tox.ini ] ; then
428       echo "  tox.ini ..... found" | tee -a ${branch}_docsconfig.log
429     else
430       echo "  tox.ini ..... NOT FOUND" | tee -a ${branch}_docsconfig.log
431     fi
432
433     echo " " | tee -a ${branch}_docsconfig.log
434
435   done
436   unset docs_array
437
438   drawline
439
440   ###
441   ### build a csv table that combines results
442   ###
443
444   #
445   # csv column #1: project name
446   #
447
448   readarray -t array < ./${repolist};
449   i=0
450   csv[i]="project"
451   ((i++))
452   for line in "${array[@]}"
453   do
454     reponame=$(echo $line | awk -F "|" '{print $1}');
455     project=$(echo $reponame | sed 's:/.*$::')
456     #echo "DBUG: reponame=${reponame}"
457     #echo "DBUG:  project=${project}"
458     #echo "DBUG:        i=${i}"
459     csv[i]=${project}
460     ((i++))
461   done
462   unset array
463   unset i
464   unset reponame
465   unset project
466
467   #
468   # csv column #2: repo name
469   #
470
471   readarray -t array < ./${repolist};
472   i=0
473   csv[i]="${csv[i]},MASTER repo name"
474   ((i++))
475   for line in "${array[@]}"
476   do
477     reponame=$(echo $line | awk -F "|" '{print $1}');
478     csv[i]="${csv[i]},${reponame}"
479     ((i++))
480   done
481   unset array
482   unset i
483   unset reponame
484
485   #
486   # csv column #3: repo state
487   #
488
489   readarray -t array < ./${repolist};
490   i=0
491   csv[i]="${csv[i]},MASTER repo state"
492   ((i++))
493   for line in "${array[@]}"
494   do
495     repostate=$(echo $line | awk -F "|" '{print $2}');
496     csv[i]="${csv[i]},${repostate}"
497     ((i++))
498   done
499   unset array
500   unset i
501   unset repostate
502
503   #
504   # csv column #4: clone message
505   #
506
507   readarray -t array < ./${branch}_repoclone.log;
508   i=0
509   csv[i]="${csv[i]},${branch_upper} clone message"
510   ((i++))
511   for line in "${array[@]}"
512   do
513     # repoclone.log format:  $1=gitexitcode|$2=reponame|$3=repostate|$4=errormsg
514     errormsg=$(echo $line | awk -F "|" '{print $4}');
515     csv[i]="${csv[i]},${errormsg}"
516     ((i++))
517   done
518   unset array
519   unset i
520   unset errormsg
521
522   #
523   # csv column #5: latest branch
524   #
525
526   readarray -t array < ./${repolist};
527   i=0
528   csv[i]="${csv[i]},latest branch"
529   ((i++))
530   for line in "${array[@]}"
531   do
532     reponame=$(echo $line | awk -F "|" '{print $1}');
533     latestbranch=$(git ls-remote -q --heads "${source}/${reponame}" | sed 's/^.*heads\///' | sed -nr '/^master$|^amsterdam$|^beijing$|^casablanca$|^dublin$|^elalto$|^frankfurt$|^guilin$|^honolulu$|^istanbul$/Ip' | tail -2 | head -1);
534     #echo "DBUG:     reponame=${reponame}"
535     #echo "DBUG: latestbranch=${latestbranch}"
536     echo "latest available branch for repo \"${reponame}\" is \"${latestbranch}\""
537     csv[i]="${csv[i]},${latestbranch}"
538     ((i++))
539   done
540   unset array
541   unset i
542   unset reponame
543   unset latestbranch
544   
545   #
546   # csv column #6: INFO.yaml LC state (project lifecycle state based on INFO.yaml / per repo)
547   # csv column #7: WIKI LC state (project lifecycle state based on ONAP Dev Wiki / per project)
548   # csv column #8: LC state match shows a "match" if both LC states match
549   #
550
551   readarray -t array < ./${repolist};
552   i=0
553   csv[i]="${csv[i]},INFO.yaml LC state,WIKI LC state,LC state match"
554   ((i++))
555   for line in "${array[@]}"
556   do
557     reponame=$(echo $line | awk -F "|" '{print $1}');
558      project=$(echo $reponame | sed 's:/.*$::')
559
560     if [ -f ./${reponame}/INFO.yaml ] ; then
561       # check if repo/branch has a INFO.yaml
562       lifecycleproject=$(grep '^project: ' ./${reponame}/INFO.yaml | awk -F ":" '{print $2}' | sed 's:^ ::' | sed "s:'::g" | tr '[:upper:]' '[:lower:]' | sed 's/\r$//')
563       lifecyclestate=$(grep '^lifecycle_state: ' ./${reponame}/INFO.yaml | awk -F ":" '{print $2}' | sed 's:^ ::' | sed "s:'::g" | tr '[:upper:]' '[:lower:]' | sed 's/\r$//')
564     elif [ ${branch} != "master" ] && [ -f ../master/${reponame}/INFO.yaml ] ; then
565       # if current branch is not master AND if info.yaml not found in the current repo/branch THAN use INFO.yaml of repo/master if available
566       #echo "DBUG: branch=${branch} - checking master for INFO.yaml"
567       lifecycleproject=$(grep '^project: ' ../master/${reponame}/INFO.yaml | awk -F ":" '{print $2}' | sed 's:^ ::' | sed "s:'::g" | tr '[:upper:]' '[:lower:]' | sed 's/\r$//')
568       lifecyclestate=$(grep '^lifecycle_state: ' ../master/${reponame}/INFO.yaml | awk -F ":" '{print $2}' | sed 's:^ ::' | sed "s:'::g" | tr '[:upper:]' '[:lower:]' | sed 's/\r$//')
569       lifecyclestate="(${lifecyclestate})"
570     else
571       lifecyclestate="INFO.yaml not found"
572     fi
573       
574     getwikilifecyclestate ${project}
575     # returns value in ${return_from_getwikilifecyclestate}
576
577     #echo "DBUG: working dir is ...";pwd
578     #echo "DBUG:   lifecycleproject=${lifecycleproject}"
579     #echo "DBUG:     lifecyclestate=${lifecyclestate}"
580     #echo "DBUG: wikilifecyclestate=${return_from_getwikilifecyclestate}"
581
582     #check if YAML.info LC state is not empty _AND_ if WIKI LC state is not empty _AND_ if YAML.info LC state contains WIKI LC state
583     if [[ ${lifecyclestate} != "" ]] && [[ ${return_from_getwikilifecyclestate} != "" ]] && [[ ${lifecyclestate} == *"${return_from_getwikilifecyclestate}"* ]]; then
584       lcstatesmatch="match"
585     else
586       lcstatesmatch=""
587     fi 
588
589     csv[i]="${csv[i]},${lifecyclestate},${return_from_getwikilifecyclestate},${lcstatesmatch}"
590     ((i++))
591   done
592   unset array
593   unset i
594   unset reponame
595   unset project
596   unset lifecycleproject
597   unset lifecyclestate
598   unset lcstatesmatch
599
600   #
601   # csv column #9: RELEASE component (yes|maybe|unknown)
602   # to be filled with values of the planned release config file maintained by
603   # the onap release manager
604   #
605
606   # repoclone.log format:  $1=gitexitcode|$2=reponame|$3=repostate|$4=errormsg
607   readarray -t array < ./${branch}_repoclone.log;
608   i=0
609   csv[i]="${csv[i]},${branch_upper} component"
610   ((i++))
611   for line in "${array[@]}"
612   do
613
614     # repoclone.log format:  $1=gitexitcode|$2=reponame|$3=repostate|$4=errormsg
615     gitexitcode=$(echo $line | awk -F "|" '{print $1}');
616        reponame=$(echo $line | awk -F "|" '{print $2}');
617       repostate=$(echo $line | awk -F "|" '{print $3}');
618        errormsg=$(echo $line | awk -F "|" '{print $4}');
619
620     if [[ ${repostate} == "ACTIVE" && ${gitexitcode} == "0" ]]; then
621       releasecomponent="yes"
622     elif [ ${repostate} == "ACTIVE" ]; then
623     #elif [[ ${repostate} == "ACTIVE" && ${gitexitcode} == "128" ]]; then
624       releasecomponent="maybe"
625     elif [[ ${repostate} == "READ_ONLY" && ${gitexitcode} == "0" ]]; then
626       releasecomponent="yes"
627     elif [ ${repostate} == "READ_ONLY" ]; then
628       releasecomponent="maybe"
629     else
630       releasecomponent="unknown"
631     fi
632
633     csv[i]="${csv[i]},${releasecomponent}"
634     ((i++))
635   done
636   unset array
637   unset i
638   unset gitexitcode
639   unset reponame
640   unset repostate
641   unset errormsg
642   unset releasecomponent
643
644   #
645   # csv column #10: docs (at repo root directory only; no recursive search!)
646   # csv column #11: conf.py
647   # csv column #12: tox.ini
648   # csv column #13: index.rst
649   # csv column #14: first title in index.rst
650   #
651   # columns are filled with values from requested branch.
652   # if data is not available values from master branch are used.
653   # to identify master branch values, data is put into round brackets "(...)"
654   #
655
656   readarray -t array < ./${repolist};
657   i=0
658   csv[$i]="${csv[i]},docs,conf.py,tox.ini,index.rst,first title in index.rst"
659   ((i++))
660   for line in "${array[@]}"
661   do
662     line=$(echo $line | sed 's:|.*$::')
663     #echo "DBUG: line=${line}"
664     #echo "DBUG: i=${i}"
665
666     # docs
667     if [ -d ./${line}/docs ] ; then
668       docs="docs"
669     elif [ -d ../master/${line}/docs ] ; then
670       docs="(docs)"
671     else
672       docs="-"
673     fi
674
675     # conf.py
676     if [ -f ./${line}/docs/conf.py ] ; then
677       docs="${docs},conf.py"
678     elif [ -f ../master/${line}/docs/conf.py ] ; then
679       docs="${docs},(conf.py)"
680     else
681       docs="${docs},-"
682     fi
683
684     # tox.ini (check docs dir and also check project root dir)
685     if [ -f ./${line}/docs/tox.ini ] || [ -f ./${line}/tox.ini ]; then
686       docs="${docs},tox.ini"
687       # tox.ini @ branch/docs dir
688       if [ -f ./${line}/docs/tox.ini ] ; then
689         docs="${docs} @docs"
690       fi
691       # tox.ini @ branch/project root dir
692       if [ -f ./${line}/tox.ini ] ; then
693         docs="${docs} @root"
694       fi
695     elif [ -f ../master/${line}/docs/tox.ini ] || [ -f ../master/${line}/tox.ini ]; then
696       docs="${docs},(tox.ini"
697       # tox.ini @ master/docs dir
698       if [ -f ../master/${line}/docs/tox.ini ] ; then
699         docs="${docs} @docs"
700       fi
701       # tox.ini @ master/project root dir
702       if [ -f ../master/${line}/tox.ini ] ; then
703         docs="${docs} @root"
704       fi   
705       # just add a round bracket at the end of the value
706       docs="${docs})"
707     else
708       # no tox.ini found in docs or root dir
709       docs="${docs},-"
710     fi
711
712     # index.rst, first title in index.rst
713     indexrsttitle=""
714     if [ -f ./${line}/docs/index.rst ] ; then
715       indexrsttitle=$(cat ${branch}_indexrst_docs_root_titles.log | grep -F '['${line}']/docs/index.rst,' | awk -F "," '{print $2}');
716       docs="${docs},index.rst,${indexrsttitle}"
717     elif [ -f ../master/${line}/docs/index.rst ] ; then
718       indexrsttitle=$(cat ../master/master_indexrst_docs_root_titles.log | grep -F '['${line}']/docs/index.rst,' | awk -F "," '{print $2}');
719       docs="${docs},(index.rst),(${indexrsttitle})"
720     else
721       docs="${docs},-,-"
722     fi
723
724     #echo "DBUG: docs=${docs}"
725     line="${csv[i]},${docs}"
726     csv[$i]=${line}
727     ((i++))
728   done
729   unset array
730   unset i
731   unset docs
732
733   #
734   # csv column #15: index.html@RTD accessibility check
735   # csv column #16: index.html url
736   #
737
738   readarray -t array < ./${branch}_repoclone.log;
739   i=0
740   csv[i]="${csv[i]},index.html@RTD,index.html url"
741   ((i++))
742   for line in "${array[@]}"
743   do
744     # repoclone.log format:  $1=gitexitcode|$2=reponame|$3=repostate|$4=errormsg
745     gitexitcode=$(echo $line | awk -F "|" '{print $1}');
746        reponame=$(echo $line | awk -F "|" '{print $2}');
747       repostate=$(echo $line | awk -F "|" '{print $3}');
748        errormsg=$(echo $line | awk -F "|" '{print $4}');
749
750             url=""
751     curl_result=""
752
753     # this script works only with release "frankfurt" and later because
754     # earlier releases are using submodule structure for documentation files
755     if echo "$branch" | grep -q '^[abcde]'; then
756       curl_result="unsupported release"
757       url="-"
758     else
759
760       # we are working on "frankfurt" branch or later ...
761       if [[ ${repostate} == "ACTIVE" ]] || [[ ${repostate} == "READ_ONLY" ]]; then
762
763         # OPTIONAL: USE ALSO GITEXITCODE AS A FILTER CRITERIA ???
764
765         # url base
766         # important! only doc project needs a different url base
767         if [[ ${reponame} == "doc" ]]; then
768           url_start="https://docs.onap.org"
769         else
770           url_start="https://docs.onap.org/projects/onap"
771         fi
772         url_lang="en"
773         url_branch=${branch}
774
775         # "master" branch documentation is available as "latest" in RTD
776         if [[ ${url_branch} == "master" ]]; then
777           url_branch="latest"
778         fi
779
780         # replace all / characters in repo name with - charachter
781         url_repo=$(echo ${reponame} | sed -r 's/\//-/g')
782         url_file="index.html"
783
784         # build the full url
785         if [[ ${reponame} == "doc" ]]; then
786           # build the full url for the doc project
787           url="${url_start}/${url_lang}/${url_branch}/${url_file}"
788         else
789           # build the full url for the other projects
790           url="${url_start}-${url_repo}/${url_lang}/${url_branch}/${url_file}"
791         fi
792         #echo "DBUG: url=$url"
793
794         # test accessibility of url
795         curl --head --silent --fail "${url}?${unique}" >/dev/null
796         curl_result=$?
797
798         # convert numeric results to text
799         if [ "${curl_result}" = "0" ]; then
800           curl_result="accessible"
801         elif [ "${curl_result}" = "22" ]; then
802           curl_result="does not exist"
803         else
804           curl_result="ERROR:${curl_result}"
805         fi
806
807         # url does not exist for this branch.
808         # in case the requested url is not already for "master" branch,
809         # we try to access the url of the master branch and denote the
810         # result by using round brackets (result)
811         if [[ ${curl_result} == "does not exist" && ! $branch == "master" ]]; then
812
813           # build the full (master/latest) url
814           url="${url_start}-${url_repo}/${url_lang}/latest/${url_file}"
815           #echo "DBUG: url=$url"
816
817           # test accessibility of url in "master branch" (latest)
818           curl --head --silent --fail "${url}?${unique}" >/dev/null
819           curl_result=$?
820           # denote result as a value from "master" branch (latest)
821           url="(${url})"
822
823           # convert numeric results to text
824           if [ "${curl_result}" = "0" ]; then
825             curl_result="(accessible)"
826           elif [ "${curl_result}" = "22" ]; then
827             curl_result="(does not exist)"
828           else
829             curl_result="(ERROR:${curl_result})"
830           fi
831
832         fi
833       else
834         # repostate IS NOT ACTIVE OR READ_ONLY - no curl test required
835         curl_result="-"
836         url="-"
837       fi
838     fi
839
840     echo "$url ... $curl_result"
841     csv[i]="${csv[i]},${curl_result},${url}"
842     #echo "DBUG: csv line=${csv[i]}"
843
844     ((i++))
845   done
846
847   #
848   # csv column #17: release notes
849   #
850
851   readarray -t array < ../${repolist};
852   i=0
853   csv[i]="${csv[i]},release notes"
854   ((i++))
855   for line in "${array[@]}"
856   do
857     line=$(echo $line | sed 's:|.*$::')
858     #echo "DBUG: line=\"${line}\""
859     #echo "DBUG: i=${i}"
860     relnote=""
861
862     # put repo name in square brackets for increased grep hit rate
863     # escape minus and bracket characters to avoid problems with the grep command
864     #repo_grepable=$(echo ${line} | sed -r s:${line}:[${line}]: | sed -r 's/-/\\-/g' | sed -r 's/\[/\\[/g' | sed -r 's/\]/\\]/g')
865     #echo "DBUG: repo_grepable=\"${repo_grepable}\""
866
867     # check if repo dir exists in this branch
868     if [ -d ./${line} ] ; then
869       # if yes, check if repo name appears in the branch releasenotes.log
870       relnote=$(find "./${line}" -type f | grep 'release.*note.*.rst' | wc -l);
871       #echo "DBUG: relnote=${relnote}"
872       # repo dir DOES NOT exist in this branch - so check if repo dir exists in MASTER branch
873     elif [ -d ../master/${line} ] ; then
874       # if yes, check if repo name appears in the MASTER releasenotes.log
875       # count release notes files in MASTER branch (in repo root and its subdirectories)
876       relnote=$(find "../master/${line}" -type f | grep 'release.*note.*.rst' | wc -l);
877       #echo "DBUG: relnote=${relnote}"
878       # put results in round brackets to show that this is MASTER data
879       relnote=$(echo ${relnote} | sed -r s:${relnote}:\(${relnote}\):)
880     else
881       relnote="-"
882     fi
883     #echo "DBUG: relnote=${relnote}"
884
885     line="${csv[i]},${relnote}"
886     csv[i]=${line}
887     ((i++))
888
889   done
890   unset array
891   unset i
892   unset relnote
893   unset repo_grepable
894
895   #
896   # build the table.csv file
897   #
898
899   for i in "${csv[@]}"
900   do
901     echo "$i" | tee -a ./${branch}_table.csv
902   done
903
904   #
905   # create data package for this branch and zip it
906   #
907
908   datadir=${branch}_data
909   mkdir $datadir
910   cp $repolist $datadir
911   cp $wikiplsfile $datadir
912   cp ${branch}_table.csv $datadir
913   cp ${branch}_*.log $datadir
914   zip -r ${datadir}.zip $datadir
915
916   # return from the branch directory
917   cd ..
918
919 # return and work on the next requested branch ... or exit
920 done