doc check updated (multiple tox.ini)
[ci-management.git] / jjb / doc / rules.yaml
1 - scm:
2     name: doc-scm
3     scm:
4       - git:
5           url: 'https://gerrit.onap.org/r/{project}'
6           refspec: '+refs/heads/*:refs/remotes/origin/* +refs/changes/*:refs/changes/*'
7           branches:
8             - '{ref}'
9
10 - trigger:
11     name: doc-rules-patchset-created
12     triggers:
13       - gerrit:
14           trigger-on:
15             - patchset-created-event
16             - comment-added-contains-event:
17                 comment-contains-value: recheck
18             - comment-added-contains-event:
19                 comment-contains-value: reverify
20           server-name: 'Primary'
21           projects:
22             - project-compare-type: 'ANT'
23               project-pattern: '**'
24               branches:
25                 - branch-compare-type: 'ANT'
26                   branch-pattern: '**/*'
27                 - branch-compare-type: 'ANT'
28                   branch-pattern: 'refs/tags/**'
29
30 - builder:
31     name: doc-rules
32     builders:
33       - shell: |
34           #!/bin/bash
35           . /lib/lsb/init-functions || exit 0
36           exitstatus="0"
37           warning="0"
38           # message, begin
39           log_success_msg "Starting additional checks related to documentation."
40           log_success_msg "See https://git.onap.org/doc/doc-best-practice for example config files (master branch)."
41           log_success_msg "Modify example config files if you like to use them in a release branch."
42           log_success_msg "See https://wiki.onap.org/x/w4IEBw for the detailed procedure #02."
43           log_success_msg "In case of questions please contact the ONAP documentation team."
44           # docs directory
45           if [ ! -d docs ] ; then
46             log_success_msg "Directory docs not found. Skipping further checks."
47             exit 0
48           fi
49           # config files, required
50           for i in docs/index.rst docs/conf.py docs/requirements-docs.txt docs/_static/css/ribbon.css; do
51             if [ ! -f $i ] ; then
52               log_failure_msg "$i missing. Please add it or remove the full docs directory."
53               exitstatus="1"
54             else
55               log_success_msg "$i found."
56             fi
57           done
58           # config files, no longer required
59           for i in docs/conf.yaml; do
60             if [ -f $i ] ; then
61               log_failure_msg "$i found. It is no longer required. Please remove it."
62               exitstatus="1"
63             else
64               log_success_msg "$i not found."
65             fi
66           done
67           # tox.ini @ docs directory
68           filename="docs/tox.ini"
69           if [ ! -f $filename ] ; then
70             log_failure_msg "$filename missing. Please add it or remove the full docs directory."
71             exitstatus="1"
72           else
73             log_success_msg "$filename found."
74             # sphinx-build command and -W option
75             sphinxbuild_detected=0
76             linenumber=0
77             while IFS="" read -r line || [ -n "$line" ] ; do
78               linenumber=$((linenumber+1))
79               if echo $line | grep -q '^[ \t]*sphinx-build.*' ; then
80                 sphinxbuild_detected="1"
81                 if echo $line | grep -q '^[ \t]*sphinx-build.* -W ' ; then
82                   log_success_msg "sphinx-build option '-W' used in $filename, line $linenumber."
83                 elif echo $line | grep -q ' \-b spelling ' ; then
84                   log_warning_msg "sphinx-build option '-W' missing for spellcheck in $filename, line $linenumber."
85                   warning="1"
86                 else
87                   log_failure_msg "sphinx-build option '-W' missing in $filename, line $linenumber. Please add it."
88                   exitstatus="1"
89                 fi
90               fi
91             done < $filename
92             if [ "$sphinxbuild_detected" = "0" ]; then
93               log_failure_msg "Sphinx-build command(s) missing in $filename. Please add it."
94               exitstatus="1"
95             fi
96             # second tox.ini @ root directory
97             if [ -f ./tox.ini ] ; then
98               # sphinx-build command
99               if cat ./tox.ini | grep -q '^[ \t]*sphinx-build.*' ; then
100                 log_warning_msg "tox.ini also exists in root directory and contains sphinx-build command(s). Please check for redundancies."
101                 warning="1"
102               fi
103             fi
104             unset sphinxbuild_detected
105             unset linenumber
106           fi
107           unset filename
108           # ribbon.css
109           filename="docs/_static/css/ribbon.css"
110           if [ ! -f $filename ]; then
111             log_failure_msg "$filename missing. Please add it or remove the full docs directory."
112             exitstatus="1"
113           else
114             log_success_msg "$filename found."
115             # max-width parameter
116             cssmaxwidth=$(grep '^[ \t]*max-width:' $filename | sed -e 's/^[ \t]*//' | sed -e 's/;$//');
117             if [[ ! $cssmaxwidth == *"max-width: 800px"* ]]; then
118               log_failure_msg "Setting 'max-width: 800px' missing in $filename. Please add it."
119               exitstatus="1"
120             else
121               log_success_msg "Setting 'max-width: 800px' found in $filename."
122             fi
123             unset cssmaxwidth
124           fi
125           unset filename
126           # message, end
127           if [ "$exitstatus" = "0" ]; then
128             if [ "$warning" = "0" ]; then
129               log_success_msg "Congratulations! No documentation problem(s) detected."
130             else
131               log_warning_msg "No major documentation problem(s) detected but there are warnings!"
132             fi
133           else
134             if [ ! "$warning" = "0" ]; then
135               log_warning_msg "Please check the detected documentation warning(s)!"
136             fi
137             log_failure_msg "Please fix the detected documentation problem(s)!"
138           fi
139           exit $exitstatus
140
141 - job-template:
142     name: doc-rules
143     node: ubuntu1804-docker-8c-8g
144     triggers:
145       - doc-rules-patchset-created
146     scm:
147       - doc-scm:
148           ref: $GERRIT_REFSPEC
149           project: $GERRIT_PROJECT
150     builders:
151       - doc-rules
152
153 - project:
154     name: 'doc-rules'
155     jobs:
156       - 'doc-rules'