[TASK] Ensure UTF-8 files contain no BOM 62/58762/6
authorChristian Kuhn <lolli@schwarzbu.ch>
Sun, 28 Oct 2018 13:29:33 +0000 (14:29 +0100)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Sun, 28 Oct 2018 20:12:29 +0000 (21:12 +0100)
Extends bamboo to verify UTF-8 files contain no BOM and
adds Build/Scripts/runTests.sh -s checkBom to do the same
locally.

Resolves: #86781
Releases: master
Change-Id: I97f994f0fe4db427563197925018f412d9ada626
Reviewed-on: https://review.typo3.org/58762
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Build/Scripts/checkUtf8Bom.sh [new file with mode: 0755]
Build/Scripts/runTests.sh
Build/bamboo/src/main/java/core/AbstractCoreSpec.java
Build/testing-docker/local/docker-compose.yml

diff --git a/Build/Scripts/checkUtf8Bom.sh b/Build/Scripts/checkUtf8Bom.sh
new file mode 100755 (executable)
index 0000000..b98ce9f
--- /dev/null
@@ -0,0 +1,34 @@
+#!/usr/bin/env bash
+
+#########################
+#
+# Check all UTF-8 files do not contain BOM.
+#
+# It expects to be run from the core root.
+#
+##########################
+
+FILES=`find . -type f \
+    ! -path "./bin/*" \
+    ! -path "./typo3conf/*" \
+    ! -path "./Build/node_modules/*" \
+    ! -path "./typo3temp/*" \
+    ! -path "./vendor/*" \
+    ! -path "./fileadmin/*" \
+    ! -path "./.git/*" \
+    ! -path "./index.php" \
+    ! -path "./.php_cs.cache" \
+    ! -path "./typo3/sysext/rte_ckeditor/Resources/Public/JavaScript/Contrib/*" \
+    ! -path "./typo3/sysext/rte_ckeditor/Resources/Public/JavaScript/Plugins/*" \
+    ! -path "./Build/bamboo/target/*" \
+    ! -path "./Build/JavaScript/*" \
+    ! -path "./typo3/sysext/*/Documentation-GENERATED-temp/*" \
+    -print0 | xargs -0 -n1 -P8 file {} | grep 'UTF-8 Unicode (with BOM)'`
+
+if [ -n "${FILES}" ]; then
+    echo "Found UTF-8 files with BOM:";
+    echo ${FILES};
+    exit 1;
+fi
+
+exit 0
index 9c90cca..73887ea 100755 (executable)
@@ -53,6 +53,7 @@ Options:
             - cglGit: test and fix latest committed patch for CGL compliance
             - cglAll: test and fix all core php files
             - checkAnnotations: check php code for allowed annotations
+            - checkBom: check UTF-8 files do not contain BOM
             - checkComposer: check composer.json files for version integrity
             - checkCsvFixtures: test integrity of functional test csv fixtures
             - checkExceptionCodes: test core for duplicate exception codes
@@ -292,6 +293,12 @@ case ${TEST_SUITE} in
         SUITE_EXIT_CODE=$?
         docker-compose down
         ;;
+    checkBom)
+        setUpDockerComposeDotEnv
+        docker-compose run check_bom
+        SUITE_EXIT_CODE=$?
+        docker-compose down
+        ;;
     checkComposer)
         setUpDockerComposeDotEnv
         docker-compose run check_composer
index 27742b8..a90b750 100644 (file)
@@ -936,6 +936,24 @@ abstract public class AbstractCoreSpec {
                         "checkIntegrityCsvFixtures"
                     ),
                 new ScriptTask()
+                    .description("Run UTF-8 BOM check")
+                    .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
+                    .inlineBody(
+                        this.getScriptTaskBashInlineBody() +
+                        "function checkIntegrityBom() {\n" +
+                        "    docker run \\\n" +
+                        "        -u ${HOST_UID} \\\n" +
+                        "        -v /bamboo-data/${BAMBOO_COMPOSE_PROJECT_NAME}/passwd:/etc/passwd \\\n" +
+                        "        -v ${BAMBOO_COMPOSE_PROJECT_NAME}_bamboo-data:/srv/bamboo/xml-data/build-dir/ \\\n" +
+                        "        --name ${BAMBOO_COMPOSE_PROJECT_NAME}sib_adhoc \\\n" +
+                        "        --rm \\\n" +
+                        "        typo3gmbh/" + requirementIdentifier.toLowerCase() + ":latest \\\n" +
+                        "        bin/bash -c \"cd ${PWD}; ./Build/Scripts/checkUtf8Bom.sh $*\"\n" +
+                        "}\n" +
+                        "\n" +
+                        "checkIntegrityBom"
+                    ),
+                new ScriptTask()
                     .description("Run composer.json integrity check")
                     .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
                     .inlineBody(
index 9d3a3c2..1dd73ff 100644 (file)
@@ -277,6 +277,23 @@ services:
         Build/Scripts/annotationChecker.php;
       "
 
+  check_bom:
+    image: typo3gmbh/${DOCKER_PHP_IMAGE}:latest
+    user: ${HOST_UID}
+    volumes:
+    - ${CORE_ROOT}:${CORE_ROOT}
+    - ${HOST_HOME}:${HOST_HOME}
+    - /etc/passwd:/etc/passwd:ro
+    - /etc/group:/etc/group:ro
+    working_dir: ${CORE_ROOT}
+    command: >
+      /bin/sh -c "
+        if [ ${SCRIPT_VERBOSE} -eq 1 ]; then
+          set -x
+        fi
+        Build/Scripts/checkUtf8Bom.sh
+      "
+
   check_composer:
     image: typo3gmbh/${DOCKER_PHP_IMAGE}:latest
     user: ${HOST_UID}