[TASK] Add RST snippet validation script
[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 outputFileToStream=1;
27 else
28 INCLUDE=""
29 fi
30
31 # This regex seems to have problems with the backtick characters.
32 # Maybe this is because it somehow interprets them from the variable $fileContent
33 if ! [[ "$fileContent" =~ 'See :issue:'\`([0-9]{4,6})\` ]]; then
34 REFERENCE="no reference"
35 outputFileToStream=1;
36 else
37 REFERENCE=""
38 fi
39
40 # This regex needs to check that the ..index:: line a) holds valid content and b) is
41 # the last line in the checked file
42 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
43 INDEX="no or wrong index"
44 outputFileToStream=1;
45 else
46 INDEX=""
47 fi
48 # Output filename in case any error was found
49 if [ $outputFileToStream == 1 ] ; then
50 FILE=${i/#typo3\/sysext\/core\/Documentation\/Changelog\//}
51 let COUNT++
52 printf "%-10s | %-12s | %-17s | %s \n" "$INCLUDE" "$REFERENCE" "$INDEX" "$FILE";
53 fi
54 fi
55
56 done
57 if [[ $COUNT > 0 ]]; then
58 >&2 echo "Found $COUNT rst files with errors, check full log for details.";
59 exit 1;
60 else
61 exit 0;
62 fi