Skip to content

Commit 80c1951

Browse files
committed
Merge remote-tracking branch 'dg/master' into custom
2 parents 1cb7a5d + bff1d3b commit 80c1951

17 files changed

Lines changed: 210 additions & 210 deletions

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
}
1515
],
1616
"require": {
17-
"php": ">=7.1",
17+
"php": ">=7.4",
1818
"ext-zlib": "*",
1919
"phpseclib/phpseclib": "^3.0"
2020
},
@@ -35,7 +35,7 @@
3535
"bin": ["deployment"],
3636
"extra": {
3737
"branch-alias": {
38-
"dev-master": "3.4-dev"
38+
"dev-master": "3.5-dev"
3939
}
4040
}
4141
}

readme.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,3 @@ ignoreTracked = "
6666
**Reason why I want this?**
6767
Sometimes I want to do a quick deploy, but first I have to run `composer install --no-dev`, run deployment, and run `composer install` which takes time. With this solution, it is possible to ignore the vendor folder, but keep those files tracked for future full deploy.
6868

69-
### 5. Return non-zero code when deploy fails
70-
- When deploy fails, non-zero code is returned. This means, exit code is not zero, which signaling error.
71-
- This is great especially for running in a pipeline
72-
- See commit [b3e62a8d](https://github.com/arxeiss/ftp-deployment/commit/b3e62a8dd67a685a2618582768392c0d5e766efa)
73-
74-
**Reason why I want this?**
75-
I used FTP Deployment in the Gitlab pipeline. Deploy failed, but the whole job succeded because the exit code was 0.

src/Deployment/CliRunner.php

Lines changed: 53 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
*/
1717
class CliRunner
1818
{
19-
/** @var array */
20-
public $defaults = [
19+
public array $defaults = [
2120
'local' => '',
2221
'fileOutputDir' => '',
2322
'passivemode' => true,
@@ -34,19 +33,17 @@ class CliRunner
3433
];
3534

3635
/** @var string[] */
37-
public $ignoreMasks = ['*.bak', '.svn', '.git*', 'Thumbs.db', '.DS_Store', '.idea'];
36+
public array $ignoreMasks = ['*.bak', '.svn', '.git*', 'Thumbs.db', '.DS_Store', '.idea'];
3837

39-
/** @var Logger */
40-
private $logger;
38+
private Logger $logger;
4139

42-
/** @var string */
43-
private $configFile;
40+
private string $configFile;
4441

45-
/** @var string|null test|generate|null */
46-
private $mode;
42+
/** test|generate|null */
43+
private ?string $mode;
4744

4845
/** @var array[] */
49-
private $batches = [];
46+
private array $batches = [];
5047

5148

5249
public function run(): ?int
@@ -72,50 +69,48 @@ public function run(): ?int
7269
$time = time();
7370
$this->logger->log('Started at ' . date('[Y/m/d H:i]'));
7471
$this->logger->log("Config file is $this->configFile");
72+
$res = 0;
7573

76-
$returnCode = 1;
7774

78-
try{
79-
foreach ($this->batches as $name => $batch) {
80-
$this->logger->log("\nDeploying $name");
75+
foreach ($this->batches as $name => $batch) {
76+
$this->logger->log("\nDeploying $name");
8177

82-
$deployment = $this->createDeployer($batch);
83-
$deployment->tempDir = $tempDir;
78+
$deployment = $this->createDeployer($batch);
79+
$deployment->tempDir = $tempDir;
8480

85-
if ($this->mode === 'generate') {
86-
$this->logger->log('Scanning files');
87-
$localPaths = $deployment->collectPaths();
88-
$this->logger->log('Saved ' . $deployment->writeDeploymentFile($localPaths));
89-
continue;
90-
}
91-
92-
if ($deployment->testMode) {
93-
$this->logger->log('Test mode', 'lime');
94-
} else if($deployment->fileOutputDir) {
95-
$this->logger->log('File Output mode', 'teal');
96-
} else {
97-
$this->logger->log('Live mode', 'aqua');
98-
}
99-
if (!$deployment->allowDelete) {
100-
$this->logger->log('Deleting disabled');
101-
}
81+
if ($this->mode === 'generate') {
82+
$this->logger->log('Scanning files');
83+
$localPaths = $deployment->collectPaths();
84+
$this->logger->log('Saved ' . $deployment->writeDeploymentFile($localPaths));
85+
continue;
86+
}
10287

88+
if ($deployment->testMode) {
89+
$this->logger->log('Test mode', 'lime');
90+
} else if($deployment->fileOutputDir) {
91+
$this->logger->log('File Output mode', 'teal');
92+
} else {
93+
$this->logger->log('Live mode', 'aqua');
94+
}
95+
if (!$deployment->allowDelete) {
96+
$this->logger->log('Deleting disabled');
97+
}
10398

99+
try{
104100
$deployment->deploy();
105-
$this->logger->log("\n\n");
101+
} catch (JobException | ServerException $e) {
102+
$this->logger->log("Error: {$e->getMessage()} in {$e->getFile()}:{$e->getLine()}\n\n$e", 'red');
103+
$res = 1;
106104
}
107-
$returnCode = 0;
108-
} catch (JobException | ServerException $e) {
109-
$this->logger->log("Error: {$e->getMessage()} in {$e->getFile()}:{$e->getLine()}\n\n$e", 'red');
110105
$this->logger->log("\n\n");
111106
}
112107

113108
$time = time() - $time;
114109
$this->logger->log(
115110
'Finished at ' . date('[Y/m/d H:i]') . " (in $time seconds)\n----------------------------------------------\n\n",
116-
$returnCode === 0 ? 'lime' : 'red'
111+
$res === 0 ? 'lime' : 'red'
117112
);
118-
return $returnCode;
113+
return $res;
119114
}
120115

121116

@@ -124,7 +119,7 @@ private function createDeployer(array $config): Deployer
124119
if (
125120
empty($config['remote'])
126121
|| !($urlParts = parse_url($config['remote']))
127-
|| !isset($urlParts['scheme'], $urlParts['host'])
122+
|| !isset($urlParts['scheme'])
128123
) {
129124
throw new \Exception("Missing or invalid 'remote' URL in config.");
130125
}
@@ -191,8 +186,10 @@ private function createDeployer(array $config): Deployer
191186
$deployment->deploymentFile = empty($config['deploymentfile'])
192187
? $deployment->deploymentFile
193188
: $config['deploymentfile'];
194-
$deployment->allowDelete = $config['allowdelete'];
195-
$deployment->alwaysRunActions = $config['alwaysrunactions'];
189+
190+
$deployment->allowDelete = (bool) $config['allowdelete'];
191+
$deployment->alwaysRunActions = (bool)$config['alwaysrunactions'];
192+
196193
$deployment->toPurge = self::toArray($config['purge'], true);
197194
$deployment->runBefore = self::toArray($config['before'], true);
198195
$deployment->runAfterUpload = self::toArray($config['afterupload'], true);
@@ -241,23 +238,24 @@ private function setupPhp(): void
241238

242239
private function loadConfig(): ?array
243240
{
244-
$cmd = new CommandLine(<<<'XX'
245241

246-
FTP deployment v3.4 - Pavel Kutáč edit
242+
$cmd = new CommandLine(
243+
<<<'XX'
244+
FTP deployment v3.5 - Pavel Kutáč edit
247245
248-
See more on https://github.com/arxeiss/ftp-deployment
249-
and original on https://github.com/dg/ftp-deployment
250-
-------------------
251-
Usage:
252-
deployment <config_file> [-t | --test]
246+
See more on https://github.com/arxeiss/ftp-deployment
247+
and original on https://github.com/dg/ftp-deployment
248+
-------------------
249+
Usage:
250+
deployment <config_file> [-t | --test]
253251
254-
Options:
255-
-t | --test Run in test-mode.
256-
--section <name> Only deploys the named section.
257-
--generate Only generates deployment file.
258-
--no-progress Hide the progress indicators.
252+
Options:
253+
-t | --test Run in test-mode.
254+
--section <name> Only deploys the named section.
255+
--generate Only generates deployment file.
256+
--no-progress Hide the progress indicators.
259257

260-
XX
258+
XX
261259
, [
262260
'config' => [CommandLine::REALPATH => true],
263261
]);

src/Deployment/CommandLine.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,15 @@ class CommandLine
2424
VALUE = 'default';
2525

2626
/** @var array[] */
27-
private $options = [];
27+
private array $options = [];
2828

2929
/** @var string[] */
30-
private $aliases = [];
30+
private array $aliases = [];
3131

3232
/** @var string[] */
33-
private $positional = [];
33+
private array $positional = [];
3434

35-
/** @var string */
36-
private $help;
35+
private string $help;
3736

3837

3938
public function __construct(string $help, array $defaults = [])

0 commit comments

Comments
 (0)