Merge "Template updates - sections"
[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.7 (2021-04-12)"
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:\n"
370         find ./$reponame -type f -name index.rst | sed -r 's:./::' | sed -r s:${reponame}:[${reponame}]: | tee -a ${branch}_indexrst.log
371
372         printf "\nINFO.yaml files:\n"
373         find ./$reponame -type f -name INFO.yaml | sed -r 's:./::' | sed -r s:${reponame}:[${reponame}]: | tee -a ${branch}_infoyaml.log
374
375       fi
376
377     # end defcounter loop
378     fi
379
380     gitexitcode=""
381
382   done <${repolist}
383
384   # examine repos
385   drawline
386   find . -type f -name values.yaml -print -exec grep "image:" {} \; | sed -r 's:^ +::' | tee ${branch}_dockerimagesfull.log
387   drawline
388   ls --format single-column -d */ | sed 's:/$::' | tee ${branch}_directories.log
389   drawline
390   cat ${branch}_dockerimagesfull.log | grep image | sed -r 's:image\:::' | sed -r 's:^ +::' | sed '/^[[:space:]]*$/d' >${branch}_dockerimages.log
391   drawline
392   ls --format single-column -d oom/kubernetes/*/ | tee ${branch}_oomkubernetes.log
393   drawline
394
395   # examine docs
396   readarray -t docs_array < ./${branch}_docs.log;
397
398   for line in "${docs_array[@]}"
399   do
400
401     echo $line | tee -a ${branch}_docsconfig.log
402
403     # remove [ and ] which are distinguish the project name in the output
404     line=$(echo $line | sed -r 's:\[:: ; s:\]::')
405
406     if [ -f ./${line}/conf.py ] ; then
407       echo "  conf.py ..... found" | tee -a ${branch}_docsconfig.log
408     else
409       echo "  conf.py ..... NOT FOUND" | tee -a ${branch}_docsconfig.log
410     fi
411
412     if [ -f ./${line}/index.rst ] ; then
413       echo "  index.rst ... found" | tee -a ${branch}_docsconfig.log
414     else
415       echo "  index.rst ... NOT FOUND" | tee -a ${branch}_docsconfig.log
416     fi
417
418     if [ -f ./${line}/tox.ini ] ; then
419       echo "  tox.ini ..... found" | tee -a ${branch}_docsconfig.log
420     else
421       echo "  tox.ini ..... NOT FOUND" | tee -a ${branch}_docsconfig.log
422     fi
423
424     echo " " | tee -a ${branch}_docsconfig.log
425
426   done
427   unset docs_array
428
429   drawline
430
431   ###
432   ### build a csv table that combines results
433   ###
434
435   #
436   # csv column #1: project name
437   #
438
439   readarray -t array < ./${repolist};
440   i=0
441   csv[i]="project"
442   ((i++))
443   for line in "${array[@]}"
444   do
445     reponame=$(echo $line | awk -F "|" '{print $1}');
446     project=$(echo $reponame | sed 's:/.*$::')
447     #echo "DBUG: reponame=${reponame}"
448     #echo "DBUG:  project=${project}"
449     #echo "DBUG:        i=${i}"
450     csv[i]=${project}
451     ((i++))
452   done
453   unset array
454   unset i
455   unset reponame
456   unset project
457
458   #
459   # csv column #2: repo name
460   #
461
462   readarray -t array < ./${repolist};
463   i=0
464   csv[i]="${csv[i]},MASTER repo name"
465   ((i++))
466   for line in "${array[@]}"
467   do
468     reponame=$(echo $line | awk -F "|" '{print $1}');
469     csv[i]="${csv[i]},${reponame}"
470     ((i++))
471   done
472   unset array
473   unset i
474   unset reponame
475
476   #
477   # csv column #3: repo state
478   #
479
480   readarray -t array < ./${repolist};
481   i=0
482   csv[i]="${csv[i]},MASTER repo state"
483   ((i++))
484   for line in "${array[@]}"
485   do
486     repostate=$(echo $line | awk -F "|" '{print $2}');
487     csv[i]="${csv[i]},${repostate}"
488     ((i++))
489   done
490   unset array
491   unset i
492   unset repostate
493
494   #
495   # csv column #4: clone message
496   #
497
498   readarray -t array < ./${branch}_repoclone.log;
499   i=0
500   csv[i]="${csv[i]},${branch_upper} clone message"
501   ((i++))
502   for line in "${array[@]}"
503   do
504     # repoclone.log format:  $1=gitexitcode|$2=reponame|$3=repostate|$4=errormsg
505     errormsg=$(echo $line | awk -F "|" '{print $4}');
506     csv[i]="${csv[i]},${errormsg}"
507     ((i++))
508   done
509   unset array
510   unset i
511   unset errormsg
512
513   #
514   # csv column #5: latest branch
515   #
516
517   readarray -t array < ./${repolist};
518   i=0
519   csv[i]="${csv[i]},latest branch"
520   ((i++))
521   for line in "${array[@]}"
522   do
523     reponame=$(echo $line | awk -F "|" '{print $1}');
524     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);
525     #echo "DBUG:     reponame=${reponame}"
526     #echo "DBUG: latestbranch=${latestbranch}"
527     echo "latest available branch for repo \"${reponame}\" is \"${latestbranch}\""
528     csv[i]="${csv[i]},${latestbranch}"
529     ((i++))
530   done
531   unset array
532   unset i
533   unset reponame
534   unset latestbranch
535   
536   #
537   # csv column #6: INFO.yaml LC state (project lifecycle state based on INFO.yaml / per repo)
538   # csv column #7: WIKI LC state (project lifecycle state based on ONAP Dev Wiki / per project)
539   # csv column #8: LC state match shows a "match" if both LC states match
540   #
541
542   readarray -t array < ./${repolist};
543   i=0
544   csv[i]="${csv[i]},INFO.yaml LC state,WIKI LC state,LC state match"
545   ((i++))
546   for line in "${array[@]}"
547   do
548     reponame=$(echo $line | awk -F "|" '{print $1}');
549      project=$(echo $reponame | sed 's:/.*$::')
550
551     if [ -f ./${reponame}/INFO.yaml ] ; then
552       # check if repo/branch has a INFO.yaml
553       lifecycleproject=$(grep '^project: ' ./${reponame}/INFO.yaml | awk -F ":" '{print $2}' | sed 's:^ ::' | sed "s:'::g" | tr '[:upper:]' '[:lower:]' | sed 's/\r$//')
554       lifecyclestate=$(grep '^lifecycle_state: ' ./${reponame}/INFO.yaml | awk -F ":" '{print $2}' | sed 's:^ ::' | sed "s:'::g" | tr '[:upper:]' '[:lower:]' | sed 's/\r$//')
555     elif [ ${branch} != "master" ] && [ -f ../master/${reponame}/INFO.yaml ] ; then
556       # 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
557       #echo "DBUG: branch=${branch} - checking master for INFO.yaml"
558       lifecycleproject=$(grep '^project: ' ../master/${reponame}/INFO.yaml | awk -F ":" '{print $2}' | sed 's:^ ::' | sed "s:'::g" | tr '[:upper:]' '[:lower:]' | sed 's/\r$//')
559       lifecyclestate=$(grep '^lifecycle_state: ' ../master/${reponame}/INFO.yaml | awk -F ":" '{print $2}' | sed 's:^ ::' | sed "s:'::g" | tr '[:upper:]' '[:lower:]' | sed 's/\r$//')
560       lifecyclestate="(${lifecyclestate})"
561     else
562       lifecyclestate="INFO.yaml not found"
563     fi
564       
565     getwikilifecyclestate ${project}
566     # returns value in ${return_from_getwikilifecyclestate}
567
568     #echo "DBUG: working dir is ...";pwd
569     #echo "DBUG:   lifecycleproject=${lifecycleproject}"
570     #echo "DBUG:     lifecyclestate=${lifecyclestate}"
571     #echo "DBUG: wikilifecyclestate=${return_from_getwikilifecyclestate}"
572
573     #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
574     if [[ ${lifecyclestate} != "" ]] && [[ ${return_from_getwikilifecyclestate} != "" ]] && [[ ${lifecyclestate} == *"${return_from_getwikilifecyclestate}"* ]]; then
575       lcstatesmatch="match"
576     else
577       lcstatesmatch=""
578     fi 
579
580     csv[i]="${csv[i]},${lifecyclestate},${return_from_getwikilifecyclestate},${lcstatesmatch}"
581     ((i++))
582   done
583   unset array
584   unset i
585   unset reponame
586   unset project
587   unset lifecycleproject
588   unset lifecyclestate
589   unset lcstatesmatch
590
591   #
592   # csv column #9: RELEASE component (yes|maybe|unknown)
593   # to be filled with values of the planned release config file maintained by
594   # the onap release manager
595   #
596
597   # repoclone.log format:  $1=gitexitcode|$2=reponame|$3=repostate|$4=errormsg
598   readarray -t array < ./${branch}_repoclone.log;
599   i=0
600   csv[i]="${csv[i]},${branch_upper} component"
601   ((i++))
602   for line in "${array[@]}"
603   do
604
605     # repoclone.log format:  $1=gitexitcode|$2=reponame|$3=repostate|$4=errormsg
606     gitexitcode=$(echo $line | awk -F "|" '{print $1}');
607        reponame=$(echo $line | awk -F "|" '{print $2}');
608       repostate=$(echo $line | awk -F "|" '{print $3}');
609        errormsg=$(echo $line | awk -F "|" '{print $4}');
610
611     if [[ ${repostate} == "ACTIVE" && ${gitexitcode} == "0" ]]; then
612       releasecomponent="yes"
613     elif [ ${repostate} == "ACTIVE" ]; then
614     #elif [[ ${repostate} == "ACTIVE" && ${gitexitcode} == "128" ]]; then
615       releasecomponent="maybe"
616     elif [[ ${repostate} == "READ_ONLY" && ${gitexitcode} == "0" ]]; then
617       releasecomponent="yes"
618     elif [ ${repostate} == "READ_ONLY" ]; then
619       releasecomponent="maybe"
620     else
621       releasecomponent="unknown"
622     fi
623
624     csv[i]="${csv[i]},${releasecomponent}"
625     ((i++))
626   done
627   unset array
628   unset i
629   unset gitexitcode
630   unset reponame
631   unset repostate
632   unset errormsg
633   unset releasecomponent
634
635   #
636   # csv column #10: docs (at repo root directory only; no recursive search!)
637   # csv column #11: conf.py
638   # csv column #12: tox.ini
639   # csv column #13: index.rst
640   #
641   # columns are filled with values from requested branch.
642   # if data is not available values from master branch are used.
643   # to identify master branch values, data is put into round brackets "(...)"
644   #
645
646   readarray -t array < ./${repolist};
647   i=0
648   csv[$i]="${csv[i]},docs,conf.py,tox.ini,index.rst"
649   ((i++))
650   for line in "${array[@]}"
651   do
652     line=$(echo $line | sed 's:|.*$::')
653     #echo "DBUG: line=${line}"
654     #echo "DBUG: i=${i}"
655
656     # docs
657     if [ -d ./${line}/docs ] ; then
658       docs="docs"
659     elif [ -d ../master/${line}/docs ] ; then
660       docs="(docs)"
661     else
662       docs="-"
663     fi
664
665     # conf.py
666     if [ -f ./${line}/docs/conf.py ] ; then
667       docs="${docs},conf.py"
668     elif [ -f ../master/${line}/docs/conf.py ] ; then
669       docs="${docs},(conf.py)"
670     else
671       docs="${docs},-"
672     fi
673
674     # tox.ini (check docs dir and also check project root dir)
675     if [ -f ./${line}/docs/tox.ini ] || [ -f ./${line}/tox.ini ]; then
676       docs="${docs},tox.ini"
677       # tox.ini @ branch/docs dir
678       if [ -f ./${line}/docs/tox.ini ] ; then
679         docs="${docs} @docs"
680       fi
681       # tox.ini @ branch/project root dir
682       if [ -f ./${line}/tox.ini ] ; then
683         docs="${docs} @root"
684       fi
685     elif [ -f ../master/${line}/docs/tox.ini ] || [ -f ../master/${line}/tox.ini ]; then
686       docs="${docs},(tox.ini"
687       # tox.ini @ master/docs dir
688       if [ -f ../master/${line}/docs/tox.ini ] ; then
689         docs="${docs} @docs"
690       fi
691       # tox.ini @ master/project root dir
692       if [ -f ../master/${line}/tox.ini ] ; then
693         docs="${docs} @root"
694       fi   
695       # just add a round bracket at the end of the value
696       docs="${docs})"
697     else
698       # no tox.ini found in docs or root dir
699       docs="${docs},-"
700     fi
701
702     # index.rst
703     if [ -f ./${line}/docs/index.rst ] ; then
704       docs="${docs},index.rst"
705     elif [ -f ../master/${line}/docs/index.rst ] ; then
706       docs="${docs},(index.rst)"
707     else
708       docs="${docs},-"
709     fi
710
711     #echo "DBUG: docs=${docs}"
712     line="${csv[i]},${docs}"
713     csv[$i]=${line}
714     ((i++))
715   done
716   unset array
717   unset i
718   unset docs
719
720   #
721   # csv column #14: index.html@RTD accessibility check
722   # csv column #15: index.html url
723   #
724
725   readarray -t array < ./${branch}_repoclone.log;
726   i=0
727   csv[i]="${csv[i]},index.html@RTD,index.html url"
728   ((i++))
729   for line in "${array[@]}"
730   do
731     # repoclone.log format:  $1=gitexitcode|$2=reponame|$3=repostate|$4=errormsg
732     gitexitcode=$(echo $line | awk -F "|" '{print $1}');
733        reponame=$(echo $line | awk -F "|" '{print $2}');
734       repostate=$(echo $line | awk -F "|" '{print $3}');
735        errormsg=$(echo $line | awk -F "|" '{print $4}');
736
737             url=""
738     curl_result=""
739
740     # this script works only with release "frankfurt" and later because
741     # earlier releases are using submodule structure for documentation files
742     if echo "$branch" | grep -q '^[abcde]'; then
743       curl_result="unsupported release"
744       url="-"
745     else
746
747       # we are working on "frankfurt" branch or later ...
748       if [[ ${repostate} == "ACTIVE" ]] || [[ ${repostate} == "READ_ONLY" ]]; then
749
750         # OPTIONAL: USE ALSO GITEXITCODE AS A FILTER CRITERIA ???
751
752         # url base
753         # important! only doc project needs a different url base
754         if [[ ${reponame} == "doc" ]]; then
755           url_start="https://docs.onap.org"
756         else
757           url_start="https://docs.onap.org/projects/onap"
758         fi
759         url_lang="en"
760         url_branch=${branch}
761
762         # "master" branch documentation is available as "latest" in RTD
763         if [[ ${url_branch} == "master" ]]; then
764           url_branch="latest"
765         fi
766
767         # replace all / characters in repo name with - charachter
768         url_repo=$(echo ${reponame} | sed -r 's/\//-/g')
769         url_file="index.html"
770
771         # build the full url
772         if [[ ${reponame} == "doc" ]]; then
773           # build the full url for the doc project
774           url="${url_start}/${url_lang}/${url_branch}/${url_file}"
775         else
776           # build the full url for the other projects
777           url="${url_start}-${url_repo}/${url_lang}/${url_branch}/${url_file}"
778         fi
779         #echo "DBUG: url=$url"
780
781         # test accessibility of url
782         curl --head --silent --fail "${url}?${unique}" >/dev/null
783         curl_result=$?
784
785         # convert numeric results to text
786         if [ "${curl_result}" = "0" ]; then
787           curl_result="accessible"
788         elif [ "${curl_result}" = "22" ]; then
789           curl_result="does not exist"
790         else
791           curl_result="ERROR:${curl_result}"
792         fi
793
794         # url does not exist for this branch.
795         # in case the requested url is not already for "master" branch,
796         # we try to access the url of the master branch and denote the
797         # result by using round brackets (result)
798         if [[ ${curl_result} == "does not exist" && ! $branch == "master" ]]; then
799
800           # build the full (master/latest) url
801           url="${url_start}-${url_repo}/${url_lang}/latest/${url_file}"
802           #echo "DBUG: url=$url"
803
804           # test accessibility of url in "master branch" (latest)
805           curl --head --silent --fail "${url}?${unique}" >/dev/null
806           curl_result=$?
807           # denote result as a value from "master" branch (latest)
808           url="(${url})"
809
810           # convert numeric results to text
811           if [ "${curl_result}" = "0" ]; then
812             curl_result="(accessible)"
813           elif [ "${curl_result}" = "22" ]; then
814             curl_result="(does not exist)"
815           else
816             curl_result="(ERROR:${curl_result})"
817           fi
818
819         fi
820       else
821         # repostate IS NOT ACTIVE OR READ_ONLY - no curl test required
822         curl_result="-"
823         url="-"
824       fi
825     fi
826
827     echo "$url ... $curl_result"
828     csv[i]="${csv[i]},${curl_result},${url}"
829     #echo "DBUG: csv line=${csv[i]}"
830
831     ((i++))
832   done
833
834   #
835   # csv column #16: release notes
836   #
837
838   readarray -t array < ../${repolist};
839   i=0
840   csv[i]="${csv[i]},release notes"
841   ((i++))
842   for line in "${array[@]}"
843   do
844     line=$(echo $line | sed 's:|.*$::')
845     #echo "DBUG: line=\"${line}\""
846     #echo "DBUG: i=${i}"
847     relnote=""
848
849     # put repo name in square brackets for increased grep hit rate
850     # escape minus and bracket characters to avoid problems with the grep command
851     #repo_grepable=$(echo ${line} | sed -r s:${line}:[${line}]: | sed -r 's/-/\\-/g' | sed -r 's/\[/\\[/g' | sed -r 's/\]/\\]/g')
852     #echo "DBUG: repo_grepable=\"${repo_grepable}\""
853
854     # check if repo dir exists in this branch
855     if [ -d ./${line} ] ; then
856       # if yes, check if repo name appears in the branch releasenotes.log
857       relnote=$(find "./${line}" -type f | grep 'release.*note.*.rst' | wc -l);
858       #echo "DBUG: relnote=${relnote}"
859       # repo dir DOES NOT exist in this branch - so check if repo dir exists in MASTER branch
860     elif [ -d ../master/${line} ] ; then
861       # if yes, check if repo name appears in the MASTER releasenotes.log
862       # count release notes files in MASTER branch (in repo root and its subdirectories)
863       relnote=$(find "../master/${line}" -type f | grep 'release.*note.*.rst' | wc -l);
864       #echo "DBUG: relnote=${relnote}"
865       # put results in round brackets to show that this is MASTER data
866       relnote=$(echo ${relnote} | sed -r s:${relnote}:\(${relnote}\):)
867     else
868       relnote="-"
869     fi
870     #echo "DBUG: relnote=${relnote}"
871
872     line="${csv[i]},${relnote}"
873     csv[i]=${line}
874     ((i++))
875
876   done
877   unset array
878   unset i
879   unset relnote
880   unset repo_grepable
881
882   #
883   # build the table.csv file
884   #
885
886   for i in "${csv[@]}"
887   do
888     echo "$i" | tee -a ./${branch}_table.csv
889   done
890
891   #
892   # create data package for this branch and zip it
893   #
894
895   datadir=${branch}_data
896   mkdir $datadir
897   cp $repolist $datadir
898   cp $wikiplsfile $datadir
899   cp ${branch}_table.csv $datadir
900   cp ${branch}_*.log $datadir
901   zip -r ${datadir}.zip $datadir
902
903   # return from the branch directory
904   cd ..
905
906 # return and work on the next requested branch ... or exit
907 done