Skip to content

Instantly share code, notes, and snippets.

@gracefullight
Last active August 10, 2017 01:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gracefullight/f57192bd4ab68d3724aa22f9126fc1be to your computer and use it in GitHub Desktop.
Save gracefullight/f57192bd4ab68d3724aa22f9126fc1be to your computer and use it in GitHub Desktop.
<?php
define('LOG_FILE_NAME', 'deploy.log');
// bitbucket payload
// https://confluence.atlassian.com/bitbucket/event-payloads-740262817.html#EventPayloads-Push
$input = json_decode(file_get_contents('php://input'), true);
$username = $input['actor']['username'];
$dpname = $input['actor']['display_name'];
$pushData = array_pop($input['push']['changes']);
$branch = $pushData['new'] ? $pushData['new']['name'] : '';
$now = date('Y-m-d H:i:s');
if($branch !== 'master'){
echo "{$branch} pushed {$now}";
exit;
}
$pull = shell_exec('git reset --hard HEAD && git pull origin master 2>&1');
$log = shell_exec('git log -1');
exec('composer install &');
$comment = "[{$now}] {$dpname} ({$username})".PHP_EOL.$pull.PHP_EOL.$log.PHP_EOL;
// deploy logging
file_put_contents(__DIR__.'/'.LOG_FILE_NAME, $comment, FILE_APPEND);
echo $comment;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment