From b698a487da345910f66bae151d2ed588aa606408 Mon Sep 17 00:00:00 2001 From: Thibaut Cheymol Date: Fri, 7 Jan 2022 09:41:22 +0100 Subject: [PATCH 1/7] Add Symfony 6 compatibility remove Symfony 2-3-4 --- composer.json | 17 +++++++------- src/Command/DeployCommand.php | 2 +- src/Command/RollbackCommand.php | 2 +- src/Deployer/DefaultDeployer.php | 2 ++ .../ConfigurationAdapterTest.php | 2 +- .../DefaultConfigurationTest.php | 15 ++++++------ tests/Server/ServerRepositoryTest.php | 2 +- tests/Server/ServerTest.php | 23 +++++++++---------- 8 files changed, 34 insertions(+), 31 deletions(-) diff --git a/composer.json b/composer.json index 68c4039..2c4fd3b 100644 --- a/composer.json +++ b/composer.json @@ -13,17 +13,18 @@ ], "require": { "php": ">=7.2.0", - "symfony/console": "~2.3|~3.0|~4.0|~5.0", - "symfony/dependency-injection": "~2.3|~3.0|~4.0|~5.0", - "symfony/expression-language": "~2.4|~3.0|~4.0|~5.0", - "symfony/filesystem": "~2.3|~3.0|~4.0|~5.0", - "symfony/http-foundation": "~2.3|~3.0|~4.0|~5.0", - "symfony/http-kernel": "~2.3|~3.0|~4.0|~5.0", + "symfony/config": "~5.0|~6.0", + "symfony/console": "~5.0|~6.0", + "symfony/dependency-injection": "~5.0|~6.0", + "symfony/expression-language": "~5.0|~6.0", + "symfony/filesystem": "~5.0|~6.0", + "symfony/http-foundation": "~5.0|~6.0", + "symfony/http-kernel": "~5.0|~6.0", "symfony/polyfill-mbstring": "^1.3", - "symfony/process": "~2.3|~3.0|~4.0|~5.0" + "symfony/process": "~5.0|~6.0" }, "require-dev": { - "phpunit/phpunit": "^6.1" + "phpunit/phpunit": "9.5.*" }, "config": { "sort-packages": true diff --git a/src/Command/DeployCommand.php b/src/Command/DeployCommand.php index a3c6a5c..54aaf82 100644 --- a/src/Command/DeployCommand.php +++ b/src/Command/DeployCommand.php @@ -69,7 +69,7 @@ protected function initialize(InputInterface $input, OutputInterface $output) $this->createDefaultConfigFile($input, $output, $defaultConfigPath, $input->getArgument('stage')); } - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $logFilePath = sprintf('%s/deploy_%s.log', $this->logDir, $input->getArgument('stage')); $context = new Context($input, $output, $this->projectDir, $logFilePath, true === $input->getOption('dry-run'), $output->isVerbose()); diff --git a/src/Command/RollbackCommand.php b/src/Command/RollbackCommand.php index 817905d..bf6f1f5 100644 --- a/src/Command/RollbackCommand.php +++ b/src/Command/RollbackCommand.php @@ -64,7 +64,7 @@ protected function initialize(InputInterface $input, OutputInterface $output) throw new \RuntimeException(sprintf("The default configuration file does not exist or it's not readable, and no custom configuration file was given either. Create the '%s' configuration file and run this command again.", $defaultConfigPath)); } - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $logFilePath = sprintf('%s/deploy_%s.log', $this->logDir, $input->getArgument('stage')); $context = new Context($input, $output, $this->projectDir, $logFilePath, true === $input->getOption('dry-run'), $output->isVerbose()); diff --git a/src/Deployer/DefaultDeployer.php b/src/Deployer/DefaultDeployer.php index fa28adc..a0ee19c 100644 --- a/src/Deployer/DefaultDeployer.php +++ b/src/Deployer/DefaultDeployer.php @@ -224,6 +224,8 @@ private function findConsoleBinaryPath(Server $server): string if (null === $server->get(Property::console_bin)) { throw new InvalidConfigurationException(sprintf('The "console" binary of your Symfony application is not available in any of the following directories: %s. Configure the "binDir" option and set it to the directory that contains the "console" binary.', implode(', ', $symfonyConsoleBinaries))); } + + return $server->resolveProperties('{{ project_dir }}/bin/console'); } private function createRemoteDirectoryLayout(): void diff --git a/tests/Configuration/ConfigurationAdapterTest.php b/tests/Configuration/ConfigurationAdapterTest.php index e6bedbf..30b8021 100644 --- a/tests/Configuration/ConfigurationAdapterTest.php +++ b/tests/Configuration/ConfigurationAdapterTest.php @@ -21,7 +21,7 @@ class ConfigurationAdapterTest extends TestCase /** @var DefaultConfiguration */ private $config; - protected function setUp() + protected function setUp(): void { $this->config = (new DefaultConfiguration(__DIR__)) ->sharedFilesAndDirs([]) diff --git a/tests/Configuration/DefaultConfigurationTest.php b/tests/Configuration/DefaultConfigurationTest.php index 7d3f1a1..d7071f0 100644 --- a/tests/Configuration/DefaultConfigurationTest.php +++ b/tests/Configuration/DefaultConfigurationTest.php @@ -12,34 +12,35 @@ namespace EasyCorp\Bundle\EasyDeployBundle\Tests; use EasyCorp\Bundle\EasyDeployBundle\Configuration\DefaultConfiguration; +use EasyCorp\Bundle\EasyDeployBundle\Exception\InvalidConfigurationException; use PHPUnit\Framework\TestCase; class DefaultConfigurationTest extends TestCase { /** * @dataProvider provideHttpRepositoryUrls - * @expectedException \EasyCorp\Bundle\EasyDeployBundle\Exception\InvalidConfigurationException - * @expectedExceptionMessageRegExp /The repository URL must use the SSH syntax instead of the HTTPs syntax to make it work on any remote server. Replace "https?:\/\/.*\/symfony\/symfony-demo.git" by "git@.*:symfony\/symfony-demo.git"/ */ public function test_repository_url_protocol(string $url) { + $this->expectException(InvalidConfigurationException::class); + $this->expectExceptionMessageMatches('/The repository URL must use the SSH syntax instead of the HTTPs syntax to make it work on any remote server. Replace "https?:\/\/.*\/symfony\/symfony-demo.git" by "git@.*:symfony\/symfony-demo.git"/'); + (new DefaultConfiguration(__DIR__)) ->repositoryUrl($url) ; } - /** - * @expectedException \EasyCorp\Bundle\EasyDeployBundle\Exception\InvalidConfigurationException - * @expectedExceptionMessage The value of resetOpCacheFor option must be the valid URL of your homepage (it must start with http:// or https://). - */ public function test_reset_opcache_for() { + $this->expectException(InvalidConfigurationException::class); + $this->expectExceptionMessage('The value of resetOpCacheFor option must be the valid URL of your homepage (it must start with http:// or https://).'); + (new DefaultConfiguration(__DIR__)) ->resetOpCacheFor('symfony.com') ; } - public function provideHttpRepositoryUrls() + public function provideHttpRepositoryUrls(): \Generator { yield ['http://github.com/symfony/symfony-demo.git']; yield ['https://github.com/symfony/symfony-demo.git']; diff --git a/tests/Server/ServerRepositoryTest.php b/tests/Server/ServerRepositoryTest.php index a32d1ed..90e683d 100644 --- a/tests/Server/ServerRepositoryTest.php +++ b/tests/Server/ServerRepositoryTest.php @@ -20,7 +20,7 @@ class ServerRepositoryTest extends TestCase /** @var ServerRepository */ private $servers; - protected function setUp() + protected function setUp(): void { $repository = new ServerRepository(); $repository->add(new Server('host0')); diff --git a/tests/Server/ServerTest.php b/tests/Server/ServerTest.php index c3960f9..1002b80 100644 --- a/tests/Server/ServerTest.php +++ b/tests/Server/ServerTest.php @@ -11,6 +11,7 @@ namespace EasyCorp\Bundle\EasyDeployBundle\EasyDeployBundle\Tests; +use EasyCorp\Bundle\EasyDeployBundle\Exception\ServerConfigurationException; use EasyCorp\Bundle\EasyDeployBundle\Server\Property; use EasyCorp\Bundle\EasyDeployBundle\Server\Server; use PHPUnit\Framework\TestCase; @@ -27,12 +28,10 @@ public function test_dsn_parsing(string $dsn, string $expectedHost, ?string $exp $this->assertSame($expectedPort, $server->getPort()); } - /** - * @expectedException \EasyCorp\Bundle\EasyDeployBundle\Exception\ServerConfigurationException - * @expectedExceptionMessage The host is missing (define it as an IP address or a host name) - */ public function test_dsn_parsing_error() { + $this->expectException(ServerConfigurationException::class); + $this->expectExceptionMessage('The host is missing (define it as an IP address or a host name)'); new Server('deployer@'); } @@ -115,16 +114,16 @@ public function test_resolve_properties(array $properties, string $expression, s /** * @dataProvider wrongExpressionProvider - * @expectedException \InvalidArgumentException - * @expectedExceptionMessageRegExp /The ".*" property in ".*" expression is not a valid server property./ */ public function test_resolve_unknown_properties(array $properties, string $expression) { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessageMatches('/The ".*" property in ".*" expression is not a valid server property./'); $server = new Server('host', [], $properties); $server->resolveProperties($expression); } - public function dsnProvider() + public function dsnProvider(): \Generator { yield ['123.123.123.123', '123.123.123.123', null, null]; yield ['deployer@123.123.123.123', '123.123.123.123', 'deployer', null]; @@ -143,7 +142,7 @@ public function dsnProvider() yield ['ssh://deployer@host:22001', 'host', 'deployer', 22001]; } - public function localDsnProvider() + public function localDsnProvider(): \Generator { yield ['local']; yield ['deployer@local']; @@ -158,7 +157,7 @@ public function localDsnProvider() yield ['deployer@127.0.0.1:22001']; } - public function serverRolesProvider() + public function serverRolesProvider(): \Generator { yield [[], []]; yield [[Server::ROLE_APP], [Server::ROLE_APP]]; @@ -166,7 +165,7 @@ public function serverRolesProvider() yield [['custom_role_1', 'custom_role_2'], ['custom_role_1', 'custom_role_2']]; } - public function sshConnectionStringProvider() + public function sshConnectionStringProvider(): \Generator { yield ['localhost', '']; yield ['123.123.123.123', 'ssh 123.123.123.123']; @@ -174,7 +173,7 @@ public function sshConnectionStringProvider() yield ['deployer@123.123.123.123:22001', 'ssh deployer@123.123.123.123 -p 22001']; } - public function expressionProvider() + public function expressionProvider(): \Generator { yield [['prop1' => 'aaa'], '{{ prop1 }}', 'aaa']; yield [['prop.1' => 'aaa'], '{{ prop.1 }}', 'aaa']; @@ -188,7 +187,7 @@ public function expressionProvider() yield [['prop1' => 'aaa', 'prop2' => 'bbb'], 'cd {{ prop1 }}{{ prop2 }}', 'cd aaabbb']; } - public function wrongExpressionProvider() + public function wrongExpressionProvider(): \Generator { yield [[], '{{ prop1 }}']; yield [['prop1' => 'aaa'], '{{ prop 1 }}']; From b7d6cb75031c5f1a7ef9b51546bf1a6258d0e3fc Mon Sep 17 00:00:00 2001 From: Thibaut Cheymol Date: Tue, 24 Jan 2023 11:24:25 +0100 Subject: [PATCH 2/7] :bug: [Hidden files] Make cp command copy hidden files from repo folder to current folder --- src/Deployer/DefaultDeployer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Deployer/DefaultDeployer.php b/src/Deployer/DefaultDeployer.php index a0ee19c..1f56990 100644 --- a/src/Deployer/DefaultDeployer.php +++ b/src/Deployer/DefaultDeployer.php @@ -263,7 +263,7 @@ private function doUpdateCode(): void $this->runRemote(sprintf('if [ -d {{ deploy_dir }}/repo ]; then cd {{ deploy_dir }}/repo && git fetch -q origin && git fetch --tags -q origin && git reset -q --hard %s && git clean -q -d -x -f; else git clone -q -b %s %s {{ deploy_dir }}/repo && cd {{ deploy_dir }}/repo && git checkout -q -b deploy %s; fi', $repositoryRevision, $this->getConfig(Option::repositoryBranch), $this->getConfig(Option::repositoryUrl), $repositoryRevision)); $this->log('

Copying the updated code to the new release directory'); - $this->runRemote(sprintf('cp -RPp {{ deploy_dir }}/repo/* {{ project_dir }}')); + $this->runRemote(sprintf('cp -pPRT {{ deploy_dir }}/repo/* {{ project_dir }}')); } private function doCreateCacheDir(): void From 6d9a1582b86773d45082d3499d18cb882c0de889 Mon Sep 17 00:00:00 2001 From: Thibaut Cheymol Date: Tue, 24 Jan 2023 11:53:41 +0100 Subject: [PATCH 3/7] :bug: [Update Code] Fix cp --- src/Deployer/DefaultDeployer.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Deployer/DefaultDeployer.php b/src/Deployer/DefaultDeployer.php index 1f56990..419d46f 100644 --- a/src/Deployer/DefaultDeployer.php +++ b/src/Deployer/DefaultDeployer.php @@ -263,7 +263,8 @@ private function doUpdateCode(): void $this->runRemote(sprintf('if [ -d {{ deploy_dir }}/repo ]; then cd {{ deploy_dir }}/repo && git fetch -q origin && git fetch --tags -q origin && git reset -q --hard %s && git clean -q -d -x -f; else git clone -q -b %s %s {{ deploy_dir }}/repo && cd {{ deploy_dir }}/repo && git checkout -q -b deploy %s; fi', $repositoryRevision, $this->getConfig(Option::repositoryBranch), $this->getConfig(Option::repositoryUrl), $repositoryRevision)); $this->log('

Copying the updated code to the new release directory'); - $this->runRemote(sprintf('cp -pPRT {{ deploy_dir }}/repo/* {{ project_dir }}')); + $this->runRemote(sprintf('cp -pPR {{ deploy_dir }}/repo/* {{ project_dir }}')); + $this->runRemote(sprintf('cp -p {{ deploy_dir }}/repo/.env* {{ project_dir }}')); } private function doCreateCacheDir(): void From 768db53ea441043b1b2d4a9cd0e70206426af70f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nils=20Lap=C3=B4tre?= Date: Fri, 8 Dec 2023 16:38:21 +0100 Subject: [PATCH 4/7] :art: [Deprecations] Fix return types --- src/Command/DeployCommand.php | 8 ++++---- src/Command/RollbackCommand.php | 8 ++++---- src/DependencyInjection/EasyDeployExtension.php | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Command/DeployCommand.php b/src/Command/DeployCommand.php index 54aaf82..e3fdb08 100644 --- a/src/Command/DeployCommand.php +++ b/src/Command/DeployCommand.php @@ -38,7 +38,7 @@ public function __construct(FileLocator $fileLocator, string $projectDir, string parent::__construct(); } - protected function configure() + protected function configure(): void { $this ->setName('deploy') @@ -50,7 +50,7 @@ protected function configure() ; } - protected function initialize(InputInterface $input, OutputInterface $output) + protected function initialize(InputInterface $input, OutputInterface $output): void { $customConfigPath = $input->getOption('configuration'); if (null !== $customConfigPath && !is_readable($customConfigPath)) { @@ -58,12 +58,12 @@ protected function initialize(InputInterface $input, OutputInterface $output) } if (null !== $customConfigPath && is_readable($customConfigPath)) { - return $this->configFilePath = $customConfigPath; + $this->configFilePath = $customConfigPath; } $defaultConfigPath = SymfonyConfigPathGuesser::guess($this->projectDir, $input->getArgument('stage')); if (is_readable($defaultConfigPath)) { - return $this->configFilePath = $defaultConfigPath; + $this->configFilePath = $defaultConfigPath; } $this->createDefaultConfigFile($input, $output, $defaultConfigPath, $input->getArgument('stage')); diff --git a/src/Command/RollbackCommand.php b/src/Command/RollbackCommand.php index bf6f1f5..d6c4be5 100644 --- a/src/Command/RollbackCommand.php +++ b/src/Command/RollbackCommand.php @@ -33,7 +33,7 @@ public function __construct(string $projectDir, string $logDir) parent::__construct(); } - protected function configure() + protected function configure(): void { $this ->setName('rollback') @@ -45,7 +45,7 @@ protected function configure() ; } - protected function initialize(InputInterface $input, OutputInterface $output) + protected function initialize(InputInterface $input, OutputInterface $output): void { $customConfigPath = $input->getOption('configuration'); if (null !== $customConfigPath && !is_readable($customConfigPath)) { @@ -53,12 +53,12 @@ protected function initialize(InputInterface $input, OutputInterface $output) } if (null !== $customConfigPath && is_readable($customConfigPath)) { - return $this->configFilePath = $customConfigPath; + $this->configFilePath = $customConfigPath; } $defaultConfigPath = SymfonyConfigPathGuesser::guess($this->projectDir, $input->getArgument('stage')); if (is_readable($defaultConfigPath)) { - return $this->configFilePath = $defaultConfigPath; + $this->configFilePath = $defaultConfigPath; } throw new \RuntimeException(sprintf("The default configuration file does not exist or it's not readable, and no custom configuration file was given either. Create the '%s' configuration file and run this command again.", $defaultConfigPath)); diff --git a/src/DependencyInjection/EasyDeployExtension.php b/src/DependencyInjection/EasyDeployExtension.php index 8c08e18..b52aa84 100644 --- a/src/DependencyInjection/EasyDeployExtension.php +++ b/src/DependencyInjection/EasyDeployExtension.php @@ -18,7 +18,7 @@ class EasyDeployExtension extends Extension { - public function load(array $configs, ContainerBuilder $container) + public function load(array $configs, ContainerBuilder $container): void { $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $loader->load('services.xml'); From b4781cefb429eff3d34429f6a96130072076364e Mon Sep 17 00:00:00 2001 From: Thibaut Cheymol Date: Thu, 4 Jan 2024 09:32:20 +0100 Subject: [PATCH 5/7] :arrow_up: [Upgrades] Support Symfony 7 --- composer.json | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index 2c4fd3b..1078eb8 100644 --- a/composer.json +++ b/composer.json @@ -13,15 +13,15 @@ ], "require": { "php": ">=7.2.0", - "symfony/config": "~5.0|~6.0", - "symfony/console": "~5.0|~6.0", - "symfony/dependency-injection": "~5.0|~6.0", - "symfony/expression-language": "~5.0|~6.0", - "symfony/filesystem": "~5.0|~6.0", - "symfony/http-foundation": "~5.0|~6.0", - "symfony/http-kernel": "~5.0|~6.0", + "symfony/config": "~5.0|~6.0|~7.0", + "symfony/console": "~5.0|~6.0|~7.0", + "symfony/dependency-injection": "~5.0|~6.0|~7.0", + "symfony/expression-language": "~5.0|~6.0|~7.0", + "symfony/filesystem": "~5.0|~6.0|~7.0", + "symfony/http-foundation": "~5.0|~6.0|~7.0", + "symfony/http-kernel": "~5.0|~6.0|~7.0", "symfony/polyfill-mbstring": "^1.3", - "symfony/process": "~5.0|~6.0" + "symfony/process": "~5.0|~6.0|~7.0" }, "require-dev": { "phpunit/phpunit": "9.5.*" From 5209a3db594d6788e273eaa853c8571a7398a358 Mon Sep 17 00:00:00 2001 From: Thibaut Cheymol Date: Thu, 4 Jan 2024 16:45:03 +0100 Subject: [PATCH 6/7] :bug: [Commands] Fix bug commands creating config file anyways --- src/Command/DeployCommand.php | 4 ++++ src/Command/RollbackCommand.php | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/Command/DeployCommand.php b/src/Command/DeployCommand.php index e3fdb08..eb0f3d6 100644 --- a/src/Command/DeployCommand.php +++ b/src/Command/DeployCommand.php @@ -59,11 +59,15 @@ protected function initialize(InputInterface $input, OutputInterface $output): v if (null !== $customConfigPath && is_readable($customConfigPath)) { $this->configFilePath = $customConfigPath; + + return; } $defaultConfigPath = SymfonyConfigPathGuesser::guess($this->projectDir, $input->getArgument('stage')); if (is_readable($defaultConfigPath)) { $this->configFilePath = $defaultConfigPath; + + return; } $this->createDefaultConfigFile($input, $output, $defaultConfigPath, $input->getArgument('stage')); diff --git a/src/Command/RollbackCommand.php b/src/Command/RollbackCommand.php index d6c4be5..c233615 100644 --- a/src/Command/RollbackCommand.php +++ b/src/Command/RollbackCommand.php @@ -54,11 +54,15 @@ protected function initialize(InputInterface $input, OutputInterface $output): v if (null !== $customConfigPath && is_readable($customConfigPath)) { $this->configFilePath = $customConfigPath; + + return; } $defaultConfigPath = SymfonyConfigPathGuesser::guess($this->projectDir, $input->getArgument('stage')); if (is_readable($defaultConfigPath)) { $this->configFilePath = $defaultConfigPath; + + return; } throw new \RuntimeException(sprintf("The default configuration file does not exist or it's not readable, and no custom configuration file was given either. Create the '%s' configuration file and run this command again.", $defaultConfigPath)); From 5f3b34612aeda19523cec81b97751d62e1384783 Mon Sep 17 00:00:00 2001 From: Thibaut Cheymol Date: Thu, 4 Jan 2024 17:02:37 +0100 Subject: [PATCH 7/7] :package: [Package] Update credentials --- composer.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 1078eb8..ff2158c 100644 --- a/composer.json +++ b/composer.json @@ -1,14 +1,14 @@ { - "name": "easycorp/easy-deploy-bundle", + "name": "reconnect/easy-deploy-bundle", "type": "symfony-bundle", "description": "The easiest way to deploy Symfony applications", "keywords": ["deploy", "deployment", "deployer"], - "homepage": "https://github.com/EasyCorp/easy-deploy-bundle", + "homepage": "https://github.com/reconnect/easy-deploy-bundle", "license": "MIT", "authors": [ { - "name": "Javier Eguiluz", - "email": "javiereguiluz@gmail.com" + "name": "Thibaut Cheymol", + "email": "thibaut.cheymol@gmail.com" } ], "require": {