forked from compiler-explorer/infra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhook.py
executable file
·68 lines (56 loc) · 1.88 KB
/
hook.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python
import tempfile
import logging
import shutil
import subprocess
import tornado.ioloop
import tornado.web
import json
import update_instances
def update_jsbeeb(branch, dest):
destdir = tempfile.mkdtemp()
subprocess.check_call([
'git', 'clone', '[email protected]:mattgodbolt/jsbeeb.git',
'-b', branch,
destdir
])
subprocess.check_call([
'make', '-C', destdir, 'upload', 'BRANCH=' + dest
])
shutil.rmtree(destdir)
class MainHandler(tornado.web.RequestHandler):
def post(self):
event = self.request.headers.get('X-GitHub-Event')
obj = json.loads(self.request.body)
logging.info("Got {}: {}".format(event, obj))
if event == 'ping':
logging.info("Got a ping")
self.write("OK")
return
if event != 'push':
raise RuntimeError("Unsupported")
if 'ref' not in obj:
logging.info("Skipping, no ref")
return
repo = obj['repository']['name']
branch = obj['ref']
hash = obj['after']
if repo == 'compiler-explorer':
if branch != 'refs/heads/master':
update_instances.build_deployment(hash)
if branch == 'refs/heads/release':
update_instances.update_compiler_explorers()
self.write("OK")
elif repo == 'jsbeeb':
if branch == 'refs/heads/release':
update_jsbeeb('release', '')
if branch == 'refs/heads/master':
update_jsbeeb('master', 'beta')
self.write("OK")
if __name__ == '__main__':
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)-8s %(module)s: %(message)s")
application = tornado.web.Application([
("/", MainHandler)
], debug=True)
application.listen(7453)
tornado.ioloop.IOLoop.instance().start()