Skip to content

Commit c146a1b

Browse files
committed
implemented breaking execution command on errors
1 parent 578c0a0 commit c146a1b

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

DeployApplication.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
*/
2929
class DeployApplication
3030
{
31+
/** @var bool */
32+
public $breakOnExecError = true;
33+
3134
/**
3235
* Private key for protection
3336
* @var string
@@ -49,6 +52,9 @@ class DeployApplication
4952
/** @var boolean */
5053
private $logError = false;
5154

55+
/** @var bool */
56+
private $hasExecError = false;
57+
5258
/**
5359
* DeployApplication constructor.
5460
* @param string $securityKey string key for protect application
@@ -66,12 +72,14 @@ public function __construct($securityKey, $workPath = '.', $logFileName = 'git-d
6672
/**
6773
* Fastest executing for typical cases
6874
* @param array $customCommands
75+
* @return bool
6976
*/
7077
public function run(array $customCommands = [])
7178
{
7279
$this->begin();
73-
$this->execute($customCommands);
80+
$res = $this->execute($customCommands);
7481
$this->end();
82+
return $res;
7583
}
7684

7785
/**
@@ -87,17 +95,20 @@ public function begin()
8795
/**
8896
* Executing command like a command lines
8997
* @param array $customCommands you can execute custom commands
98+
* @return bool
9099
*/
91100
public function execute(array $customCommands = [])
92101
{
93102
if (!$this->checkSecurity()) {
94-
return;
103+
return false;
95104
}
105+
$this->hasExecError = false;
96106
if (empty($customCommands)) {
97107
$this->exec(['git branch', 'git pull']); // git pull && git log -1
98108
} else {
99109
$this->exec($customCommands);
100110
}
111+
return $this->hasExecError;
101112
}
102113

103114
/**
@@ -173,10 +184,14 @@ private function exec(array $commands)
173184
exec($command . ' 2>&1', $response, $error_code);
174185
if ($error_code > 0 && empty($response)) {
175186
$response = array('Error: ' . $error_code);
187+
$this->hasExecError = true;
176188
}
177189
$response = implode("\n", $response);
178190
$this->log($response . "\n" . ($response ? "\n" : ''));
179191
}
192+
if ($this->hasExecError && $this->breakOnExecError) {
193+
return;
194+
}
180195
}
181196
}
182197

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "optimistex/git-auto-deploy-ex",
3-
"version": "1.3.3",
3+
"version": "1.3.4",
44
"type": "library",
55
"description": "The little project for auto-deploying projects to a hosting",
66
"keywords": [

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "git-auto-deploy-ex",
3-
"version": "1.3.3",
3+
"version": "1.3.4",
44
"description": "The little project for auto-deploying projects to a hosting",
55
"main": "index.js",
66
"directories": {

0 commit comments

Comments
 (0)