286c27886f4f5bded7127ab4eeda0667aa562a4c
[Packages/TYPO3.CMS.git] / 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 fileContent=$(cat $i);
19 outputFileToStream=0;
20
21 # This regex needs to allow whitespace and/or newlines before the .. include:: ../../Includes.txt
22 # The regex itself is correct, bash doesn't like it
23 if ! [[ "$fileContent" =~ ^[[:space:]]*'.. include:: ../../Includes.txt' ]]; then
24 INCLUDE="no include"
25 include_message="insert '.. include:: ../../Includes.txt' in first line of the file"
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 reference_message="insert 'See :issue:\`<issuenumber>\`' after headline"
36 outputFileToStream=1;
37 else
38 REFERENCE=""
39 fi
40
41 # This regex needs to check that the ..index:: line a) holds valid content and b) is
42 # the last line in the checked file
43 INDEX=""
44 if ! [[ "$fileContent" =~ '.. index:: '((FullyScanned|PartiallyScanned|NotScanned|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 valid keyword>' at last line of the file. See Build/Scripts/validateRstFiles.sh for allowed keywords"
47 outputFileToStream=1;
48 fi
49
50 # All Deprecation- / Breaking- files since v9 must have one of the tags FullyScanned|PartiallyScanned|NotScanned
51 if ! [[ "$i" =~ (Changelog\/8\.[0-99]+\/|Changelog\/8\.7\.x\/|Changelog\/7\.[0-99]+\/|Changelog\/7\.6\.x\/|Changelog\/master\/Feature-|Changelog\/master\/Important-|Changelog\/[0-99]+\.[0-99]+\/Feature-|Changelog\/[0-99]+\.[0-99]+\/Important-) ]]; then
52 if ! [[ "$fileContent" =~ ('.. index:: '.*(FullyScanned|PartiallyScanned|NotScanned)+.*) ]]; then
53 INDEX="missing FullyScanned / PartiallyScanned / NotScanned tag"
54 index_message="insert '.. index:: <at least one valid keyword and either FullyScanned, PartiallyScanned or NotScanned>' at last line of the file. See Build/Scripts/validateRstFiles.sh for allowed keywords"
55 outputFileToStream=1;
56 fi
57 fi
58
59 # Output filename in case any error was found
60 if [ $outputFileToStream == 1 ] ; then
61 FILE=${i/#typo3\/sysext\/core\/Documentation\/Changelog\//}
62 let COUNT++
63 printf "%-10s | %-12s | %-17s | %s \n" "$INCLUDE" "$REFERENCE" "$INDEX" "$FILE";
64 if ! [[ -z ${include_message} ]] ; then
65 echo ${include_message};
66 fi
67 if ! [[ -z ${reference_message} ]] ; then
68 echo ${reference_message};
69 fi
70 if ! [[ -z ${index_message} ]] ; then
71 echo ${index_message};
72 fi
73 fi
74 fi
75
76 done
77 if [[ $COUNT > 0 ]]; then
78 >&2 echo "Found $COUNT rst files with errors, check full log for details.";
79 exit 1;
80 else
81 exit 0;
82 fi