Skip to content

Instantly share code, notes, and snippets.

@davidsword
Last active May 11, 2018 22:22
Show Gist options
  • Save davidsword/ab2089e5592223aee454cb10a78b5a38 to your computer and use it in GitHub Desktop.
Save davidsword/ab2089e5592223aee454cb10a78b5a38 to your computer and use it in GitHub Desktop.
Github deploy webhook location to pull any pushes from master
<?php
// just a pinch of authorization
$sig = hash_hmac('sha1', file_get_contents('php://input'), 'mywebhooksecrethere');
if (
$_POST['payload'] &&
$_SERVER['HTTP_X_GITHUB_EVENT'] == 'push' &&
$_SERVER['HTTP_X_HUB_SIGNATURE'] == 'sha1='.$sig
) {
$cmd = 'cd /var/www/path/to/repo && /usr/bin/git reset --hard HEAD 2>&1 && /usr/bin/git pull 2>&1';
$out = shell_exec( $cmd );
echo preg_match("/[up-to-date|Updating]/",$out) ? "🚀" : "🚫 {$out}";
} else {
echo "🤷🏼‍";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment