Skip to content

Instantly share code, notes, and snippets.

@philbirnie
Created March 21, 2017 18:35
Show Gist options
  • Save philbirnie/1f877bde78b2bb54add4642fdbfe9be1 to your computer and use it in GitHub Desktop.
Save philbirnie/1f877bde78b2bb54add4642fdbfe9be1 to your computer and use it in GitHub Desktop.
Webook deployment script
<?php
/** @var string Secret Key $secret */
$secret = '';
/** @var bool $debugging */
$debugging = false;
$webDirectory = '/var/www/html/';
/** @var array $headers */
$headers = getallheaders();
/** @var string $rawResponse (Payload) */
$rawResponse = file_get_contents( 'php://input' );
/** @var stdClass $decodedPayload */
$decodedPayload = json_decode( $rawResponse );
$repoSSHUrl = $decodedPayload->repository->ssh_url;
/** @var string $keyVerification */
$keyVerification = hash_hmac( 'sha1', $rawResponse, $secret );
if ( ! $debugging && ! isset( $headers['X-Hub-Signature'] ) || str_replace( 'sha1=', '',
$headers['X-Hub-Signature'] ) !== $keyVerification
) {
header( 'Invalid Git Key', true, 400 );
exit;
}
/** Initialize The Bare Repository **/
if ( ! is_dir( $webDirectory . '/.git' ) ) {
chdir($webDirectory);
exec('git clone ' . $repoSSHUrl . ' . ');
}
/** Only Deploy on the master branch **/
if($decodedPayload->ref === 'refs/heads/master') {
/** Site Specific Deployment **/
/** Synchronize Working Directory **/
chdir($webDirectory);
exec('git pull');
/** Run Gulp Task **/
chdir($webDirectory . '/fabricator');
exec($webDirectory . 'fabricator/node_modules/gulp/bin/gulp.js &');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment