#!/usr/bin/env python3 """画个标 Gitea webhook 监听(push main 时自动部署)""" import http.server, subprocess, json, os, datetime DEPLOY_SCRIPT = '/opt/drawlogo/deploy/deploy.sh' class Handler(http.server.BaseHTTPRequestHandler): def do_POST(self): length = int(self.headers.get('Content-Length', 0)) body = self.rfile.read(length) try: data = json.loads(body) if body else {} ref = data.get('ref', '') if ref == 'refs/heads/main': subprocess.Popen( ['/bin/bash', DEPLOY_SCRIPT], stdout=open('/opt/drawlogo/.deploy.log', 'a'), stderr=subprocess.STDOUT ) except Exception: pass self.send_response(200) self.end_headers() self.wfile.write(b'ok') def log_message(self, format, *args): pass if __name__ == '__main__': http.server.HTTPServer(('0.0.0.0', 7890), Handler).serve_forever()