|
@@ -0,0 +1,28 @@
|
|
|
+from flask import Flask, request
|
|
|
+import subprocess
|
|
|
+
|
|
|
+app = Flask(__name__)
|
|
|
+
|
|
|
+# Webhook 路由
|
|
|
+@app.route('/webhook', methods=['POST'])
|
|
|
+def webhook():
|
|
|
+ # 获取推送的分支信息
|
|
|
+ data = request.json
|
|
|
+ if not data:
|
|
|
+ return "No data received", 400
|
|
|
+
|
|
|
+ # 确认推送到的分支
|
|
|
+ branch = data.get('ref', '')
|
|
|
+ if branch.endswith('main'): # 检查是否是 main 分支
|
|
|
+ try:
|
|
|
+ # 执行部署脚本
|
|
|
+ deploy_script = "/home/user/go-msa-auth/deploy.sh"
|
|
|
+ result = subprocess.run([deploy_script], shell=True, capture_output=True, text=True)
|
|
|
+ return f"Deployment triggered:\n{result.stdout}", 200
|
|
|
+ except Exception as e:
|
|
|
+ return f"Error during deployment: {str(e)}", 500
|
|
|
+
|
|
|
+ return "No action taken", 200
|
|
|
+
|
|
|
+if __name__ == '__main__':
|
|
|
+ app.run(host='0.0.0.0', port=5000)
|