Allow doc-build.sh to ignore D000 of doc8
[releng.git] / utils / docs-build.sh
index bf9ab5b..5f9eeee 100755 (executable)
@@ -38,6 +38,26 @@ html_notes="\n    Revision: $rev_full\n\n    Build date: |today|"
 default_conf='releng/docs/etc/conf.py'
 opnfv_logo='releng/docs/etc/opnfv-logo.png'
 
+function check_rst_doc() {
+    _src="$1"
+
+    if ! which doc8 > /dev/null ; then
+        echo "Error: 'doc8' not found. Exec 'sudo pip install doc8' first."
+        exit 1
+    fi
+    # Note: This check may fail in many jobs for building project docs, since
+    #       the old sample has lines more than 120. We ignore failures on this
+    #       check right now, but these have to be fixed before OPNFV B release.
+    _out=$(doc8 --max-line-length 120 --ignore D000 "$_src") || {
+        _msg='Error: rst validatino (doc8) has failed, please fix the following error(s).'
+        _errs=$(echo "$_out" | sed -n -e "/^$_src/s/^/    /p")
+        echo
+        echo -e "$_msg\n$_errs"
+        echo
+        [[ -n "$GERRIT_COMMENT" ]] && echo -e "$_msg\n$_errs" >> "$GERRIT_COMMENT"
+    }
+}
+
 function add_html_notes() {
     _src="$1"
     _dir="$2"
@@ -64,6 +84,36 @@ function add_config() {
     fi
 }
 
+function is_top_dir() {
+    [[ "$1" == "$SRC_DIR" ]]
+}
+
+function generate_name_for_top_dir() {
+    for suffix in '' '.top' '.all' '.master' '_' '__' '___'
+    do
+        _name="$(basename $SRC_DIR)$suffix"
+        [[ -e "$SRC_DIR/$_name" ]] && continue
+        echo "$_name"
+        return
+    done
+
+    echo "Error: cannot find name for top directory [$SRC_DIR]"
+    exit 1
+}
+
+function generate_name() {
+    _dir=$1
+
+    if is_top_dir "$_dir" ; then
+        _name=$(generate_name_for_top_dir $SRC_DIR)
+    else
+        _name="${_dir#$SRC_DIR/}"
+    fi
+    # Replace '/' by '_'
+    echo "${_name////_}"
+}
+
+check_rst_doc $SRC_DIR
 
 if [[ ! -d "$RELENG_DIR" ]] ; then
     echo "Error: $RELENG_DIR dir not found. See https://wiki.opnfv.org/documentation/tools ."
@@ -72,7 +122,7 @@ fi
 
 find $SRC_DIR -name $INDEX_RST -printf '%h\n' | while read dir
 do
-    name="${dir##*/}"
+    name=$(generate_name $dir)
     src="$BUILD_DIR/src/$name"
     build="$BUILD_DIR/$name"
     output="$OUTPUT_DIR/$name"
@@ -121,4 +171,9 @@ do
         [[ -n "$GERRIT_COMMENT" ]] && echo "$msg" >> "$GERRIT_COMMENT"
     }
 
+    if is_top_dir "$dir" ; then
+        mv "$output"/* "$OUTPUT_DIR"/
+        rm -rf "$output"
+    fi
+
 done