-
-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathsample_deploy.php
49 lines (40 loc) · 1.31 KB
/
sample_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
<?php
/**
* GitHub Deployment Script Sample
*/
$postHeaders = getallheaders();
$checkPostBody = file_get_contents('php://input');
$secret = '123ABC456DEF789'; // change this to match the secret you set e.g. on GitHub (mind to not add this file afterwards to your repo!)
$checkSum = 'sha1=' . hash_hmac('sha1', $checkPostBody, $secret);
$output = '';
if (isset($postHeaders['X-Hub-Signature']) and $checkSum == $postHeaders['X-Hub-Signature']) {
// The commands
$commands = array(
'git checkout master',
'git fetch --all',
'git reset --hard origin/master',
'git pull',
'git status',
'npm install', // remove if you do not want to minify the css and js on the server
'npm run build' // remove if you do not want to minify the css and js on the server
);
// Run the commands for output
foreach($commands as $command){
$tmp = shell_exec($command);
$output .= "\$" . $command . "\n";
$output .= htmlentities(trim($tmp)) . "\n";
}
}
?>
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>Updating Git</title>
</head>
<body style="background-color: #000000; color: #FFFFFF; font-weight: bold; padding: 10px;">
<pre>
<?php echo $output; // Remove this for more security. Still, since we check for the secret above, no strong need. ?>
</pre>
</body>
</html>