update doc tools to reflect changes in project lifecycle states
[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.11 (2021-10-18)"
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 # function to parse release partizipation information
149 # call:   getrpinfo "projectname"
150 # result: $return_from_getrpinfo
151 # because bash supports only returning numeric values a variable $return_from_getrpinfo is used
152
153 function getrpinfo {
154
155   local requested=$1
156
157   # clean up first
158   local rpdetails=""
159   local rpline=""
160   local rprepo=""
161   local rpproject=""
162   local current_branch_starting_letter=""
163         return_from_getrpinfo=""
164
165   # finds first matching line in the array using grep (currently every line shows the same partizipation for the project (NOT repository!) )
166   # this is much faster then looping line by line
167      rpline=$(IFS=$'\n'; echo "${rparray[*]}" | grep -m 1 ";${requested};");
168      rpline=$(echo ${rpline} | tr -d '^M')
169      rprepo=$(echo ${rpline} | awk -F ";" '{print $1}');
170   rpproject=$(echo ${rpline} | awk -F ";" '{print $2}');
171   # concatenate details to do an easy grep later on to find out if or if not the project/repo has partizipated to a release
172   rpdetails=$(echo ${rpline} | awk -F ";" '{print "-" $3 "-" $4 "-" $5 "-" $6 "-" $7 "-" $8 "-" $9 "-" $10 "-" $11 "-" $12 "-"}');
173
174   # result will be e.g. "-g" and this avoids false positives with the "m" release
175   # (because "m" is also used to indicate the maintenance release, e.g. "gm")
176   current_branch_starting_letter="-${branch:0:1}"
177
178   #echo "DBUG: getrpinfo ****************************";
179   #echo "DBUG: getrpinfo requested = \"${requested}\"";
180   #echo "DBUG: getrpinfo rpproject = \"${rpproject}\"";
181   #echo "DBUG: getrpinfo rpdetails = \"${rpdetails}\"";
182   #echo "DBUG:      current branch = \"${branch}\"";
183   #echo "DBUG:     starting_letter = \"${current_branch_starting_letter}\"";
184
185   ## check if PROJECT has partizipated to INITIAL release
186   #if [[ ${rpproject} = ${requested} ]] && [[ "${rpdetails}" == *"${current_branch_starting_letter}-"* ]]; then
187   #  return_from_getrpinfo="project | ${current_branch_starting_letter:1:1}"
188   #  # check ADDITIONALLY if PROJECT has ALSO partizipated to MAINTENANCE release
189   #  if [[ "${rpdetails}" == *"${current_branch_starting_letter}m-"* ]]; then
190   #    return_from_getrpinfo="${return_from_getrpinfo} | ${current_branch_starting_letter:1:1}m"
191   #    #echo "DBUG:  getrpinfo return = \"${return_from_getrpinfo}\"";
192   #  fi
193   #  return 0;
194   ## check if PROJECT has ONLY partizipated to MAINTENANCE release
195   #elif [[ ${rpproject} = ${requested} ]] && [[ "${rpdetails}" == *"${current_branch_starting_letter:1:1}m-"* ]]; then
196   #  return_from_getrpinfo="project | ${current_branch_starting_letter:1:1}m"
197   #  #echo "DBUG:  getrpinfo return = \"${return_from_getrpinfo}\"";
198   #  return 0;
199   #fi
200
201   # check if requested PROJECT was found in the array of partizipating projects
202   if [[ ${rpproject} = ${requested} ]]; then
203     # check if PROJECT has partizipated to INITIAL release
204     if [[ "${rpdetails}" == *"${current_branch_starting_letter}-"* ]]; then
205       return_from_getrpinfo="project | ${current_branch_starting_letter:1:1}"
206       # check ADDITIONALLY if PROJECT has ALSO partizipated to MAINTENANCE release
207       if [[ "${rpdetails}" == *"${current_branch_starting_letter}m-"* ]]; then
208       return_from_getrpinfo="${return_from_getrpinfo} ${current_branch_starting_letter:1:1}m"
209       #echo "DBUG:  getrpinfo return = \"${return_from_getrpinfo}\"";
210       fi
211       return 0;
212     elif [[ "${rpdetails}" == *"${current_branch_starting_letter:1:1}m-"* ]]; then
213       return_from_getrpinfo="project | ${current_branch_starting_letter:1:1}m"
214       #echo "DBUG:  getrpinfo return = \"${return_from_getrpinfo}\"";
215       return 0;
216     fi
217   fi
218   #echo "DBUG: getrpinfo requested \"${requested}\" NOT FOUND in list"
219   return_from_getrpinfo=""
220 }
221
222 ###
223 ### arguments handling
224 ###
225
226 PARAMS=""
227
228 while (( "$#" )); do
229   case "$1" in
230     -d|--dev)
231       devmode="TRUE"
232       shift
233       ;;
234     -b|--branches)
235       if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then
236         branches_csv=$2
237         shift 2
238       else
239         echo "Error: Argument for $1 is missing" >&2
240         usage
241         exit 1
242       fi
243       ;;
244     -u|--user)
245       if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then
246         lfusername=$2
247         shift 2
248       else
249         echo "Error: Argument for $1 is missing" >&2
250         usage
251         exit 1
252       fi
253         ;;
254     -*|--*=) # unsupported flags
255       echo "Error: Unsupported argument $1" >&2
256       usage
257       exit 1
258       ;;
259     *) # preserve positional arguments
260       PARAMS="$PARAMS $1"
261       shift
262       ;;
263   esac
264 done
265
266 # set positional arguments in their proper place
267 eval set -- "$PARAMS"
268
269 # old: declare -a branches=("master" "frankfurt" "guilin")
270 if [[ $branches_csv == "" || $lfusername == "" ]]; then
271   usage
272   exit -1
273 fi
274
275 # master branch is automatically added and must not part of the user arguments
276 if [[ $branches_csv == *"master"* ]]; then
277   usage
278   exit -1
279 fi
280 # clone master first, then the other branches
281 branches_csv="master,${branches_csv}"
282
283 # create the branches array by readinging in the values from the variable
284 IFS=',' read -r -a branches <<< "${branches_csv}"
285
286 #echo "DBUG: devmode      = \"${devmode}\""
287 #echo "DBUG: branches_csv = \"${branches_csv}\""
288 #echo "DBUG: lfusername   = \"${lfusername}\""
289 #echo "DBUG: branches     = \"${branches[@]}\""
290
291 # restart script with logging enabled
292 lockfile="checkdocs-runtime-lockfile"
293 if [ ! -f $lockfile ] ; then
294   touch $lockfile
295   echo "Restarting script with logging enabled."
296   ${fullcommand} 2>&1 | tee checkdocs.log
297   rm $lockfile
298   exit
299 fi
300
301 echo " "
302 echo "checkdocs.sh Version ${script_version}"
303 echo " "
304
305 #
306 # read in wiki (project) lifecycle state
307 # always use the lastest available file (derived from date in filename e.g. wiki_lifecycle_state_210409.txt)
308 # format is <reponame abbrev>;<state>;<reponame full>
309 #
310
311 wikiplsfile=$(ls | sed -nr '/wiki_lifecycle_state_[0-9]{6}.txt/Ip' | tail -1);
312 if [[ $wikiplsfile == "" ]]; then
313   echo "ERROR: wiki_lifecycle_state_yymmdd.txt missing"
314   exit -1
315 fi
316 echo "Using \"${wikiplsfile}\" as the source for wiki (project) lifecycle state information."
317 readarray -t wikiplsarray < ./${wikiplsfile};
318
319 #
320 # read in release_partizipation_YYMMDD.csv file
321 # always use the latest available file (derived from date in filename e.g. release_partizipation_210409.csv)
322 # format is: $1=repository;$2=project;$3=g;$4=gm;$5=h;$6=hm;$7=i;$8=im;$9=j;$10=jm;$11=k;$12=km;;;;
323 # example: "g"  = project partizipated to the (g)uilin release
324 #          "gm" = project partizipated to the (g)uilin (m)aintenance release
325 # file may contain windows control charaters at end of line (^M)
326 #
327
328 rpfile=$(ls | sed -nr '/release_partizipation_[0-9]{6}.csv/Ip' | tail -1);
329 if [[ $rpfile == "" ]]; then
330   echo "ERROR: release_partizipation_yymmdd.csv missing"
331   exit -1
332 fi
333 echo "Using \"${rpfile}\" as the source for release partizipation information."
334 readarray -t rparray < ./${rpfile};
335 # remove first line
336 rparray=("${rparray[@]:1}")
337 #printf '%s\n' "${rparray[@]}" #DBUG ONLY
338
339 #
340 # curl must be installed
341 #
342
343 if ! command -v curl &> /dev/null
344 then
345   echo "ERROR: curl command could not be found"
346   exit -1
347 fi
348
349 today=$(date '+%Y-%m-%d');
350 repolist="gerrit-repos-master-"$today".txt";
351 unique=$(date +%s)
352
353 echo "Retrieving a full list of ONAP repositories (master) from gerrit.onap.org."
354
355 #
356 # retrieve the full repolist from gerrit
357 # workaround because of the (wrong?) response of gerrit.onap.org which makes jq command fail
358 # "| awk '{if(NR>1)print}'" filters the first line of the response so that jq will work again (thx marek)
359 #
360
361 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
362
363 # process the created repolist and try to clone the projects from the mirror
364
365 source="git://cloud.onap.org/mirror"
366 echo "Using \"${source}\" as the source and username \"${lfusername}\" for cloning the repositories."
367 echo "Start cloning of repositories ..."
368
369 for branch in "${branches[@]}"
370 do
371
372   echo " "
373   echo "###"
374   echo "### ${branch}"
375   echo "###"
376   echo " "
377
378   branch_upper=$(echo "${branch}" | tr '[:lower:]' '[:upper:]')
379
380   mkdir $branch
381   cp $repolist $branch
382   cd $branch
383
384   devcounter=0
385
386   # process repolist
387   while read line
388   do
389
390   if [[ $devmode == "TRUE" ]]; then
391     devcounter=$((devcounter+1))
392   fi
393
394   if [[ $devcounter -lt "50" ]]; then
395
396       if [[ $devmode == "TRUE" ]]; then
397         echo "INFO: devmode! counter=${devcounter}"
398       fi
399
400       drawline
401       reponame=$(echo $line | awk -F "|" '{print $1}');
402       repostate=$(echo $line | awk -F "|" '{print $2}');
403       echo $reponame
404       echo $repostate
405
406       if [[ $repostate == "ACTIVE" ]] || [[ $repostate == "READ_ONLY" ]]; then
407         echo "Cloning \"${branch}\" branch of \"${repostate}\" project ${reponame}..."
408
409         # previously used:   git clone --branch ${branch} --recurse-submodules ssh://${lfusername}@gerrit.onap.org:29418/$reponame ./$reponame
410         # clone script Jess: git clone "git://cloud.onap.org/mirror/${i}" "${LOCALNAME}"
411         git clone --branch ${branch} --recurse-submodules ${source}/${reponame} ./${reponame}
412         gitexitcode=$?
413
414         if [[ ! ${gitexitcode} == "0" ]]; then
415           errormsg=$(tail -1 ../checkdocs.log)
416         else
417           errormsg="cloned"
418         fi
419
420         # repoclone.log format:  $1=gitexitcode|$2=reponame|$3=repostate|$4=errormsg
421         echo "${gitexitcode}|${reponame}|${repostate}|${errormsg}" | tee -a ${branch}_repoclone.log
422
423       #elif [[ $repostate == "READ_ONLY" ]]; then
424         #echo "-|${reponame}|${repostate}|ignored" | tee -a ${branch}_repoclone.log
425       else
426         echo "-|${reponame}|unknown repo state \"${repostate}\"|-" | tee -a ${branch}_repoclone.log
427       fi
428
429       # examine repo
430       if [[ ${gitexitcode} == "0" ]]; then
431
432         printf "\ndocs directories:\n"
433         find ./$reponame -type d -name docs | sed -r 's:./::' | sed -r s:${reponame}:[${reponame}]: | tee -a ${branch}_docs.log
434
435         printf "\nrst files:\n"
436         find ./$reponame -type f -name *.rst | sed -r 's:./::' | sed -r s:${reponame}:[${reponame}]: | tee -a ${branch}_rstfiles.log
437
438         printf "\nrelease notes rst:\n"
439         find ./$reponame -type f | grep '.*release.*note.*.rst' | sed -r 's:./::' | sed -r s:${reponame}:[${reponame}]: | tee -a ${branch}_releasenotes.log
440
441         printf "\ntox.ini files:\n"
442         find ./$reponame -type f -name tox.ini | sed -r 's:./::' | sed -r s:${reponame}:[${reponame}]: | tee -a ${branch}_toxini.log
443
444         printf "\nconf.py files:\n"
445         find ./$reponame -type f -name conf.py | sed -r 's:./::' | sed -r s:${reponame}:[${reponame}]: | tee -a ${branch}_confpy.log
446
447         printf "\nindex.rst files (all):\n"
448         find ./$reponame -type f -name index.rst | sed -r 's:./::' | sed -r s:${reponame}:[${reponame}]: | tee -a ${branch}_indexrst_all.log
449
450         printf "\nindex.rst files (docs root directory):\n"
451         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
452
453         printf "\nINFO.yaml files:\n"
454         find ./$reponame -type f -name INFO.yaml | sed -r 's:./::' | sed -r s:${reponame}:[${reponame}]: | tee -a ${branch}_infoyaml.log
455
456       fi
457
458     # end defcounter loop
459     fi
460
461     gitexitcode=""
462
463   done <${repolist}
464
465   # get (first) title for a rst file
466   drawline
467   python3 ../getrsttitle.py ${branch}_rstfiles.log | tee ${branch}_rstfiles_titles.log
468   drawline
469   python3 ../getrsttitle.py ${branch}_indexrst_docs_root.log | tee ${branch}_indexrst_docs_root_titles.log
470
471   # examine repos
472   drawline
473   find . -type f -name values.yaml -print -exec grep "image:" {} \; | sed -r 's:^ +::' | tee ${branch}_dockerimagesfull.log
474   drawline
475   ls --format single-column -d */ | sed 's:/$::' | tee ${branch}_directories.log
476   drawline
477   cat ${branch}_dockerimagesfull.log | grep image | sed -r 's:image\:::' | sed -r 's:^ +::' | sed '/^[[:space:]]*$/d' >${branch}_dockerimages.log
478   drawline
479   ls --format single-column -d oom/kubernetes/*/ | tee ${branch}_oomkubernetes.log
480   drawline
481
482   # examine docs
483   readarray -t docs_array < ./${branch}_docs.log;
484
485   for line in "${docs_array[@]}"
486   do
487
488     echo $line | tee -a ${branch}_docsconfig.log
489
490     # remove [ and ] which are distinguish the project name in the output
491     line=$(echo $line | sed -r 's:\[:: ; s:\]::')
492
493     if [ -f ./${line}/conf.py ] ; then
494       echo "  conf.py ..... found" | tee -a ${branch}_docsconfig.log
495     else
496       echo "  conf.py ..... NOT FOUND" | tee -a ${branch}_docsconfig.log
497     fi
498
499     if [ -f ./${line}/index.rst ] ; then
500       echo "  index.rst ... found" | tee -a ${branch}_docsconfig.log
501     else
502       echo "  index.rst ... NOT FOUND" | tee -a ${branch}_docsconfig.log
503     fi
504
505     if [ -f ./${line}/tox.ini ] ; then
506       echo "  tox.ini ..... found" | tee -a ${branch}_docsconfig.log
507     else
508       echo "  tox.ini ..... NOT FOUND" | tee -a ${branch}_docsconfig.log
509     fi
510
511     echo " " | tee -a ${branch}_docsconfig.log
512
513   done
514   unset docs_array
515
516   drawline
517
518   ###
519   ### build a csv table that combines results
520   ###
521
522   #
523   # csv column #1: project name
524   #
525
526   readarray -t array < ./${repolist};
527   i=0
528   csv[i]="project"
529   ((i++))
530   for line in "${array[@]}"
531   do
532     reponame=$(echo $line | awk -F "|" '{print $1}');
533     project=$(echo $reponame | sed 's:/.*$::')
534     #echo "DBUG: reponame=${reponame}"
535     #echo "DBUG:  project=${project}"
536     #echo "DBUG:        i=${i}"
537     csv[i]=${project}
538     ((i++))
539   done
540   unset array
541   unset i
542   unset reponame
543   unset project
544
545   #
546   # csv column #2: repo name
547   #
548
549   readarray -t array < ./${repolist};
550   i=0
551   csv[i]="${csv[i]},MASTER repo name"
552   ((i++))
553   for line in "${array[@]}"
554   do
555     reponame=$(echo $line | awk -F "|" '{print $1}');
556     csv[i]="${csv[i]},${reponame}"
557     ((i++))
558   done
559   unset array
560   unset i
561   unset reponame
562
563   #
564   # csv column #3: repo state
565   #
566
567   readarray -t array < ./${repolist};
568   i=0
569   csv[i]="${csv[i]},MASTER repo state"
570   ((i++))
571   for line in "${array[@]}"
572   do
573     repostate=$(echo $line | awk -F "|" '{print $2}');
574     csv[i]="${csv[i]},${repostate}"
575     ((i++))
576   done
577   unset array
578   unset i
579   unset repostate
580
581   #
582   # csv column #4: clone message
583   #
584
585   readarray -t array < ./${branch}_repoclone.log;
586   i=0
587   csv[i]="${csv[i]},${branch_upper} clone message"
588   ((i++))
589   for line in "${array[@]}"
590   do
591     # repoclone.log format:  $1=gitexitcode|$2=reponame|$3=repostate|$4=errormsg
592     errormsg=$(echo $line | awk -F "|" '{print $4}');
593     csv[i]="${csv[i]},${errormsg}"
594     ((i++))
595   done
596   unset array
597   unset i
598   unset errormsg
599
600   #
601   # csv column #5: latest branch
602   #
603
604   readarray -t array < ./${repolist};
605   i=0
606   csv[i]="${csv[i]},latest branch"
607   ((i++))
608   for line in "${array[@]}"
609   do
610     reponame=$(echo $line | awk -F "|" '{print $1}');
611     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);
612     #echo "DBUG:     reponame=${reponame}"
613     #echo "DBUG: latestbranch=${latestbranch}"
614     echo "latest available branch for repo \"${reponame}\" is \"${latestbranch}\""
615     csv[i]="${csv[i]},${latestbranch}"
616     ((i++))
617   done
618   unset array
619   unset i
620   unset reponame
621   unset latestbranch
622
623   #
624   # csv column #6: INFO.yaml LC state (project lifecycle state based on INFO.yaml / per repo)
625   # csv column #7: WIKI LC state (project lifecycle state based on ONAP Dev Wiki / per project)
626   # csv column #8: LC state match shows a "match" if both LC states match
627   #
628
629   readarray -t array < ./${repolist};
630   i=0
631   csv[i]="${csv[i]},INFO.yaml LC state,WIKI LC state,LC state match"
632   ((i++))
633   for line in "${array[@]}"
634   do
635     reponame=$(echo $line | awk -F "|" '{print $1}');
636      project=$(echo $reponame | sed 's:/.*$::')
637
638     if [ -f ./${reponame}/INFO.yaml ] ; then
639       # check if repo/branch has a INFO.yaml
640       lifecycleproject=$(grep '^project: ' ./${reponame}/INFO.yaml | awk -F ":" '{print $2}' | sed 's:^ ::' | sed "s:'::g" | tr '[:upper:]' '[:lower:]' | sed 's/\r$//')
641       lifecyclestate=$(grep '^lifecycle_state: ' ./${reponame}/INFO.yaml | awk -F ":" '{print $2}' | sed 's:^ ::' | sed "s:'::g" | tr '[:upper:]' '[:lower:]' | sed 's/\r$//')
642     elif [ ${branch} != "master" ] && [ -f ../master/${reponame}/INFO.yaml ] ; then
643       # 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
644       #echo "DBUG: branch=${branch} - checking master for INFO.yaml"
645       lifecycleproject=$(grep '^project: ' ../master/${reponame}/INFO.yaml | awk -F ":" '{print $2}' | sed 's:^ ::' | sed "s:'::g" | tr '[:upper:]' '[:lower:]' | sed 's/\r$//')
646       lifecyclestate=$(grep '^lifecycle_state: ' ../master/${reponame}/INFO.yaml | awk -F ":" '{print $2}' | sed 's:^ ::' | sed "s:'::g" | tr '[:upper:]' '[:lower:]' | sed 's/\r$//')
647       lifecyclestate="(${lifecyclestate})"
648     else
649       lifecyclestate="INFO.yaml not found"
650     fi
651
652     getwikilifecyclestate ${project}
653     # returns value in ${return_from_getwikilifecyclestate}
654
655     #echo "DBUG: working dir is ...";pwd
656     #echo "DBUG:   lifecycleproject=${lifecycleproject}"
657     #echo "DBUG:     lifecyclestate=${lifecyclestate}"
658     #echo "DBUG: wikilifecyclestate=${return_from_getwikilifecyclestate}"
659
660     #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
661     if [[ ${lifecyclestate} != "" ]] && [[ ${return_from_getwikilifecyclestate} != "" ]] && [[ ${lifecyclestate} == *"${return_from_getwikilifecyclestate}"* ]]; then
662       lcstatesmatch="match"
663     else
664       lcstatesmatch=""
665     fi
666
667     csv[i]="${csv[i]},${lifecyclestate},${return_from_getwikilifecyclestate},${lcstatesmatch}"
668     ((i++))
669   done
670   unset array
671   unset i
672   unset reponame
673   unset project
674   unset lifecycleproject
675   unset lifecyclestate
676   unset lcstatesmatch
677
678   #
679   # csv column #9: RELEASE component (yes|maybe|unknown)
680   # to be filled with values of the planned release config file maintained by
681   # the onap release manager
682   # NOT FUNCTIONAL YET
683
684   # repoclone.log format:  $1=gitexitcode|$2=reponame|$3=repostate|$4=errormsg
685   readarray -t array < ./${branch}_repoclone.log;
686   i=0
687   csv[i]="${csv[i]},${branch_upper} component"
688   ((i++))
689   for line in "${array[@]}"
690   do
691
692     # repoclone.log format:  $1=gitexitcode|$2=reponame|$3=repostate|$4=errormsg
693     gitexitcode=$(echo $line | awk -F "|" '{print $1}');
694        reponame=$(echo $line | awk -F "|" '{print $2}');
695       repostate=$(echo $line | awk -F "|" '{print $3}');
696        errormsg=$(echo $line | awk -F "|" '{print $4}');
697
698     #if [[ ${repostate} == "ACTIVE" && ${gitexitcode} == "0" ]]; then
699     #  releasecomponent="yes"
700     #elif [ ${repostate} == "ACTIVE" ]; then
701     ##elif [[ ${repostate} == "ACTIVE" && ${gitexitcode} == "128" ]]; then
702     #  releasecomponent="maybe"
703     #elif [[ ${repostate} == "READ_ONLY" && ${gitexitcode} == "0" ]]; then
704     #  releasecomponent="yes"
705     #elif [ ${repostate} == "READ_ONLY" ]; then
706     #  releasecomponent="maybe"
707     #else
708     #  releasecomponent="unknown"
709     #fi
710
711     # not functional yet!
712     releasecomponent=""
713
714     csv[i]="${csv[i]},${releasecomponent}"
715     ((i++))
716   done
717   unset array
718   unset i
719   unset gitexitcode
720   unset reponame
721   unset repostate
722   unset errormsg
723   unset releasecomponent
724
725   #
726   # csv column #10: RELEASE partizipation
727   #
728
729   # repoclone.log format:  $1=gitexitcode|$2=reponame|$3=repostate|$4=errormsg
730   readarray -t array < ./${branch}_repoclone.log;
731   i=0
732   csv[i]="${csv[i]},${branch_upper} partizipation"
733   ((i++))
734   echo "INFO: determine release partizipation for project ..."
735   for line in "${array[@]}"
736   do
737
738     # repoclone.log format:  $1=gitexitcode|$2=reponame|$3=repostate|$4=errormsg
739     gitexitcode=$(echo $line | awk -F "|" '{print $1}');
740        reponame=$(echo $line | awk -F "|" '{print $2}');
741       repostate=$(echo $line | awk -F "|" '{print $3}');
742        errormsg=$(echo $line | awk -F "|" '{print $4}');
743     projectname=$(echo $reponame | sed 's:/.*$::')
744
745     if [[ $branch == "master" ]]; then
746       return_from_getrpinfo="";
747     else
748       #echo "DBUG: calling getrpinfo for projectname ${projectname}"
749       getrpinfo ${projectname}
750     fi
751
752     csv[i]="${csv[i]},${return_from_getrpinfo}"
753     ((i++))
754
755   done
756
757   unset array
758   unset i
759   unset gitexitcode
760   unset reponame
761   unset repostate
762   unset errormsg
763   unset projectname
764   unset return_from_getrpinfo
765
766   #
767   # csv column #11: docs (at repo root directory only; no recursive search!)
768   # csv column #12: conf.py
769   # csv column #13: tox.ini
770   # csv column #14: index.rst
771   # csv column #15: first title in index.rst
772   #
773   # columns are filled with values from requested branch.
774   # if data is not available values from master branch are used.
775   # to identify master branch values, data is put into round brackets "(...)"
776   #
777
778   readarray -t array < ./${repolist};
779   i=0
780   csv[$i]="${csv[i]},docs,conf.py,tox.ini,index.rst,first title in index.rst"
781   ((i++))
782   for line in "${array[@]}"
783   do
784     line=$(echo $line | sed 's:|.*$::')
785     #echo "DBUG: line=${line}"
786     #echo "DBUG: i=${i}"
787
788     # docs
789     if [ -d ./${line}/docs ] ; then
790       docs="docs"
791     elif [ -d ../master/${line}/docs ] ; then
792       docs="(docs)"
793     else
794       docs="-"
795     fi
796
797     # conf.py
798     if [ -f ./${line}/docs/conf.py ] ; then
799       docs="${docs},conf.py"
800     elif [ -f ../master/${line}/docs/conf.py ] ; then
801       docs="${docs},(conf.py)"
802     else
803       docs="${docs},-"
804     fi
805
806     # tox.ini (check docs dir and also check project root dir)
807     if [ -f ./${line}/docs/tox.ini ] || [ -f ./${line}/tox.ini ]; then
808       docs="${docs},tox.ini"
809       # tox.ini @ branch/docs dir
810       if [ -f ./${line}/docs/tox.ini ] ; then
811         docs="${docs} @docs"
812       fi
813       # tox.ini @ branch/project root dir
814       if [ -f ./${line}/tox.ini ] ; then
815         docs="${docs} @root"
816       fi
817     elif [ -f ../master/${line}/docs/tox.ini ] || [ -f ../master/${line}/tox.ini ]; then
818       docs="${docs},(tox.ini"
819       # tox.ini @ master/docs dir
820       if [ -f ../master/${line}/docs/tox.ini ] ; then
821         docs="${docs} @docs"
822       fi
823       # tox.ini @ master/project root dir
824       if [ -f ../master/${line}/tox.ini ] ; then
825         docs="${docs} @root"
826       fi
827       # just add a round bracket at the end of the value
828       docs="${docs})"
829     else
830       # no tox.ini found in docs or root dir
831       docs="${docs},-"
832     fi
833
834     # index.rst, first title in index.rst
835     indexrsttitle=""
836     if [ -f ./${line}/docs/index.rst ] ; then
837       indexrsttitle=$(cat ${branch}_indexrst_docs_root_titles.log | grep -F '['${line}']/docs/index.rst,' | awk -F "," '{print $4}');
838       docs="${docs},index.rst,${indexrsttitle}"
839     elif [ -f ../master/${line}/docs/index.rst ] ; then
840       indexrsttitle=$(cat ../master/master_indexrst_docs_root_titles.log | grep -F '['${line}']/docs/index.rst,' | awk -F "," '{print $4}');
841       docs="${docs},(index.rst),(${indexrsttitle})"
842     else
843       docs="${docs},-,-"
844     fi
845
846     #echo "DBUG: docs=${docs}"
847     line="${csv[i]},${docs}"
848     csv[$i]=${line}
849     ((i++))
850   done
851   unset array
852   unset i
853   unset docs
854
855   #
856   # csv column #16: index.html@RTD accessibility check
857   # csv column #17: index.html url
858   #
859
860   readarray -t array < ./${branch}_repoclone.log;
861   i=0
862   csv[i]="${csv[i]},index.html@RTD,index.html url"
863   ((i++))
864   for line in "${array[@]}"
865   do
866     # repoclone.log format:  $1=gitexitcode|$2=reponame|$3=repostate|$4=errormsg
867     gitexitcode=$(echo $line | awk -F "|" '{print $1}');
868        reponame=$(echo $line | awk -F "|" '{print $2}');
869       repostate=$(echo $line | awk -F "|" '{print $3}');
870        errormsg=$(echo $line | awk -F "|" '{print $4}');
871
872             url=""
873     curl_result=""
874
875     # this script works only with release "frankfurt" and later because
876     # earlier releases are using submodule structure for documentation files
877     if echo "$branch" | grep -q '^[abcde]'; then
878       curl_result="unsupported release"
879       url="-"
880     else
881
882       # we are working on "frankfurt" branch or later ...
883       if [[ ${repostate} == "ACTIVE" ]] || [[ ${repostate} == "READ_ONLY" ]]; then
884
885         # OPTIONAL: USE ALSO GITEXITCODE AS A FILTER CRITERIA ???
886
887         # url base
888         # important! only doc project needs a different url base
889         if [[ ${reponame} == "doc" ]]; then
890           url_start="https://docs.onap.org"
891         else
892           url_start="https://docs.onap.org/projects/onap"
893         fi
894         url_lang="en"
895         url_branch=${branch}
896
897         # "master" branch documentation is available as "latest" in RTD
898         if [[ ${url_branch} == "master" ]]; then
899           url_branch="latest"
900         fi
901
902         # replace all / characters in repo name with - charachter
903         url_repo=$(echo ${reponame} | sed -r 's/\//-/g')
904         url_file="index.html"
905
906         # build the full url
907         if [[ ${reponame} == "doc" ]]; then
908           # build the full url for the doc project
909           url="${url_start}/${url_lang}/${url_branch}/${url_file}"
910         else
911           # build the full url for the other projects
912           url="${url_start}-${url_repo}/${url_lang}/${url_branch}/${url_file}"
913         fi
914         #echo "DBUG: url=$url"
915
916         # test accessibility of url
917         curl --head --silent --fail "${url}?${unique}" >/dev/null
918         curl_result=$?
919
920         # convert numeric results to text
921         if [ "${curl_result}" = "0" ]; then
922           curl_result="accessible"
923         elif [ "${curl_result}" = "22" ]; then
924           curl_result="does not exist"
925         else
926           curl_result="ERROR:${curl_result}"
927         fi
928
929         # url does not exist for this branch.
930         # in case the requested url is not already for "master" branch,
931         # we try to access the url of the master branch and denote the
932         # result by using round brackets (result)
933         if [[ ${curl_result} == "does not exist" && ! $branch == "master" ]]; then
934
935           # build the full (master/latest) url
936           url="${url_start}-${url_repo}/${url_lang}/latest/${url_file}"
937           #echo "DBUG: url=$url"
938
939           # test accessibility of url in "master branch" (latest)
940           curl --head --silent --fail "${url}?${unique}" >/dev/null
941           curl_result=$?
942           # denote result as a value from "master" branch (latest)
943           url="(${url})"
944
945           # convert numeric results to text
946           if [ "${curl_result}" = "0" ]; then
947             curl_result="(accessible)"
948           elif [ "${curl_result}" = "22" ]; then
949             curl_result="(does not exist)"
950           else
951             curl_result="(ERROR:${curl_result})"
952           fi
953
954         fi
955       else
956         # repostate IS NOT ACTIVE OR READ_ONLY - no curl test required
957         curl_result="-"
958         url="-"
959       fi
960     fi
961
962     echo "$url ... $curl_result"
963     csv[i]="${csv[i]},${curl_result},${url}"
964     #echo "DBUG: csv line=${csv[i]}"
965
966     ((i++))
967   done
968
969   #
970   # csv column #18: release notes
971   #
972
973   readarray -t array < ../${repolist};
974   i=0
975   csv[i]="${csv[i]},release notes"
976   ((i++))
977   for line in "${array[@]}"
978   do
979     line=$(echo $line | sed 's:|.*$::')
980     #echo "DBUG: line=\"${line}\""
981     #echo "DBUG: i=${i}"
982     relnote=""
983
984     # put repo name in square brackets for increased grep hit rate
985     # escape minus and bracket characters to avoid problems with the grep command
986     #repo_grepable=$(echo ${line} | sed -r s:${line}:[${line}]: | sed -r 's/-/\\-/g' | sed -r 's/\[/\\[/g' | sed -r 's/\]/\\]/g')
987     #echo "DBUG: repo_grepable=\"${repo_grepable}\""
988
989     # check if repo dir exists in this branch
990     if [ -d ./${line} ] ; then
991       # if yes, check if repo name appears in the branch releasenotes.log
992       relnote=$(find "./${line}" -type f | grep '.*release.*note.*.rst' | wc -l);
993       #echo "DBUG: relnote=${relnote}"
994       # repo dir DOES NOT exist in this branch - so check if repo dir exists in MASTER branch
995     elif [ -d ../master/${line} ] ; then
996       # if yes, check if repo name appears in the MASTER releasenotes.log
997       # count release notes files in MASTER branch (in repo root and its subdirectories)
998       relnote=$(find "../master/${line}" -type f | grep 'release.*note.*.rst' | wc -l);
999       #echo "DBUG: relnote=${relnote}"
1000       # put results in round brackets to show that this is MASTER data
1001       relnote=$(echo ${relnote} | sed -r s:${relnote}:\(${relnote}\):)
1002     else
1003       relnote="-"
1004     fi
1005     #echo "DBUG: relnote=${relnote}"
1006
1007     line="${csv[i]},${relnote}"
1008     csv[i]=${line}
1009     ((i++))
1010
1011   done
1012   unset array
1013   unset i
1014   unset relnote
1015   unset repo_grepable
1016
1017   #
1018   # build the table.csv file
1019   #
1020
1021   for i in "${csv[@]}"
1022   do
1023     echo "$i" | tee -a ./${branch}_table.csv
1024   done
1025
1026   #
1027   # create data package for this branch and zip it
1028   #
1029
1030   datadir=${branch}_data
1031   mkdir $datadir
1032   cp $repolist $datadir
1033   cp ../$wikiplsfile $datadir
1034   cp ../$rpfile $datadir
1035   cp ${branch}_table.csv $datadir
1036   cp ${branch}_*.log $datadir
1037   zip -r ${datadir}.zip $datadir
1038
1039   # return from the branch directory
1040   cd ..
1041
1042 # return and work on the next requested branch ... or exit
1043 done