[TASK] Add various Composer scripts 80/57480/2
authorMathias Brodala <mbrodala@pagemachine.de>
Thu, 7 Dec 2017 11:05:07 +0000 (12:05 +0100)
committerMathias Brodala <mbrodala@pagemachine.de>
Fri, 6 Jul 2018 10:08:09 +0000 (12:08 +0200)
This vastly simplifies running common commands for TYPO3 development.

E.g. executing PHPUnit can be done like this:

    composer test:php:unit

Since Composer uses Symfony Console this can even be shortened:

    composer t:p:u

Also arbitrary arguments can be passed to the executed command:

    composer t:p:u -- --filter unitTestMethodName

Change-Id: I3ef62417227b3c4c1c3d8f8f3662052ca36ed885
Resolves: #83249
Related: #84836
Releases: master, 8.7
Reviewed-on: https://review.typo3.org/57480
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Mathias Brodala <mbrodala@pagemachine.de>
Tested-by: Mathias Brodala <mbrodala@pagemachine.de>
Build/Scripts/composer/InstallerScripts.php [new file with mode: 0644]
composer.json

diff --git a/Build/Scripts/composer/InstallerScripts.php b/Build/Scripts/composer/InstallerScripts.php
new file mode 100644 (file)
index 0000000..2f27149
--- /dev/null
@@ -0,0 +1,67 @@
+<?php
+declare(strict_types = 1);
+namespace TYPO3\CMS\Composer\Scripts;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2018 Helmut Hummel <info@helhum.io>
+ *  All rights reserved
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *  A copy is found in the text file GPL.txt and important notices to the license
+ *  from the author is found in LICENSE.txt distributed with these scripts.
+ *
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+use Composer\Script\Event;
+use Symfony\Component\Filesystem\Filesystem as SymfonyFilesystem;
+use TYPO3\CMS\Composer\Plugin\Util\Filesystem;
+
+class InstallerScripts
+{
+    public static function enableCommitMessageHook(Event $event)
+    {
+        $symfonyFilesystem = new SymfonyFilesystem();
+        $filesystem = new Filesystem();
+        try {
+            $filesystem->copy('Build/git-hooks/commit-msg', '.git/hooks/commit-msg');
+            if (!is_executable('.git/hooks/commit-msg')) {
+                $symfonyFilesystem->chmod('.git/hooks/commit-msg', 0755);
+            }
+        } catch (\Symfony\Component\Filesystem\Exception\IOException $e) {
+            $event->getIO()->writeError('<warning>Exception:enableCommitMessageHook:' . $e->getMessage() . '</warning>');
+        }
+    }
+
+    public static function enablePreCommitHook(Event $event)
+    {
+        if (DIRECTORY_SEPARATOR === '\\') {
+            return;
+        }
+        $symfonyFilesystem = new SymfonyFilesystem();
+        $filesystem = new Filesystem();
+        try {
+            $filesystem->copy('Build/git-hooks/unix+mac/pre-commit', '.git/hooks/pre-commit');
+            if (!is_executable('.git/hooks/pre-commit')) {
+                $symfonyFilesystem->chmod('.git/hooks/pre-commit', 0755);
+            }
+        } catch (\Symfony\Component\Filesystem\Exception\IOException $e) {
+            $event->getIO()->writeError('<warning>Exception:enablePreCommitHook:' . $e->getMessage() . '</warning>');
+        }
+    }
+
+    public static function disablePreCommitHook(Event $event)
+    {
+        $filesystem = new Filesystem();
+        $filesystem->remove('.git/hooks/pre-commit');
+    }
+}
index 44ef2bb..5d6a230 100644 (file)
                        "dev-TYPO3_8-7": "8.x-dev"
                }
        },
+       "scripts": {
+               "test:php:unit": [
+                       "@php -v",
+                       "@php vendor/phpunit/phpunit/phpunit -c vendor/typo3/testing-framework/Resources/Core/Build/UnitTests.xml"
+               ],
+               "test": [
+                       "@test:php:unit"
+               ],
+               "gerrit:setup": [
+                       "@gerrit:setup:commitMessageHook:enable",
+                       "@gerrit:setup:preCommitHook:enable"
+               ],
+               "gerrit:setup:commitMessageHook:enable": [
+                       "TYPO3\\CMS\\Composer\\Scripts\\InstallerScripts::enableCommitMessageHook"
+               ],
+               "gerrit:setup:preCommitHook:enable": [
+                       "TYPO3\\CMS\\Composer\\Scripts\\InstallerScripts::enablePreCommitHook"
+               ],
+               "gerrit:setup:preCommitHook:disable": [
+                       "TYPO3\\CMS\\Composer\\Scripts\\InstallerScripts::disablePreCommitHook"
+               ],
+               "post-autoload-dump": [
+                       "@gerrit:setup:commitMessageHook:enable"
+               ]
+       },
+       "scripts-descriptions": {
+               "test:php:unit": "Run all PHP unit tests",
+               "test": "Run all tests",
+               "gerrit:setup": "Enable all the git hooks needed to make contribution easy",
+               "gerrit:setup:commitMessageHook:enable": "Enable the commit message hook needed for gerrit",
+               "gerrit:setup:preCommitHook:enable": "Enable pre commit hook to run some checks locally",
+               "gerrit:setup:preCommitHook:disable": "Disable pre commit hook to run some checks locally"
+       },
        "non-feature-branches": [
                "TYPO3_.+"
        ],