Skip to content

Commit ee18ab3

Browse files
Various code styling changes
1 parent 98911b7 commit ee18ab3

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

deploy.php

+20-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ function removeLockFile() {
2626
removeLockFile();
2727
die('File deploy-config.php does not exist');
2828
}
29+
30+
// Check configuration errors
2931
$err = array();
3032
if (!defined('ACCESS_TOKEN')) $err[] = 'Access token is not configured';
3133
if (!defined('REMOTE_REPOSITORY')) $err[] = 'Remote repository is not configured';
@@ -38,6 +40,7 @@ function removeLockFile() {
3840
if (!isset($_GET['t']) || $_GET['t'] !== ACCESS_TOKEN || ACCESS_TOKEN === '') {
3941
header($_SERVER['SERVER_PROTOCOL'] . ' 403 Forbidden', true, 403);
4042
}
43+
4144
// Prevent caching
4245
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
4346
header("Cache-Control: post-check=0, pre-check=0", false);
@@ -74,6 +77,7 @@ function removeLockFile() {
7477
<?php
7578
// The branch
7679
$branch = '';
80+
7781
// Process request headers
7882
$headers = getallheaders();
7983
if(isset($headers['X-Event-Key'])) {
@@ -111,7 +115,8 @@ function removeLockFile() {
111115
removeLockFile();
112116
exit;
113117
}
114-
}
118+
}
119+
115120
// Branch from webhook?
116121
if($branch) {
117122
// Only main branch is allowed for webhook deployments
@@ -197,10 +202,14 @@ function cmd($command, $print = true) {
197202

198203
// The commits
199204
$commits = array();
205+
200206
// The checkout commit
201207
$checkout = '';
208+
202209
// The current files version
203210
$version = '';
211+
212+
// Check if there is a git directory
204213
if (!is_dir(GIT_DIR)) {
205214
// Clone the repository into the GIT_DIR
206215
echo "\nGit directory not found, cloning repository\n";
@@ -237,19 +246,22 @@ function cmd($command, $print = true) {
237246
, $branch
238247
));
239248
}
249+
240250
// Get list of all commits
241251
$commits = cmd(sprintf(
242252
'git --no-pager --git-dir="%s.git" log --pretty=format:"%%h" origin/%s'
243253
, GIT_DIR
244254
, $branch)
245255
, false);
256+
246257
// Set checkout commit
247258
if(in_array($_GET['c'], $commits)) {
248259
$checkout = $_GET['c'];
249260
} else {
250261
$checkout = reset($commits);
251262
echo "\nPassed commit hash is blank or doesn't match existing commits. Assuming most recent commit in branch: $checkout\n";
252263
}
264+
253265
// Checkout specific commit
254266
echo "\nReset branch to commit $checkout in git directory\n";
255267
cmd(sprintf(
@@ -258,9 +270,11 @@ function cmd($command, $print = true) {
258270
, GIT_DIR
259271
, $checkout
260272
));
273+
261274
// Update the submodules
262275
echo "\nUpdating git submodules in git directory\n";
263276
cmd('git submodule update --init --recursive');
277+
264278
// Get current version or assume oldest commit
265279
if(file_exists(TARGET_DIR . 'VERSION')) {
266280
$version = trim(file_get_contents(TARGET_DIR . 'VERSION'));
@@ -273,6 +287,7 @@ function cmd($command, $print = true) {
273287
$version = end($commits);
274288
echo "No version file found, assuming current version is oldest commit\n";
275289
}
290+
276291
// Get list of added, modified and deleted files
277292
echo "\nGet list of files added, modified and deleted from $version to $checkout\n";
278293
$files = cmd(sprintf(
@@ -281,6 +296,7 @@ function cmd($command, $print = true) {
281296
, $version
282297
, $checkout
283298
));
299+
284300
// Count files that were added or modified. Add removed files to array.
285301
$added = $modified = 0;
286302
$deleted = array();
@@ -307,15 +323,18 @@ function cmd($command, $print = true) {
307323
, count($deleted)
308324
);
309325
echo "\nNOTE: repository files that have been modfied or removed in target directory will be resynced with repository even if not listed in commits\n";
326+
310327
// rsync all added and modified files (no deletes, exclude .git directory)
311328
cmd(sprintf(
312329
'rsync -rltgoDzvO %s %s --exclude=.git'
313330
, GIT_DIR
314331
, TARGET_DIR
315332
));
316333
echo "\nDeleting files removed from repository\n";
334+
317335
// Delete files removed in commits
318336
foreach($deleted as $file) unlink($file);
337+
319338
// Update version file to current commit
320339
echo "\nUpdate target directory version file to commit $checkout\n";
321340
cmd(sprintf(

0 commit comments

Comments
 (0)