-
-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy pathDeploy.php
103 lines (89 loc) · 2.58 KB
/
Deploy.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
/**
* @file Deploy.php
*
* Represents a single deploy action.
*/
namespace DevShop\Component\Deploy;
use DevShop\Component\Common\GitRepository;
use DevShop\Component\Common\GitRepositoryAwareTrait;
use DevShop\Component\DeployStageGit;
class Deploy {
use GitRepositoryAwareTrait;
const DEFAULT_STAGES = [
'git',
'build',
'deploy',
];
/**
* @return string[] List of stages that will be run by default during a deploy.
*/
public static function getDefaultStages(){
return self::DEFAULT_STAGES;
}
/**
* Get the list of stages that are run by default.
*
* @return string[] List of stages that run by default during a "deploy" command.
*/
public static function isDefaultStage($stage_name){
return in_array($stage_name, self::getDefaultStages());
}
/**
* @var DeployStage[] The stages to run during this deploy.
* @TODO: replace with protected access and addStage() method.
*/
public $stages = [];
/**
* @var DeployStage[] The stages to run during this deploy.
* @TODO: replace with protected access and addStage() method.
*/
public $options = [];
/**
* Deploy constructor.
*
* @param $stages
* @param \DevShop\Component\Common\GitRepository|null $repository
*/
function __construct($stages = null, GitRepository $repository = NULL) {
$this->stages = $stages;
$this->setRepository($repository);
}
/**
* @param $name
* @param null $value
*
* @return mixed|null
*/
public function setOption($name, $value = null) {
return $this->options[$name] = $value;
}
/**
* @param $name
* @param null $value
*
* @return string
*/
public function getOption($name, $value = null) {
return isset($this->options[$name])
? $this->options[$name]
: $value;
}
/**
* Run the stages.
* @TODO: Throw exceptions on fail.
*/
public function runStages() {
foreach ($this->stages as $stage) {
// @TODO: Make IOAware
$time = date(DATE_RFC2822);
$path = $stage->getRepository()->getRepositoryPath();
echo " -----------------------------------------------------------------------\n";
echo " Deploy Stage: $stage->name | $time \n";
echo " > $path \n";
echo " > {$stage->getCommand()} \n";
echo " -----------------------------------------------------------------------\n";
$stage->runStage();
}
}
}