Skip to content

Commit 4fc77eb

Browse files
committed
Add target option and remove PHP 7.4 support
1 parent b337c5f commit 4fc77eb

File tree

9 files changed

+316
-110
lines changed

9 files changed

+316
-110
lines changed

.github/workflows/tests.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
matrix:
1515
include:
1616
#Mini (for each Symfony version)
17-
- php-version: '7.4'
17+
- php-version: '8.0'
1818
symfony-version: '5.4.*'
1919
composer-flags: '--prefer-stable --prefer-lowest'
2020
description: 'with SF 5.4.* lowest'
@@ -51,7 +51,6 @@ jobs:
5151
description: 'with SF 7.1.* dev'
5252

5353
#PHP versions
54-
- php-version: '7.4'
5554
- php-version: '8.0'
5655
- php-version: '8.1'
5756
- php-version: '8.2'
@@ -63,7 +62,7 @@ jobs:
6362
coding-standards: true
6463

6564
#Static Analysis (min PHP version)
66-
- php-version: '7.4'
65+
- php-version: '8.0'
6766
description: 'with Static Analysis'
6867
static-analysis: true
6968

.php-cs-fixer.dist.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
'@Symfony' => true,
2020
'@Symfony:risky' => true,
2121
'@DoctrineAnnotation' => true,
22-
'@PHP74Migration' => true,
23-
'@PHP74Migration:risky' => true,
22+
'@PHP80Migration' => true,
23+
'@PHP80Migration:risky' => true,
2424
'@PHPUnit84Migration:risky' => true,
2525
'array_syntax' => ['syntax' => 'short'],
2626
'fopen_flags' => true,

README.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,17 @@ ecommit_deploy_rsync:
3131
#Environments configuration
3232
environments:
3333
my_server1: #Environment name
34-
hostname: myserver.com #SSH hostname - Required
35-
username: myuser #SSH username - Required
36-
dir: /home/remote_dir #SSH remote directory - Required
37-
#port: 22 #Port - Not required - Default value: 22
34+
#Target - Required
35+
#The target can be either an SSH target or a local target
36+
#SSH target format: ssh://<username>@<hostname>:<path> or ssh://<username>@<hostname>:<port>:<path>
37+
#Local target format: file://<path>
38+
target: ssh://[email protected]:/home/remote_dir
3839
#rsync_options: [] #Rsync command options - Not required - Default values: [] - If not defined, the global rsync_options is used
3940
#ignore_file: #Rsync ignore file - Not required - Default value: null - If not defined, the global ignore_file option is used
4041

4142
#You can define others environments :
4243
#my_server2:
43-
#hostname: myserver2.com
44-
#username: myser
45-
#dir: /home/remote_dir
44+
#target: ssh://[email protected]:/home/remote_dir
4645

4746
#Rsync global configuration
4847
#rsync:

UPGRADE-2.0.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# UPGRADE FROM 1.x to 2.0
2+
3+
The following options have been removed and replaced by the option `target` :
4+
* `hostname`
5+
* `port`
6+
* `username`
7+
* `dir`
8+
9+
Before :
10+
11+
```yaml
12+
ecommit_deploy_rsync:
13+
environments:
14+
my_server1:
15+
hostname: myserver.com
16+
username: myuser
17+
dir: /home/remote_dir
18+
19+
my_server2:
20+
hostname: myserver2.com
21+
port: 23
22+
username: myuser
23+
dir: /home/remote_dir
24+
```
25+
26+
After :
27+
28+
```yaml
29+
ecommit_deploy_rsync:
30+
environments:
31+
my_server1:
32+
target: ssh://[email protected]:/home/remote_dir
33+
34+
my_server2:
35+
target: ssh://[email protected]:23:/home/remote_dir
36+
```

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
},
1919
"extra": {
2020
"branch-alias": {
21-
"dev-master": "1.x-dev"
21+
"dev-master": "2.x-dev"
2222
}
2323
},
2424
"require": {
25-
"php": "^7.4|^8.0",
25+
"php": "^8.0",
2626
"ext-mbstring": "*",
2727
"symfony/config": "^5.4|^6.4|^7.0",
2828
"symfony/console": "^5.4|^6.4|^7.0",

src/Command/DeployRsyncCommand.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
#[AsCommand(name: 'ecommit:deploy-rsync', description: 'Deploy the application with RSYNC and SSH')]
2727
final class DeployRsyncCommand extends Command
2828
{
29+
public const TARGET_FILE_REGEX = '/^file:\/\/(?<path>.+)$/';
30+
public const TARGET_SSH_REGEX = '/^ssh:\/\/(?<username>.+)@(?<hostname>[^:]+)(:(?<port>\d+)){0,1}:(?<path>.+)$/';
31+
2932
/**
3033
* @var array
3134
*/
@@ -92,10 +95,17 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9295
if ($ignoreFile) {
9396
$command[] = '--exclude-from='.$ignoreFile;
9497
}
95-
$command[] = '-e';
96-
$command[] = sprintf('ssh -p%s', $environment['port']);
97-
$command[] = $this->getDirPath($this->projetDir);
98-
$command[] = sprintf('%s@%s:%s', $environment['username'], $environment['hostname'], $this->getDirPath($environment['dir']));
98+
if (preg_match(self::TARGET_FILE_REGEX, $environment['target'], $targetPats)) {
99+
$command[] = $this->getDirPath($this->projetDir);
100+
$command[] = $this->getDirPath($targetPats['path']);
101+
} elseif (preg_match(self::TARGET_SSH_REGEX, $environment['target'], $targetPats)) {
102+
$command[] = '-e';
103+
$command[] = sprintf('ssh -p%s', (isset($targetPats['port']) && '' !== $targetPats['port']) ? $targetPats['port'] : 22);
104+
$command[] = $this->getDirPath($this->projetDir);
105+
$command[] = sprintf('%s@%s:%s', $targetPats['username'], $targetPats['hostname'], $this->getDirPath($targetPats['path']));
106+
} else {
107+
throw new \Exception('Invalid target');
108+
}
99109

100110
foreach ($this->executeProcess($command) as $data) {
101111
$output->writeln($data);

src/DependencyInjection/Configuration.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace Ecommit\DeployRsyncBundle\DependencyInjection;
1515

16+
use Ecommit\DeployRsyncBundle\Command\DeployRsyncCommand;
1617
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
1718
use Symfony\Component\Config\Definition\ConfigurationInterface;
1819

@@ -33,10 +34,12 @@ public function getConfigTreeBuilder(): TreeBuilder
3334
->normalizeKeys(false)
3435
->arrayPrototype()
3536
->children()
36-
->scalarNode('hostname')->isRequired()->end()
37-
->integerNode('port')->defaultValue(22)->end()
38-
->scalarNode('username')->isRequired()->end()
39-
->scalarNode('dir')->isRequired()->end()
37+
->scalarNode('target')->isRequired()
38+
->validate()
39+
->ifTrue(fn (mixed $value) => !\is_string($value) || (!preg_match(DeployRsyncCommand::TARGET_FILE_REGEX, $value) && !preg_match(DeployRsyncCommand::TARGET_SSH_REGEX, $value)))
40+
->thenInvalid('Invalid target')
41+
->end()
42+
->end()
4043
->arrayNode('rsync_options')->prototype('scalar')->end()->end()
4144
->scalarNode('ignore_file')->end()
4245
->end()

0 commit comments

Comments
 (0)