[TASK] Improve problem reporting of validateRstFiles.sh
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Build / Scripts / validateRstFiles.sh
1 #!/bin/bash
2
3 #########################
4 #
5 # Check all rst snippets
6 # in typo3/sysext/core/Documentation/Changelog
7 #
8 # It expects to be run from the core root.
9 #
10 ##########################
11
12 echo 'Searching for rst snippets'
13 EXT=rst
14 COUNT=0
15 for i in `find typo3/sysext/core/Documentation/Changelog -name "*.rst" -type f`; do
16 if [[ "${i}" != "${i%.${EXT}}" && ! $i =~ 'Index.rst' && ! $i =~ 'Howto.rst' ]];then
17
18
19 fileContent=$(cat $i);
20 outputFileToStream=0;
21
22 # This regex needs to allow whitespace and/or newlines before the .. include:: ../../Includes.txt
23 # The regex itself is correct, bash doesn't like it
24 if ! [[ "$fileContent" =~ ^[[:space:]]*'.. include:: ../../Includes.txt' ]]; then
25 INCLUDE="no include"
26 include_message="insert '.. include:: ../../Includes.txt' in first line of the file"
27 outputFileToStream=1;
28 else
29 INCLUDE=""
30 fi
31
32 # This regex seems to have problems with the backtick characters.
33 # Maybe this is because it somehow interprets them from the variable $fileContent
34 if ! [[ "$fileContent" =~ 'See :issue:'\`([0-9]{4,6})\` ]]; then
35 REFERENCE="no reference"
36 reference_message="insert 'See :issue:\`<issuenumber>\`' after headline"
37 outputFileToStream=1;
38 else
39 REFERENCE=""
40 fi
41
42 # This regex needs to check that the ..index:: line a) holds valid content and b) is
43 # the last line in the checked file
44 if ! [[ "$fileContent" =~ '.. index:: '((TypoScript|TSConfig|TCA|FlexForm|LocalConfiguration|Fluid|FAL|Database|JavaScript|PHP-API|Frontend|Backend|CLI|RTE|ext:([a-z|A-Z|_|0-9]*))([,|[:space:]]{2})?)+$ ]]; then
45 INDEX="no or wrong index"
46 index_message="insert '.. index:: <at least one keyword>' at last line of the file"
47 outputFileToStream=1;
48 else
49 INDEX=""
50 fi
51 # Output filename in case any error was found
52 if [ $outputFileToStream == 1 ] ; then
53 FILE=${i/#typo3\/sysext\/core\/Documentation\/Changelog\//}
54 let COUNT++
55 printf "%-10s | %-12s | %-17s | %s \n" "$INCLUDE" "$REFERENCE" "$INDEX" "$FILE";
56 if ! [[ -z ${include_message} ]] ; then
57 echo ${include_message};
58 fi
59 if ! [[ -z ${reference_message} ]] ; then
60 echo ${reference_message};
61 fi
62 if ! [[ -z ${index_message} ]] ; then
63 echo ${index_message};
64 fi
65 fi
66 fi
67
68 done
69 if [[ $COUNT > 0 ]]; then
70 >&2 echo "Found $COUNT rst files with errors, check full log for details.";
71 exit 1;
72 else
73 exit 0;
74 fi