mini-deploy/deploy_bitbucket.php

39 lines
904 B
PHP
Executable File

<?php
// SETUP
$ref = 'master';
$logfile = 'logs/deploy-log.txt';
$input = json_decode(file_get_contents('php://input')); // BitBucket payload
$remoteref = $input->push->changes[0]->new->name;
// LOGIC
if ($remoteref == $ref) {
$commands = array(
'echo $PWD',
'whoami',
'git pull',
'git status',
);
$log = "####### ".date('Y-m-d H:i:s'). " #######\n";
$log .= 'deploying ref: '.$ref;
echo 'deploying ref: '.$ref;
foreach($commands AS $command){
$tmp = shell_exec("$command 2>&1");
$log .= "\n\$ $command\n".trim($tmp)."\n";
}
$log .= "\n";
file_put_contents($logfile,$log,FILE_APPEND);
} else if(!isset($remoteref)) {
die('no ref');
} else {
die('wrong ref: '.$remoteref);
}
// OTHER HELPFUL COMMANDS
/*
'git submodule sync',
'git submodule update',
'git submodule status',
'test -e /usr/share/update-notifier/notify-reboot-required && echo "system restart required"',
*/