diff --git a/.github/workflows/test-and-build.yml b/.github/workflows/test-and-build.yml new file mode 100644 index 0000000..d9e0a2a --- /dev/null +++ b/.github/workflows/test-and-build.yml @@ -0,0 +1,64 @@ +name: Test and build +on: [push, pull_request] +jobs: + test-and-build: + name: '[PHP ${{ matrix.php-version }}] test and build' + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + php-version: [ 7.1, 7.2, 7.3, 7.4 ] + + steps: + - uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + ini-values: phar.readonly=off + tools: composer:v1 + + - uses: actions/checkout@v2 + + - name: composer install + run: composer install --optimize-autoloader -n + + - name: create version file + run: versionYaml="$(cat .version.yml.dist | envsubst)" && echo "$versionYaml" > .version.yml + + - name: run lint script + run: ./etc/scripts/lintFiles.sh + shell: bash + + - name: run codingstandard script + run: ./etc/scripts/checkCodingStandards.sh + shell: bash + + - name: run specs script + run: ./etc/scripts/runSpecs.sh + shell: bash + + - name: install kherge/box globally + run: composer global require kherge/box + + - name: box build + run: ${HOME}/.composer/vendor/bin/box build + + - name: info output + run: cat .version.yml && echo "Built following version:" && php ./build/sd-sw-plugin-manager.phar sd:plugins:info -v + + - name: prepare deployment + run: mv ./build/sd-sw-plugin-manager.phar ./build/sd-sw-plugin-manager.php${{matrix.php-version}}.phar + + - name: deploy + if: + contains(' + refs/heads/master + ', github.ref) + uses: shallwefootball/s3-upload-action@master + id: S3 + with: + aws_key_id: ${{ secrets.S3_BUILD_ACCESS_KEY }} + aws_secret_access_key: ${{ secrets.S3_BUILD_SECRET_KEY }} + aws_bucket: ${{ secrets.S3_BUILD_BUCKET }} + source_dir: 'build' + destination_dir: 'phar' diff --git a/.php.travis.ini b/.php.travis.ini deleted file mode 100644 index 95eb3c9..0000000 --- a/.php.travis.ini +++ /dev/null @@ -1 +0,0 @@ -error_reporting = E_ALL & ~E_NOTICE diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 4438155..0000000 --- a/.travis.yml +++ /dev/null @@ -1,50 +0,0 @@ -language: php -dist: bionic -sudo: false - -php: - - '7.1' - - '7.2' - - '7.3' - -env: - global: - - S3_BUCKET="build-tools.cloud.solutiondrive.de" - - secure: "B5P5TLTUi4oUBCGNpHUY258NFV5/4WjxHrM/27TiV0J4uuYcqcme5J9O5NTU6OGxxweM1XA5mkApvf8lMmI5uelQfnR6fPRzx+a4LTLOGFwoJJ+/ZZcw3bjAlV5RUeJocMUG1F0ohNMoJkV0Du8+YOSoSicFfRkh6nOuv4pzMgUSPIqHqGCvLBoQ1Z1WxZIlRSlwmgyPMYBquRp5uS2td5xf4Yg/VQ0XKdt31oiOLyuh5jPJeK4fBYEvbLIHidAR+geQLscj4OS9xfTHphTonFU7G7czC+7Drb3XdRQxod86GFUAiADRzbclmhzqBDps934VjmLStV/pD6GBxqciUU3oT7GxXGf0rpq3bAnRdeo4/f8Mk7mwa20HgZPKqw1k44LpUva2hFLPvDjazOkHPAPwp9oXw1q7xKDnDszRRbUANkjBzVIj7oosxXs9Aqat1wN4nzLUAlQdEZ+7Go323gTq7K4ID5qHsWnzvQGP2QSi0NbvKRfAhANIsP46YiAlbSvvit3ZItdQjCpfevAtDHbuMretl9hwW8SGYxGcLzrc2HnBYi0uIYAgmBzYiedfxNx2M8rVhhcaq51jh6VmGM0kDZaHKkPofxXTCmZdUIqXIM9B+hwTIPX4Y7tV2gSV6MPWQ36yflUkc/6FyxqXKrX9g1GV3z028uQcekn3wtY=" - - secure: "BqKu9oGWPbT50MttdoQAg5GbvCaz4Lan5fK+czB7SzWUoQX4sW6PeTd3KmhzO1f4Kc3ivxIx/193t0kZAfHx90htmdNL5RSGN5acAthSgWbGjPP1+N8KcVhp3ms5LmyZDbUORbVzvuXzT0uVFuH//x90vwROkunXPFqNpO0/NUnIfAwPSel5vCDyfihRfypU3GhFRWF5vaQPkVdT/naOyzAeTbIhFPNCQkl4UooZ4OXOPnCQkT8HlEn7hma/fvgWafuen+Y5W8qEXTq/KLJVsK6LhnW4voKOiNpTNF8oPx7J4n1+EHh9wFxCQQImzs0fx4SDQCrFkS2hu9wcFpTYssmqILAcWihGLlu3TNUPyW/fUp5Q3u35CqjuHMqN7yR4DPHTd5kH7+69Hqo+Pecwb8DOgiVkdrvjIsJdbLxlCmjTlIoAXEKMLEfwI0TEbN6klYnn/f7317eUkuT/x0oQMXu1Ub3lYR73h9K0K+H1R3BVabPdZu6bm8Vsk9qXmVLPK6pVYfaDC/KXgy2Jxol4A4l44cTfrbJsyezqaKGcqQvz/wYf4wx/Jlnh9dsevG5065FHg6rULeNHh8B44KSMnusN/B3QOr4eXc1ygg/0pbFSwPeUdHdxNP4el+iB4wPVFHbMGTi0VI3AeZ9+DqT9ds27pDPBcic6//OpkiYMxv4=" - -before_install: - - phpenv config-add .php.travis.ini - - export PATH=$PATH:$HOME/.composer/vendor/bin - - travis_retry composer self-update --1; - -install: - - composer install --optimize-autoloader -n - -before_script: - - versionYaml="$(cat .version.yml.dist | envsubst)" - - echo "$versionYaml" > .version.yml - -script: - - ./etc/scripts/lintFiles.sh - - if [ "${TRAVIS_PHP_VERSION}" == "7.3" ]; then ./etc/scripts/checkCodingStandards.sh ; fi - - ./etc/scripts/runSpecs.sh - -before_deploy: - - composer global require kherge/box - - ${HOME}/.config/composer/vendor/bin/box build - - echo "Built following version:" && php ./build/sd-sw-plugin-manager.phar sd:plugins:info -v - - mv ./build/sd-sw-plugin-manager.phar ./build/sd-sw-plugin-manager.php${TRAVIS_PHP_VERSION}.phar - -deploy: - provider: s3 - access_key_id: "${S3_ACCESS_KEY}" - secret_access_key: "${S3_SECRET_KEY}" - bucket: "${S3_BUCKET}" - skip_cleanup: true - region: "eu-central-1" - local_dir: "build" - upload-dir: "phar" - acl: "public-read" - on: - branch: master diff --git a/.version.yml.dist b/.version.yml.dist index 8f9ea50..af920a5 100644 --- a/.version.yml.dist +++ b/.version.yml.dist @@ -1,3 +1,3 @@ version: - tag: "${TRAVIS_BRANCH}" - commit: "${TRAVIS_COMMIT}" + tag: "${GITHUB_REF}" + commit: "${GITHUB_SHA}" diff --git a/README.md b/README.md index cc87cef..5114c8a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ Shopware plugin manager ======================= +[![Test and build](https://github.com/solutionDrive/sdSwPluginManager/actions/workflows/test-and-build.yml/badge.svg)](https://github.com/solutionDrive/sdSwPluginManager/actions/workflows/test-and-build.yml) + This is a CLI based plugin manager that can simply install, uninstall, enable or disable plugins in a shopware shop. The shopware instance needs not to be fully working for this plugin manager to work as it is designed to be independent from the Shopware core itself. diff --git a/composer.json b/composer.json index a623333..e89e19e 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,8 @@ ], "require-dev": { "mikey179/vfsstream": "^1.6", - "solutiondrive/standalone-build-tools": "^1.0" + "solutiondrive/standalone-build-tools": "^2.0", + "symfony/var-dumper": "^2.1" }, "config": { "sort-packages": true, @@ -31,8 +32,12 @@ "phpspec-standalone.php7.1.phar": "http://build-tools.cloud.solutiondrive.de/phar/phpspec-standalone.php7.1.phar", "phpspec-standalone.php7.2.phar": "http://build-tools.cloud.solutiondrive.de/phar/phpspec-standalone.php7.2.phar", "phpspec-standalone.php7.3.phar": "http://build-tools.cloud.solutiondrive.de/phar/phpspec-standalone.php7.3.phar", + "phpspec-standalone.php7.4.phar": "http://build-tools.cloud.solutiondrive.de/phar/phpspec-standalone.php7.4.phar", "ecs-standalone.phar": "http://build-tools.cloud.solutiondrive.de/phar/coding-standard-standalone.ecs.php7.2.phar", - "easy-coding-standard-php7.1.yml": "http://build-tools.cloud.solutiondrive.de/phar/easy-coding-standard-php7.1.yml" + "easy-coding-standard.yml": "http://build-tools.cloud.solutiondrive.de/phar/easy-coding-standard-php7.1.yml" + }, + "allow-plugins": { + "solutiondrive/standalone-build-tools": true } } } diff --git a/etc/scripts/checkCodingStandards.sh b/etc/scripts/checkCodingStandards.sh index f04d866..e9923da 100755 --- a/etc/scripts/checkCodingStandards.sh +++ b/etc/scripts/checkCodingStandards.sh @@ -1,4 +1,4 @@ #!/usr/bin/env bash FOLDERS="./src ./spec" -vendor/bin/ecs-standalone.phar check --no-progress-bar -n -c vendor/bin/easy-coding-standard-php7.1.yml $FOLDERS $@ +vendor/bin/ecs-standalone.phar check --no-progress-bar -n -c vendor/bin/easy-coding-standard.yml $FOLDERS $@ diff --git a/spec/Entity/ConfiguredPluginStateSpec.php b/spec/Entity/ConfiguredPluginStateSpec.php index 08ae1eb..b326f34 100644 --- a/spec/Entity/ConfiguredPluginStateSpec.php +++ b/spec/Entity/ConfiguredPluginStateSpec.php @@ -82,7 +82,7 @@ public function it_has_default_parameters(): void false ); - $this->getAlwaysReinstall()->shouldReturn(true); + $this->getAlwaysReinstall()->shouldReturn(false); $this->getRemoveDataOnReinstall()->shouldReturn(false); $this->getAlwaysClearCache()->shouldReturn(false); } diff --git a/spec/Repository/StateFileSpec.php b/spec/Repository/StateFileSpec.php index 18bb650..c3360ab 100644 --- a/spec/Repository/StateFileSpec.php +++ b/spec/Repository/StateFileSpec.php @@ -57,7 +57,7 @@ public function it_can_read_from_array_and_get_plugins( 'testPlugin2' => [ 'provider' => 'http', 'version' => '1', - 'alwaysReinstall' => false, + 'alwaysReinstall' => true, 'removeDataOnReinstall' => true, 'alwaysClearCache' => true, ], @@ -73,7 +73,7 @@ public function it_can_read_from_array_and_get_plugins( 'installed' => true, 'activated' => true, 'env' => [], - 'alwaysReinstall' => true, + 'alwaysReinstall' => false, 'removeDataOnReinstall' => false, 'alwaysClearCache' => false, ]) @@ -90,7 +90,7 @@ public function it_can_read_from_array_and_get_plugins( 'installed' => true, 'activated' => true, 'env' => [], - 'alwaysReinstall' => false, + 'alwaysReinstall' => true, 'removeDataOnReinstall' => true, 'alwaysClearCache' => true, ]) diff --git a/src/Command/AutomaticDeployCommand.php b/src/Command/AutomaticDeployCommand.php index 6cc8487..4205d28 100644 --- a/src/Command/AutomaticDeployCommand.php +++ b/src/Command/AutomaticDeployCommand.php @@ -63,9 +63,9 @@ protected function configure(): void ->addOption( 'env', 'e', - InputOption::VALUE_REQUIRED, - 'The current environment to use for plugin filtering', - 'production' + InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, + 'The current environment(s) to use for plugin filtering, when using multiple only the first one is used for shopware commands.', + ['production'] ) ->addOption( 'skip-download', @@ -105,7 +105,8 @@ protected function execute( $forceDownload = (bool) $input->getOption('force-download'); $skipInstall = (bool) $input->getOption('skip-install'); - $environment = $input->getOption('env'); + $environments = $input->getOption('env'); + $yamlStateFilePath = $input->getArgument('statefile'); if (false === \is_readable($yamlStateFilePath)) { throw new \RuntimeException( @@ -122,7 +123,7 @@ protected function execute( if (false === $skipDownload) { foreach ($this->stateFile->getPlugins() as $configuredPluginState) { // Skip if plugin should not be installed in the current environment - if ($this->skipPluginByEnviroment($environment, $configuredPluginState->getEnvironments())) { + if ($this->skipPluginByEnviroments($environments, $configuredPluginState->getEnvironments())) { continue; } @@ -151,13 +152,13 @@ protected function execute( if (false === $skipInstall) { $refreshPluginCommand = new ArrayInput([ 'command' => 'sd:plugins:refresh', - '--env' => $environment, + '--env' => $environments[0], ]); $app->run($refreshPluginCommand, $output); $pluginListCommand = new ArrayInput([ 'command' => 'sd:plugin:list', - '--env' => $environment, + '--env' => $environments[0], ]); $bufferedOutput = new BufferedOutput($output->getVerbosity(), $output->isDecorated()); @@ -168,7 +169,7 @@ protected function execute( // And now install and activate all plugins (if configured) foreach ($this->stateFile->getPlugins() as $configuredPluginState) { // Skip if plugin should not be installed in the current environment - if ($this->skipPluginByEnviroment($environment, $configuredPluginState->getEnvironments())) { + if ($this->skipPluginByEnviroments($environments, $configuredPluginState->getEnvironments())) { continue; } @@ -176,7 +177,7 @@ protected function execute( $parameters = [ 'command' => 'sd:plugins:install', 'pluginId' => $configuredPluginState->getId(), - '--env' => $environment, + '--env' => $environments[0], ]; if (false === $configuredPluginState->getAlwaysReinstall()) { @@ -195,10 +196,17 @@ protected function execute( $app->run($input, $output); if ($this->pluginVersionService->pluginNeedsUpdate($configuredPluginState)) { - $updatePluginCommand = new ArrayInput([ + $parameters = [ 'command' => 'sd:plugin:update', 'plugin' => $configuredPluginState->getId(), - ]); + '--env' => $environments[0], + ]; + + if ($configuredPluginState->getAlwaysClearCache()) { + $parameters['--clear-cache'] = null; + } + + $updatePluginCommand = new ArrayInput($parameters); $app->run($updatePluginCommand, $output); } } else { @@ -206,7 +214,7 @@ protected function execute( 'command' => 'sd:plugins:uninstall', '--secure' => true, 'pluginId' => $configuredPluginState->getId(), - '--env' => $environment, + '--env' => $environments[0], ]; if ($configuredPluginState->getAlwaysClearCache()) { @@ -222,7 +230,7 @@ protected function execute( $parameters = [ 'command' => 'sd:plugins:activate', 'pluginId' => $configuredPluginState->getId(), - '--env' => $environment, + '--env' => $environments[0], ]; if ($configuredPluginState->getAlwaysClearCache()) { @@ -235,7 +243,7 @@ protected function execute( $parameters = [ 'command' => 'sd:plugins:deactivate', 'pluginId' => $configuredPluginState->getId(), - '--env' => $environment, + '--env' => $environments[0], ]; if ($configuredPluginState->getAlwaysClearCache()) { @@ -264,14 +272,23 @@ protected function execute( } /** + * @param string[] $currentEnvironments * @param string[] $targetEnvironments */ - private function skipPluginByEnviroment( - string $currentEnvironment, + private function skipPluginByEnviroments( + array $currentEnvironments, array $targetEnvironments ): bool { - return - false === empty($targetEnvironments) && - false === \in_array($currentEnvironment, $targetEnvironments); + if (empty($targetEnvironments)) { + return false; + } + + foreach ($currentEnvironments as $environment) { + if (\in_array($environment, $targetEnvironments)) { + return false; + } + } + + return true; } }