From da1ba9654220c0f355aa44456df43b2999f457e2 Mon Sep 17 00:00:00 2001 From: Helmut Hummel Date: Mon, 2 Jul 2018 15:32:51 +0200 Subject: [PATCH] Further simplify extension build and release --- .gitattributes | 1 + .gitignore | 2 +- .travis.yml | 11 +- Classes/Console/Composer/InstallerScripts.php | 39 -- Classes/Console/Composer/ScriptHelper.php | 86 +++++ Libraries/composer.json | 22 ++ Libraries/composer.lock | 342 ++++++++++++++++++ .../ExtensionArtifacts/ext_autoload.php | 15 +- composer.json | 14 +- 9 files changed, 464 insertions(+), 68 deletions(-) create mode 100644 Classes/Console/Composer/ScriptHelper.php create mode 100644 Libraries/composer.json create mode 100644 Libraries/composer.lock diff --git a/.gitattributes b/.gitattributes index e86900f3..923a26da 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,3 +1,4 @@ +/Libraries/ export-ignore /Packages/ export-ignore /Resources/Private/ExtensionArtifacts/ export-ignore /Resources/Private/Patches/ export-ignore diff --git a/.gitignore b/.gitignore index bdff9e25..62ca6215 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ /.Build/* /Classes/Console/Hook/* /Configuration/Console/ComposerPackagesCommands.php -/Libraries/* +/Libraries/vendor /Resources/Public/* /.php_cs.cache diff --git a/.travis.yml b/.travis.yml index 6aa1201e..c52ba5a2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -94,7 +94,8 @@ jobs: composer set-version $TRAVIS_TAG test -z "$(git diff --shortstat 2> /dev/null | tail -n1)"; fi - - composer extension-create-libs && ls -la Libraries/*.phar | grep -v ^-rwx + - composer extension-verify-composer-json + - composer extension-create-libs - stage: sonar code scanner if: type = push AND branch IN (master, develop) @@ -121,10 +122,8 @@ jobs: - | if [ -n "$TYPO3_ORG_USERNAME" ] && [ -n "$TYPO3_ORG_PASSWORD" ]; then echo -e "Preparing upload of release ${TRAVIS_TAG} to TER\n"; - # Install requirements - composer require --dev helhum/ter-client dev-master - # Cleanup before we upload - git reset --hard HEAD && git clean -fx + # Install ter client + composer require --global helhum/ter-client # Build extension files composer extension-release @@ -132,5 +131,5 @@ jobs: # Upload TAG_MESSAGE=`git tag -n10 -l $TRAVIS_TAG | sed 's/^[0-9.]*[ ]*//g'` echo "Uploading release ${TRAVIS_TAG} to TER" - .Build/bin/ter-client upload typo3_console . -u "$TYPO3_ORG_USERNAME" -p "$TYPO3_ORG_PASSWORD" -m "$TAG_MESSAGE" + $HOME/.composer/vendor/bin/ter-client upload typo3_console . -u "$TYPO3_ORG_USERNAME" -p "$TYPO3_ORG_PASSWORD" -m "$TAG_MESSAGE" fi; diff --git a/Classes/Console/Composer/InstallerScripts.php b/Classes/Console/Composer/InstallerScripts.php index a91efc8c..c78feb72 100644 --- a/Classes/Console/Composer/InstallerScripts.php +++ b/Classes/Console/Composer/InstallerScripts.php @@ -15,10 +15,8 @@ */ use Composer\Script\Event; -use Composer\Script\Event as ScriptEvent; use Composer\Semver\Constraint\EmptyConstraint; use Helhum\Typo3Console\Composer\InstallerScript\PopulateCommandConfiguration; -use Symfony\Component\Console\Exception\RuntimeException; use TYPO3\CMS\Composer\Plugin\Core\InstallerScripts\AutoloadConnector; use TYPO3\CMS\Composer\Plugin\Core\InstallerScripts\WebDirectory; use TYPO3\CMS\Composer\Plugin\Core\InstallerScriptsRegistration; @@ -49,41 +47,4 @@ public static function register(Event $event, ScriptDispatcher $scriptDispatcher $scriptDispatcher->addInstallerScript(new AutoloadConnector()); } } - - /** - * @param ScriptEvent $event - * @internal - * @throws RuntimeException - */ - public static function setVersion(ScriptEvent $event) - { - $version = $event->getArguments()[0]; - if (!preg_match('/\d+\.\d+\.\d+/', $version)) { - throw new RuntimeException('No valid version number provided!', 1468672604); - } - $docConfigFile = __DIR__ . '/../../../Documentation/Settings.yml'; - $content = file_get_contents($docConfigFile); - $content = preg_replace('/(version|release): \d+\.\d+\.\d+/', '$1: ' . $version, $content); - file_put_contents($docConfigFile, $content); - - $extEmConfFile = __DIR__ . '/../../../Resources/Private/ExtensionArtifacts/ext_emconf.php'; - $content = file_get_contents($extEmConfFile); - $content = preg_replace('/(\'version\' => )\'\d+\.\d+\.\d+/', '$1\'' . $version, $content); - file_put_contents($extEmConfFile, $content); - - $applicationFile = __DIR__ . '/../Mvc/Cli/Symfony/Application.php'; - $content = file_get_contents($applicationFile); - $content = preg_replace('/(const TYPO3_CONSOLE_VERSION = \')\d+\.\d+\.\d+/', 'const TYPO3_CONSOLE_VERSION = \'' . $version, $content); - file_put_contents($applicationFile, $content); - - $travisYmlFile = __DIR__ . '/../../../.travis.yml'; - $content = file_get_contents($travisYmlFile); - $content = preg_replace('/(export COMPOSER_ROOT_VERSION)=\d+\.\d+\.\d+/', '$1=' . $version, $content); - file_put_contents($travisYmlFile, $content); - - $sonarConfigFile = __DIR__ . '/../../../sonar-project.properties'; - $content = file_get_contents($sonarConfigFile); - $content = preg_replace('/(sonar.projectVersion)=\d+\.\d+\.\d+/', '$1=' . $version, $content); - file_put_contents($sonarConfigFile, $content); - } } diff --git a/Classes/Console/Composer/ScriptHelper.php b/Classes/Console/Composer/ScriptHelper.php new file mode 100644 index 00000000..39016b91 --- /dev/null +++ b/Classes/Console/Composer/ScriptHelper.php @@ -0,0 +1,86 @@ +getArguments()[0]; + if (!preg_match('/\d+\.\d+\.\d+/', $version)) { + throw new Exception('No valid version number provided!', 1468672604); + } + $docConfigFile = __DIR__ . '/../../../Documentation/Settings.yml'; + $content = file_get_contents($docConfigFile); + $content = preg_replace('/(version|release): \d+\.\d+\.\d+/', '$1: ' . $version, $content); + file_put_contents($docConfigFile, $content); + + $extEmConfFile = __DIR__ . '/../../../Resources/Private/ExtensionArtifacts/ext_emconf.php'; + $content = file_get_contents($extEmConfFile); + $content = preg_replace('/(\'version\' => )\'\d+\.\d+\.\d+/', '$1\'' . $version, $content); + file_put_contents($extEmConfFile, $content); + + $applicationFile = __DIR__ . '/../Mvc/Cli/Symfony/Application.php'; + $content = file_get_contents($applicationFile); + $content = preg_replace('/(const TYPO3_CONSOLE_VERSION = \')\d+\.\d+\.\d+/', 'const TYPO3_CONSOLE_VERSION = \'' . $version, $content); + file_put_contents($applicationFile, $content); + + $travisYmlFile = __DIR__ . '/../../../.travis.yml'; + $content = file_get_contents($travisYmlFile); + $content = preg_replace('/(export COMPOSER_ROOT_VERSION)=\d+\.\d+\.\d+/', '$1=' . $version, $content); + file_put_contents($travisYmlFile, $content); + + $sonarConfigFile = __DIR__ . '/../../../sonar-project.properties'; + $content = file_get_contents($sonarConfigFile); + $content = preg_replace('/(sonar.projectVersion)=\d+\.\d+\.\d+/', '$1=' . $version, $content); + file_put_contents($sonarConfigFile, $content); + } + + public static function verifyAutoloadInfoInLibraries() + { + $main = json_decode(file_get_contents('composer.json'), true)['autoload']; + $lib = json_decode(file_get_contents('Libraries/composer.json'), true)['autoload']; + if (count($main) !== count($lib)) { + throw new Exception('Count of autoload definition mismatch'); + } + if (count($main['psr-4']) !== count($lib['psr-4'])) { + throw new Exception('Count of psr-4 definition mismatch'); + } + foreach ($main['psr-4'] as $prefix => $paths) { + if ( + count($paths) !== count($lib['psr-4'][$prefix]) + || empty($lib['psr-4'][$prefix]) + ) { + throw new Exception('Count of psr-4 paths mismatch'); + } + foreach ($paths as $index => $path) { + if ('../' . $path !== $lib['psr-4'][$prefix][$index]) { + throw new Exception('Different psr-4 paths defined'); + } + } + } + } +} diff --git a/Libraries/composer.json b/Libraries/composer.json new file mode 100644 index 00000000..717451bd --- /dev/null +++ b/Libraries/composer.json @@ -0,0 +1,22 @@ +{ + "config": { + "patform": { + "php": "7.0.8" + }, + "classmap-authoritative": true, + "prepend-autoloader": true + }, + "autoload": { + "psr-4": { + "Helhum\\Typo3Console\\": [ + "../Classes/Console/", + "../Classes/Compatibility/" + ] + } + }, + "require": { + "symfony/console": "^3.4.4", + "symfony/process": "^3.4.4", + "helhum/config-loader": "^0.9.0" + } +} diff --git a/Libraries/composer.lock b/Libraries/composer.lock new file mode 100644 index 00000000..538bc73a --- /dev/null +++ b/Libraries/composer.lock @@ -0,0 +1,342 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "4ba11c34cad4c55876f0d660a163a75d", + "packages": [ + { + "name": "helhum/config-loader", + "version": "v0.9.0", + "source": { + "type": "git", + "url": "https://github.com/helhum/config-loader.git", + "reference": "11188d23b3c5e1e3fb61de9d7e3d6ddaae3cf389" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/helhum/config-loader/zipball/11188d23b3c5e1e3fb61de9d7e3d6ddaae3cf389", + "reference": "11188d23b3c5e1e3fb61de9d7e3d6ddaae3cf389", + "shasum": "" + }, + "require": { + "php": ">=7.0.0 <7.3.0" + }, + "require-dev": { + "mikey179/vfsstream": "^1.6", + "phpunit/phpunit": "^5.0", + "symfony/yaml": "^2.8 || ^3.3 || ^4.0" + }, + "suggest": { + "ext-yaml": "For improved performance when parsing yaml files you should use the PECL YAML Parser php extension", + "symfony/yaml": "To be able to parse yaml files, you will need symfony/yaml" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Helhum\\ConfigLoader\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "GPL-2.0-or-later" + ], + "description": "Generic config loader with context and environment support.", + "time": "2018-06-14T12:33:08+00:00" + }, + { + "name": "psr/log", + "version": "1.0.2", + "source": { + "type": "git", + "url": "https://github.com/php-fig/log.git", + "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/log/zipball/4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", + "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Log\\": "Psr/Log/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for logging libraries", + "homepage": "https://github.com/php-fig/log", + "keywords": [ + "log", + "psr", + "psr-3" + ], + "time": "2016-10-10T12:19:37+00:00" + }, + { + "name": "symfony/console", + "version": "v3.4.12", + "source": { + "type": "git", + "url": "https://github.com/symfony/console.git", + "reference": "1b97071a26d028c9bd4588264e101e14f6e7cd00" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/console/zipball/1b97071a26d028c9bd4588264e101e14f6e7cd00", + "reference": "1b97071a26d028c9bd4588264e101e14f6e7cd00", + "shasum": "" + }, + "require": { + "php": "^5.5.9|>=7.0.8", + "symfony/debug": "~2.8|~3.0|~4.0", + "symfony/polyfill-mbstring": "~1.0" + }, + "conflict": { + "symfony/dependency-injection": "<3.4", + "symfony/process": "<3.3" + }, + "require-dev": { + "psr/log": "~1.0", + "symfony/config": "~3.3|~4.0", + "symfony/dependency-injection": "~3.4|~4.0", + "symfony/event-dispatcher": "~2.8|~3.0|~4.0", + "symfony/lock": "~3.4|~4.0", + "symfony/process": "~3.3|~4.0" + }, + "suggest": { + "psr/log-implementation": "For using the console logger", + "symfony/event-dispatcher": "", + "symfony/lock": "", + "symfony/process": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.4-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Console\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Console Component", + "homepage": "https://symfony.com", + "time": "2018-05-23T05:02:55+00:00" + }, + { + "name": "symfony/debug", + "version": "v4.1.1", + "source": { + "type": "git", + "url": "https://github.com/symfony/debug.git", + "reference": "dbe0fad88046a755dcf9379f2964c61a02f5ae3d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/debug/zipball/dbe0fad88046a755dcf9379f2964c61a02f5ae3d", + "reference": "dbe0fad88046a755dcf9379f2964c61a02f5ae3d", + "shasum": "" + }, + "require": { + "php": "^7.1.3", + "psr/log": "~1.0" + }, + "conflict": { + "symfony/http-kernel": "<3.4" + }, + "require-dev": { + "symfony/http-kernel": "~3.4|~4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.1-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Debug\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Debug Component", + "homepage": "https://symfony.com", + "time": "2018-06-08T09:39:36+00:00" + }, + { + "name": "symfony/polyfill-mbstring", + "version": "v1.8.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-mbstring.git", + "reference": "3296adf6a6454a050679cde90f95350ad604b171" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/3296adf6a6454a050679cde90f95350ad604b171", + "reference": "3296adf6a6454a050679cde90f95350ad604b171", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "suggest": { + "ext-mbstring": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.8-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Mbstring\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for the Mbstring extension", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "mbstring", + "polyfill", + "portable", + "shim" + ], + "time": "2018-04-26T10:06:28+00:00" + }, + { + "name": "symfony/process", + "version": "v3.4.12", + "source": { + "type": "git", + "url": "https://github.com/symfony/process.git", + "reference": "acc5a37c706ace827962851b69705b24e71ca17c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/process/zipball/acc5a37c706ace827962851b69705b24e71ca17c", + "reference": "acc5a37c706ace827962851b69705b24e71ca17c", + "shasum": "" + }, + "require": { + "php": "^5.5.9|>=7.0.8" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.4-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Process\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Process Component", + "homepage": "https://symfony.com", + "time": "2018-05-30T04:24:30+00:00" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [] +} diff --git a/Resources/Private/ExtensionArtifacts/ext_autoload.php b/Resources/Private/ExtensionArtifacts/ext_autoload.php index 9bf1b0f7..f14c4df0 100644 --- a/Resources/Private/ExtensionArtifacts/ext_autoload.php +++ b/Resources/Private/ExtensionArtifacts/ext_autoload.php @@ -10,20 +10,7 @@ $typo3AutoLoadFile = realpath(($rootPath = dirname(__DIR__, 3)) . '/typo3') . '/../vendor/autoload.php'; putenv('TYPO3_PATH_ROOT=' . $rootPath); $classLoader = require $typo3AutoLoadFile; - - $extensionBaseDir = __DIR__; - $autoloadDefinition = json_decode(file_get_contents($extensionBaseDir . '/composer.json'), true)['autoload']['psr-4']; - foreach ($autoloadDefinition as $prefix => $paths) { - $paths = array_map( - function ($path) use ($extensionBaseDir) { - return $extensionBaseDir . '/' . $path; - }, - (array)$paths - ); - $classLoader->addPsr4($prefix, $paths); - } - $pharFile = __DIR__ . '/Libraries/symfony-process.phar'; - require 'phar://' . $pharFile . '/vendor/autoload.php'; + require __DIR__ . '/Libraries/vendor/autoload.php'; return $classLoader; })(); diff --git a/composer.json b/composer.json index 765567da..5a945056 100644 --- a/composer.json +++ b/composer.json @@ -89,7 +89,10 @@ ], "scripts": { "set-version": [ - "Helhum\\Typo3Console\\Composer\\InstallerScripts::setVersion" + "Helhum\\Typo3Console\\Composer\\ScriptHelper::setVersion" + ], + "extension-verify-composer-json": [ + "Helhum\\Typo3Console\\Composer\\ScriptHelper::verifyAutoloadInfoInLibraries" ], "extension-copy-artifacts": [ "cp -f Resources/Private/ExtensionArtifacts/ext_* .", @@ -97,12 +100,7 @@ "cp -rf Resources/Private/ExtensionArtifacts/Classes/Console/* Classes/Console/" ], "extension-create-libs": [ - "mkdir -p Libraries/temp", - "[ -f $HOME/.composer/vendor/bin/phar-composer ] || composer global require clue/phar-composer", - "if [ ! -f Libraries/symfony-process.phar ]; then cd Libraries/temp && composer require symfony/console=^3.4.4 symfony/process=^3.4.4 helhum/config-loader=^0.9.0 && composer config classmap-authoritative true && composer config prepend-autoloader true && composer dump-autoload -o; fi", - "[ -f Libraries/symfony-process.phar ] || $HOME/.composer/vendor/bin/phar-composer build Libraries/temp/ Libraries/symfony-process.phar", - "chmod -x Libraries/*.phar", - "rm -rf Libraries/temp" + "@composer install -d Libraries" ], "extension-build": [ "@extension-create-libs", @@ -125,7 +123,7 @@ "rm sonar-project.properties" ], "extension-clean": [ - "rm -rf Libraries Resources/Public/Icons", + "rm -rf Libraries/vendor Resources/Public/Icons", "rm -f ext_*" ] },