-
Notifications
You must be signed in to change notification settings - Fork 2
/
marmdeployment.php
80 lines (68 loc) · 1.85 KB
/
marmdeployment.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
<?php
/**
* This script deploys a whole project
*
* It was invented by the marmalade GmbH team
*
* @author Jens Richter<richter@marmalade.de>
* @author Joscha Krug<krug@marmalade.de>
*/
if (php_sapi_name() == "cli")
{
$baseDir = (__DIR__)."/../";
include_once $baseDir.'marmdeployment.conf.php';
// Check environment
$handle = fopen($baseDir.'environment.txt','r');
if($handle == false)
{
die('Environemt not specified!');
}
$env = trim(fgets($handle));
fclose($handle);
// Check if environment is configured
if(!is_array($config[$env]))
{
die('Environment not configured');
}
$conf = $config[$env];
// Run hook before deployment
if(function_exists('before_run_hook'))
{
before_run_hook();
}
//Go to project root and deploy there
chdir($baseDir);
system("git pull origin " . $conf['project']['ref']);
//Now deploy the
foreach ($conf['modules'] as $name=>$module)
{
echo "\nWork on $name\n";
//Check if dir exists
if(!is_dir($baseDir.$module['dir']))
{
mkdir($baseDir.$module['dir'], 0755, true);
chdir($baseDir.$module['dir']);
system("git init");
system("git remote add origin ".$module['remote']);
system("git fetch origin -a");
system("git checkout ".$module['ref']);
}
else
{
chdir($baseDir.$module['dir']);
}
// pull the specified ref
system("git fetch origin -a");
system("git checkout ".$module['ref']);
system("git merge --ff-only origin/".$module['ref']);
}
chdir($baseDir . 'marmdeployment/');
if(function_exists('after_run_hook'))
{
after_run_hook();
}
}
else
{
echo "No execution from web.";
}