[TASK] Add RST snippet validation script 15/50215/7
authorMathias Schreiber <mathias.schreiber@wmdb.de>
Thu, 13 Oct 2016 14:17:35 +0000 (16:17 +0200)
committerFrank Naegler <frank.naegler@typo3.org>
Wed, 19 Oct 2016 09:35:15 +0000 (11:35 +0200)
Documentation snippets are now checked for validity.
Every rst file needs:

* An include line at the very top
* A reference to a ticket via "See :issue:`ISSUE_ID`
* An index at the very bottom of the file

Resolves: #78284
Releases: master
Change-Id: I538a089cece283fdc64b751e5a3275e65db598cc
Reviewed-on: https://review.typo3.org/50215
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Frank Naegler <frank.naegler@typo3.org>
Tested-by: Frank Naegler <frank.naegler@typo3.org>
typo3/sysext/core/Build/Scripts/checkFilePermissions.sh
typo3/sysext/core/Build/Scripts/validateRstFiles.sh [new file with mode: 0755]

index c8728cc..4e0e2a9 100755 (executable)
@@ -17,7 +17,8 @@ IGNORE[2]="typo3/sysext/core/Build/Scripts/checkFilePermissions.sh"
 IGNORE[3]="typo3/sysext/core/Build/Scripts/duplicateExceptionCodeCheck.sh"
 IGNORE[4]="typo3/sysext/core/Build/Scripts/splitFunctionalTests.sh"
 IGNORE[5]="typo3/sysext/core/Build/Scripts/xlfcheck.sh"
-IGNORE[6]="typo3/sysext/core/bin/typo3"
+IGNORE[6]="typo3/sysext/core/Build/Scripts/validateRstFiles.sh"
+IGNORE[7]="typo3/sysext/core/bin/typo3"
 
 COUNTER=0
 
diff --git a/typo3/sysext/core/Build/Scripts/validateRstFiles.sh b/typo3/sysext/core/Build/Scripts/validateRstFiles.sh
new file mode 100755 (executable)
index 0000000..b85fe0d
--- /dev/null
@@ -0,0 +1,62 @@
+#!/bin/bash
+
+#########################
+#
+# Check all rst snippets
+# in typo3/sysext/core/Documentation/Changelog
+#
+# It expects to be run from the core root.
+#
+##########################
+
+echo 'Searching for rst snippets'
+EXT=rst
+COUNT=0
+for i in `find typo3/sysext/core/Documentation/Changelog -name "*.rst" -type f`; do
+    if [[ "${i}" != "${i%.${EXT}}" && ! $i =~ 'Index.rst' &&  ! $i =~ 'Howto.rst' ]];then
+
+
+        fileContent=$(cat $i);
+        outputFileToStream=0;
+
+# This regex needs to allow whitespace and/or newlines before the .. include:: ../../Includes.txt
+# The regex itself is correct, bash doesn't like it
+        if ! [[ "$fileContent" =~ ^[[:space:]]*'.. include:: ../../Includes.txt' ]]; then
+            INCLUDE="no include"
+            outputFileToStream=1;
+        else
+            INCLUDE=""
+        fi
+
+# This regex seems to have problems with the backtick characters.
+# Maybe this is because it somehow interprets them from the variable $fileContent
+        if ! [[ "$fileContent" =~ 'See :issue:'\`([0-9]{4,6})\` ]]; then
+            REFERENCE="no reference"
+            outputFileToStream=1;
+        else
+            REFERENCE=""
+        fi
+
+# This regex needs to check that the ..index:: line a) holds valid content and b) is
+# the last line in the checked file
+        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
+            INDEX="no or wrong index"
+            outputFileToStream=1;
+        else
+            INDEX=""
+        fi
+        # Output filename in case any error was found
+        if [ $outputFileToStream == 1 ] ; then
+            FILE=${i/#typo3\/sysext\/core\/Documentation\/Changelog\//}
+            let COUNT++
+            printf "%-10s | %-12s | %-17s | %s \n" "$INCLUDE" "$REFERENCE" "$INDEX" "$FILE";
+        fi
+    fi
+
+done
+if [[ $COUNT > 0 ]]; then
+     >&2 echo "Found $COUNT rst files with errors, check full log for details.";
+     exit 1;
+   else
+     exit 0;
+fi
\ No newline at end of file