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