Skip to content

GitHub Webhook GO

简介

Webhook 安装配置

准备脚本

指定目录准备脚本文件

shell
vi /root/webhook/hook.sh
chmod +x /root/webhook/hook.sh

脚本参考

shell
#!/bin/bash
echo "hello webhook"
exit 0

安装 webhook

shell
cd ~
wget https://ghproxy.com/https://github.com/yezihack/github-webhook/releases/download/v1.5.0/github-webhook1.5.0.linux-amd64.tar.gz
tar -zxvf github-webhook1.5.0.linux-amd64.tar.gz
cp ~/github-webhook /usr/local/sbin
chmod u+x /usr/local/sbin/github-webhook

配置启动

!> 注意修改脚本路径和密码

shell
cat > /lib/systemd/system/github-webhook.service << EOF
[Unit]
Description=github-webhook
Documentation=https://github.com/yezihack/github-webhook
After=network.target
 
[Service]
Type=simple
ExecStart=/usr/local/sbin/github-webhook --bash /root/webhook/hook.sh --secret xxxxxx
Restart=on-failure
RestartSec=5s
 
[Install]
WantedBy=multi-user.target
EOF

启动命令

shell
systemctl daemon-reload
systemctl start github-webhook
systemctl status github-webhook
systemctl enable github-webhook
systemctl restart github-webhook
systemctl stop github-webhook

其他运行命令

shell
nohup github-webhook --bash /home/my.sh --secret mysecret -q &
# Daemonize run 后台运行
github-webhook --bash /home/my.sh --secret mysecret
# Monitor run
github-webhook --bash /home/my.sh --secret mysecret --quiet
#Quiet mode run
github-webhook --bash /home/my.sh --secret mysecret --port 6100 --quiet
# Custom port mode run
github-webhook --bash /home/my.sh --quiet
# Hidden secret mode run

相关参数

shell
GLOBAL OPTIONS:
   --bash value, -b value    Execute the script path. eg: /home/hook.sh 自定义脚本
   --port value, -p value    http port (default: 2020) 自定义端口,默认6666
   --secret value, -s value  github hook secret 自定义密码, 不允许为空
   --verbose, --vv           print verbose (default: false) 打印更多详细信息
   --quiet, -q               quiet operation (default: false) 安静模式,默认关闭. -q 开启,不输出任何信息
   --help, -h                show help (default: false) 
   --version, -v             print the version (default: false)

GitHub 配置

GitHub 仓库 - Settings - Webhooks - Add webhook