Compare commits
3 Commits
7972becddd
...
5555808095
Author | SHA1 | Date | |
---|---|---|---|
5555808095 | |||
2ea2ce8e54 | |||
13d46ad901 |
@ -34,3 +34,12 @@ logo = "/logo.png"
|
|||||||
## Language specifier, used in RSS feed.
|
## Language specifier, used in RSS feed.
|
||||||
##
|
##
|
||||||
language = "en"
|
language = "en"
|
||||||
|
|
||||||
|
## Port that is used to listed to remote git push signals.
|
||||||
|
##
|
||||||
|
webhook_port = 14032
|
||||||
|
|
||||||
|
## Something that only git hosting and your server should know.
|
||||||
|
## See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Authorization
|
||||||
|
##
|
||||||
|
webhook_auth = "Basic you-secure-credentials"
|
||||||
|
3
remote_host.sh
Executable file
3
remote_host.sh
Executable file
@ -0,0 +1,3 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
python3 -m http.server --directory ./html/ & python3 ./tools/git_webhook.py
|
56
tools/git_webhook.py
Normal file
56
tools/git_webhook.py
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
from http.client import parse_headers
|
||||||
|
from http.server import BaseHTTPRequestHandler
|
||||||
|
from http.server import HTTPServer
|
||||||
|
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
import config
|
||||||
|
|
||||||
|
## Simple way to automatically pull and recompile on a remote server.
|
||||||
|
## Run this from the root directory.
|
||||||
|
##
|
||||||
|
## Currently supports:
|
||||||
|
## - Gitea (Via GET method).
|
||||||
|
##
|
||||||
|
|
||||||
|
|
||||||
|
class HttpHandler(BaseHTTPRequestHandler):
|
||||||
|
def do_GET(self):
|
||||||
|
got_gitea_push_event = False
|
||||||
|
got_auth = False
|
||||||
|
|
||||||
|
for header in self.headers:
|
||||||
|
match [header, self.headers[header]]:
|
||||||
|
case ["X-Gitea-Event", "push"]:
|
||||||
|
got_gitea_push_event = True
|
||||||
|
|
||||||
|
case ["Authorization", config.webhook_auth]:
|
||||||
|
got_auth = True
|
||||||
|
|
||||||
|
|
||||||
|
if not got_gitea_push_event or not got_auth:
|
||||||
|
self.send_response(400)
|
||||||
|
return
|
||||||
|
|
||||||
|
# todo: This way of doing it blocks both parties. Not ideal.
|
||||||
|
self.send_response(200)
|
||||||
|
|
||||||
|
subprocess.run(["git", "pull"])
|
||||||
|
subprocess.run(["./compile.sh"])
|
||||||
|
|
||||||
|
print("Pulled and recompiled.")
|
||||||
|
|
||||||
|
|
||||||
|
def run(server_class=HTTPServer, handler_class=HttpHandler):
|
||||||
|
server_address = ('', config.webhook_port)
|
||||||
|
httpd = server_class(server_address, handler_class)
|
||||||
|
try:
|
||||||
|
httpd.serve_forever()
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
httpd.server_close()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
run()
|
Loading…
Reference in New Issue
Block a user