Last active
December 27, 2024 07:52
-
-
Save horsley/7269392 to your computer and use it in GitHub Desktop.
一个简单的post hook用来自动部署
This file contains hidden or 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 | |
/** | |
* 简单自动部署 | |
* bitbucket POST hook http://horsley:anypassword@your_host/autodeploy.php | |
*/ | |
define('APP_PATH', dirname(__FILE__)); | |
if (php_sapi_name() != 'cli') { | |
if (!isset($_SERVER['PHP_AUTH_USER'])) { | |
header('WWW-Authenticate: Basic realm="My Realm"'); | |
header('HTTP/1.0 401 Unauthorized'); | |
die('Restricted Area!'); | |
} else { | |
if (($_SERVER['PHP_AUTH_USER'] != 'horsley') || | |
($_SERVER['PHP_AUTH_PW'] != 'anypassword') | |
) { | |
die('Authentication Failed.'); | |
} | |
} | |
} | |
if (file_exists(APP_PATH.'/_before_deploy.php')) { | |
echo "====== Tasks before update ======\n"; | |
require(APP_PATH.'/_before_deploy.php'); | |
} | |
echo "\n\n====== Now update the repo ======\n"; | |
chdir(); | |
system('git pull'); | |
if (file_exists(APP_PATH.'/_after_deploy.php')) { | |
echo "\n\n====== Tasks after update ======\n"; | |
require(APP_PATH.'/_after_deploy.php'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment