Skip to content

Instantly share code, notes, and snippets.

@cijagani
Forked from riodw/deploy.php
Last active January 15, 2021 13:19
Show Gist options
  • Save cijagani/9f7281fa8c6ab7e5ee1b3aded9e9eb84 to your computer and use it in GitHub Desktop.
Save cijagani/9f7281fa8c6ab7e5ee1b3aded9e9eb84 to your computer and use it in GitHub Desktop.
Deploy to Production Server with git using PHP
<?php
function isEnabled($func) {
return is_callable($func) && false === stripos(ini_get('disable_functions'), $func);
}
if (!isEnabled('shell_exec')) {
echo "shell_exec is disabled";
exit();
}
/**
* GIT DEPLOYMENT SCRIPT
*
*/
// The commands
$commands = array(
'echo $PWD',
'whoami',
'git remote show origin',
'git reset --hard HEAD',
'git reset --hard origin/master',
'git fetch --all',
'git log -1 --format="%at" | xargs -I{} date -d @{} +%Y-%M-%d--%Hh:%Im:%Ss:%A',
'git pull --rebase origin master --autostash',
'git status',
'git submodule sync',
'git submodule update',
'git submodule status',
'git show --summary',
);
// if you found error like : The following untracked working tree files would be overwritten by merge:
//git fetch --all
//git reset --hard origin/master
// Run the commands for output
$output = '';
foreach($commands AS $command){
// Run it
$tmp = shell_exec($command);
// Output
$output .= "<span style=\"color: #6BE234;\">\$</span> <span style=\"color: #FFC107;\"><i>{$command}</i>\n</span>";
$output .= htmlentities(trim($tmp)) . "\n---------------------------------------------------------------------------------------------\n\n";
}
// Make it pretty for manual user access (and why not?)
?>
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>GIT DEPLOYMENT SCRIPT</title>
</head>
<body style="background-color: #220022; color: #f5f4f4; padding: 0 10px;font-size:15px">
<pre>
____________________________
| |
| Git Deployment Script v0.2 |
| trueline labs | 2020 |
|____________________________|
<?php echo $output; ?>
</pre>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment