Last active
August 10, 2017 01:09
-
-
Save gracefullight/f57192bd4ab68d3724aa22f9126fc1be to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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