-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.php
More file actions
43 lines (37 loc) · 1.77 KB
/
deploy.php
File metadata and controls
43 lines (37 loc) · 1.77 KB
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
<?php
/**
* This script is for easily deploying updates to Github repos to your local server. It will automatically git clone or
* git pull in your repo directory every time an update is pushed to your $BRANCH (configured below).
*
* Read more about how to use this script at http://behindcompanies.com/2014/01/a-simple-script-for-deploying-code-with-githubs-webhooks/
*
* INSTRUCTIONS:\
* 1. Edit the variables below
* 2. Upload this script to your server somewhere it can be publicly accessed
* 3. Make sure the apache user owns this script (e.g., sudo chown www-data:www-data webhook.php)
* 4. (optional) If the repo already exists on the server, make sure the same apache user from step 3 also owns that
* directory (i.e., sudo chown -R www-data:www-data)
* 5. Go into your Github Repo > Settings > Service Hooks > WebHook URLs and add the public URL
* (e.g., http://example.com/webhook.php)
*
**/
// Set Variables
$LOCAL_ROOT = "/home/site1/public_html/";
$LOCAL_REPO_NAME = "codeclub.cornwall.ac.uk";
$LOCAL_REPO = "{$LOCAL_ROOT}/{$LOCAL_REPO_NAME}";
$REMOTE_REPO = "https://github.com/CodeClubCornwall/Easter-School-Web.git";
$BRANCH = "master";
if ($_SERVER['HTTP_X_GITHUB_EVENT'] == 'push') {
// Only respond to requests from Github
if( file_exists($LOCAL_REPO) ) {
// If there is already a repo, just run a git pull to grab the latest changes
echo shell_exec("cd {$LOCAL_REPO} && git reset --hard origin/master");
echo shell_exec("cd {$LOCAL_REPO} && git pull 2>&1 ");
die("done " . mktime());
} else {
// If the repo does not exist, then clone it into the parent directory
echo shell_exec("cd {$LOCAL_ROOT} && git clone {$REMOTE_REPO} 2>&1");
die("done " . mktime());
}
}
?>