Skip to content

Instantly share code, notes, and snippets.

@guanguans
Forked from overtrue/gist:0bf1cd704bf804de2e2c
Last active March 14, 2019 03:50
Show Gist options
  • Save guanguans/3e5089033732c44115bd382ce05b5488 to your computer and use it in GitHub Desktop.
Save guanguans/3e5089033732c44115bd382ce05b5488 to your computer and use it in GitHub Desktop.
deploy.php
<?php
error_reporting(1);
$target = __DIR__ . '/../website.com'; // 生产环境web目录
$token = '您在coding填写的hook令牌';
$wwwUser = 'apache';
$wwwGroup = 'apache';
$json = json_decode(file_get_contents('php://input'), true);
if (empty($json['token']) || $json['token'] !== $token) {
exit('error request');
}
$repo = $json['repository']['name'];
$dir = __DIR__ . '/repos/' . $repo;
$cmds = array(
"cd $dir && git pull",
"rm -rf $target/* && cp -r $dir/* $target/",
"chown -R {$wwwUser}:{$wwwGroup} $target/",
);
foreach ($cmds as $cmd) {
shell_exec($cmd);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment