update.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. error_reporting(E_ALL);
  3. header("Content-type: text/html; charset=utf-8");
  4. $p = json_decode($_REQUEST["hook"]); // json转换
  5. $fp = fopen("./log.txt", 'a');
  6. $lastcommit = $p->push_data->commits[count($js->push_data->commits) - 1]; // 获取最后的commit
  7. print_r($_SERVER);
  8. //if (strstr($lastcommit->message, "release")) // 这里意为:如果最后的commit包含"release"则进行自动发布。
  9. //{
  10. echo "<br>\n---- PWD ----- \n\n<br>";
  11. echo exec("pwd",$res1); // 进入目录
  12. print_r($res1);
  13. echo "<br>\n---- PRINTENV ----- \n\n<br>";
  14. echo exec("printenv", $res2); // 进入目录
  15. print_r($res2);
  16. echo "<br>\n---- CD ----- \n\n<br>";
  17. echo exec("cd ./"); // 进入目录
  18. echo "<br>\n---- GIT ----- \n\n<br>";
  19. echo exec("git pull origin master", $res3); // 进行git拉取,前提是使用了ssh
  20. print_r($res3);
  21. echo "<br>";
  22. echo exec("git log --graph", $res4); // 进行git拉取,前提是使用了ssh
  23. for($i=0;$i<count($res4);$i++){
  24. echo $res4[$i] . "<br>";
  25. }
  26. echo "<br>";
  27. fwrite($fp, "※" . date('Y-m-d H:i:s') . "\t" . $lastcommit->message . "\t" . $lastcommit->author->name . "\n"); // 进行记录
  28. echo "Pull Success";
  29. //} else {
  30. // fwrite($fp, date('Y-m-d H:i:s') . "\t" . $lastcommit->message . "\t" . $lastcommit->author->name . "\n");
  31. //}
  32. fclose($fp);
  33. ?>