-
Notifications
You must be signed in to change notification settings - Fork 21
/
deploy.php
54 lines (42 loc) · 1.37 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
#!/usr/bin/php
<?php
require "config.php";
chdir(CUSTOM_CONFIG::$ROOT_PATH);
require "libs/spyc.php";
@ list(, $request_file) = $_SERVER['argv'];
if ($request_file && file_exists('requests/' . $request_file)) {
if($request_data = file_get_contents('requests/' . $request_file)) {
unlink('requests/' . $request_file);
$request_data = unserialize($request_data);
chdir($request_data['path']);
foreach(array(
'git clone ' . $request_data['clone_url'] . ' ./',
'git reset --hard',
'git checkout ' . $request_data['branch'],
'git fetch origin',
'git rebase origin/'. $request_data['branch'] . ' ' . $request_data['branch'],
'git status',
) AS $command)
{
syslog(LOG_INFO, $command);
syslog(LOG_INFO, "===== " . shell_exec($command . " 2>&1"));
}
sleep(1);
$hooks = @ Spyc::YAMLLoad($request_data['hook_path']) ?: array();
syslog(LOG_INFO, serialize($hooks));
if(isset($hooks['writable'])) {
foreach($hooks['writable'] AS $make_writeable) {
$cmd = "chmod 777 -R " . $make_writeable . " 2>&1";
syslog(LOG_INFO, $cmd);
syslog(LOG_INFO, "===== " . shell_exec($cmd));
}
}
if(isset($hooks['after_deploy'])) {
foreach($hooks['after_deploy'] AS $after_deploy) {
$cmd = $after_deploy . " 2>&1";
syslog(LOG_INFO, $cmd);
syslog(LOG_INFO, "===== " . shell_exec($cmd));
}
}
}
}