mini-deploy/deploy_github.php

38 lines
858 B
PHP

<?php
// SETUP
$ref = 'refs/heads/master';
$logfile = 'logs/deploy-log.txt';
// LOGIC
$payload = json_decode($_POST['payload']); // GitHub payload
if ($payload->ref == $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($payload->ref)) {
die('no ref');
} else {
die('wrong ref: '.$payload->ref);
}
// 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"',
*/