This commit is contained in:
wandoubaba 2023-07-04 14:44:55 +08:00
parent 145ba879bf
commit ce00fa26fa

View File

@ -17,74 +17,20 @@ $worker->onConnect = function ($connection) {
}; };
$worker->onMessage = function (TcpConnection $connection, Request $request) { $worker->onMessage = function (TcpConnection $connection, Request $request) {
$work_dir = isset($_ENV['WORK_DIR']) ? $_ENV['WORK_DIR'] : null; $work_dir = '/www/wwwroot/fs.book.wandoubaba.com';
$branch = isset($_ENV['BRANCH']) ? $_ENV['BRANCH'] : null; $branch = 'master';
$git_url = isset($_ENV['GIT_URL']) ? $_ENV['GIT_URL'] : null; $git_url = 'git@git.wandoubaba.com:wandoubaba/knowledge.git';
// var_dump(json_encode($request->post('repository'), JSON_UNESCAPED_UNICODE));
if ($work_dir && $branch && $git_url) {
$repository = $request->post('repository'); $repository = $request->post('repository');
if (is_array($repository)) { if (is_array($repository)) {
$ssh_url = isset($repository['ssh_url']) ? $repository['ssh_url'] : null; $ssh_url = isset($repository['ssh_url']) ? $repository['ssh_url'] : null;
$clone_url = isset($repository['clone_url']) ? $repository['clone_url'] : null; $clone_url = isset($repository['clone_url']) ? $repository['clone_url'] : null;
if ($git_url === $ssh_url || $git_url === $clone_url) { if ($git_url === $ssh_url || $git_url === $clone_url) {
chdir($work_dir); chdir($work_dir);
shell_exec("sh auto_build.sh"); shell_exec("sh auto_build.sh > /dev/null &");
// shell_exec("git reset --hard FETCH_HEAD");
// shell_exec("yarn install");
// shell_exec("yarn build");
$connection->send("Deployment finished\n"); $connection->send("Deployment finished\n");
$connection->close(); $connection->close();
} }
} }
}
// $connection->send($request->post());
// if ($work_dir && $branch) {
// chdir($work_dir);
// exec("git fetch origin $branch");
// exec("git reset --hard FETCH_HEAD");
// exec("yarn install");
// exec("yarn build");
// $connection->send("Deployment finished\n");
// $connection->close();
// }
// 设置工作目录
// $WORK_DIR = "/www/wwwroot/fs.book.wandoubaba.com";
// 设置远程仓库地址
// $REMOTE_REPO = "git@git.wandoubaba.com:wandoubaba/knowledge.git";
// 设置分支名称
// $BRANCH = "master";
// 验证请求是否合法
// $secret = "your-webhook-secret";
// $signature = $_SERVER['HTTP_X_HUB_SIGNATURE'] ?? '';
// $body = $data;
// if (!hash_equals('sha1=' . hash_hmac('sha1', $body, $secret), $signature)) {
// $connection->send("Invalid request\n");
// $connection->close();
// return;
// }
// // 切换到工作目录
// chdir($WORK_DIR);
// // 拉取最新代码
// exec("git fetch origin $BRANCH");
// exec("git reset --hard FETCH_HEAD");
// // 执行相关命令
// exec("yarn install");
// exec("yarn build");
// $connection->send("Deployment finished\n");
// $connection->close();
}; };
// 运行worker // 运行worker