搬砖仔

  • {{ item.name }}
  • SVN迁移至GIT
  • Gitea Webhook 实现自动拉取代码
  • 首页
  • 作品
  • 代码
  • GO
  • 随笔
  • 关于博主
  • 友情链接
  • 文章归档
  • 榜上有名
  • Mail
  • GitHub

Gitea Webhook 实现自动拉取代码

  • 小酱沫
  • 2019-04-08
  • 33

SVN迁移至GIT

选择了几款不错的代码托管解决方案,最终选择了Gitea,公司的svn代码也在逐步迁移至git中
迁移方案如下:

git svn clone http://svn.jinjiajin.net/test
git remote add origin http://git.jinjiajin.net/jinjiajin/test.git
git pull --rebase origin master
git push -u origin master

Gitea Webhook 实现自动拉取代码

  • hooks.php
 <?php
    // 安全验证字符串,为空则不验证
    $token = '123456';
    //  payload为字符串,需要经过解析
    $payload = file_get_contents('php://input');
    if (!$payload) {
        header('HTTP/1.1 400 Bad Request');
        die('HTTP HEADER or POST is missing.');
    }
    $content = json_decode($payload, true);
    // 如果启用验证,并且验证失败,返回错误
    if ($token && $content['secret'] != $token) {
        header('HTTP/1.1 403 Permission Denied');
        die('Permission denied.');
    }
    // shell_exec函数默认是禁止的,无法使用的话需要进php.ini修改相关配置
    echo shell_exec("/gitshell.sh");
    die("done " . date('Y-m-d H:i:s', time()));
  • gitshell.sh
#!/bin/sh
DeployPath="/data/test"
cd $DeployPath
git pull origin master 2>&1
./app/base/cmd update
exit 0
© 2023 搬砖仔
Theme by Wing
沪ICP备2021031606号-1 沪公网安备31010402004615号