2012-08-31 19:46:12 +02:00
|
|
|
#!/usr/bin/python
|
|
|
|
#
|
2012-10-30 21:15:57 +01:00
|
|
|
# Humbug's post-receive hook. There is a symlink
|
|
|
|
# from /srv/git/humbug.git/hooks/post-receive
|
|
|
|
# to ~humbug/humbug/tools/post-receive
|
|
|
|
# on git.humbughq.com. So to deploy changes to this script, run
|
|
|
|
#
|
|
|
|
# ssh humbug@git.humbughq.com 'cd humbug; git pull'
|
2012-08-31 19:46:12 +02:00
|
|
|
#
|
2013-02-20 01:16:55 +01:00
|
|
|
# To send the Humbug notices, this script calls out to our
|
|
|
|
# for-distribution git hook (under api/integrations/); since the git
|
|
|
|
# hook needs to be in the same directory as the configuration script
|
|
|
|
# for the git hook, this means that we need to have a shared directory
|
|
|
|
# containing (a symlink to) both the the for-distribution git hook and
|
|
|
|
# the Humbug configuration; for the moment those are
|
|
|
|
# bots/githook-post-receive and bots/humbug_git_config.py,
|
|
|
|
# respectively. We need the intermediate symlink because the git hook
|
|
|
|
# looks for its configuration in the directory that it sits in, and
|
|
|
|
# api/integrations/git/ has the example configuration.
|
|
|
|
#
|
|
|
|
#
|
2012-08-31 19:46:12 +02:00
|
|
|
# The "post-receive" script is run after receive-pack has accepted a pack
|
|
|
|
# and the repository has been updated. It is passed arguments in through
|
|
|
|
# stdin in the form
|
|
|
|
# <oldrev> <newrev> <refname>
|
|
|
|
# For example:
|
|
|
|
# aa453216d1b3e49e7f6f98441fa56946ddcd6a20 68f7abf4e6f922807889f52bc043ecd31b79f814 refs/heads/master
|
|
|
|
#
|
|
|
|
# see contrib/hooks/ for a sample
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import subprocess
|
2012-10-03 20:48:51 +02:00
|
|
|
|
2013-02-15 23:01:55 +01:00
|
|
|
# check_output is backported from subprocess.py in Python 2.7
|
2012-10-03 20:48:51 +02:00
|
|
|
def check_output(*popenargs, **kwargs):
|
|
|
|
if 'stdout' in kwargs:
|
|
|
|
raise ValueError('stdout argument not allowed, it will be overridden.')
|
|
|
|
process = subprocess.Popen(stdout=subprocess.PIPE, *popenargs, **kwargs)
|
|
|
|
output, unused_err = process.communicate()
|
|
|
|
retcode = process.poll()
|
|
|
|
if retcode:
|
|
|
|
cmd = kwargs.get("args")
|
|
|
|
if cmd is None:
|
|
|
|
cmd = popenargs[0]
|
|
|
|
raise subprocess.CalledProcessError(retcode, cmd, output=output)
|
|
|
|
return output
|
|
|
|
subprocess.check_output = check_output
|
2012-10-03 20:31:59 +02:00
|
|
|
|
2012-11-06 17:09:07 +01:00
|
|
|
def update_deployment(server, oldrev, newrev, refname):
|
|
|
|
subprocess.check_call(["ssh", server, "--", "env", "-u", "GIT_DIR",
|
2012-09-17 17:47:20 +02:00
|
|
|
"/home/humbug/humbug/tools/update-deployment",
|
2012-08-31 20:16:50 +02:00
|
|
|
oldrev, newrev, refname])
|
2012-10-17 03:02:21 +02:00
|
|
|
|
2013-02-15 23:01:55 +01:00
|
|
|
deployments = {
|
|
|
|
'refs/heads/prod': ('humbughq.com', 'prod'),
|
|
|
|
'refs/heads/master': ('staging.humbughq.com', 'master'),
|
|
|
|
'refs/heads/test-post-receive': ('staging.humbughq.com', 'master'),
|
2012-10-03 20:31:59 +02:00
|
|
|
}
|
2012-10-03 21:18:16 +02:00
|
|
|
|
|
|
|
for ln in sys.stdin:
|
|
|
|
oldrev, newrev, refname = ln.strip().split()
|
2013-02-15 23:01:55 +01:00
|
|
|
if refname in deployments:
|
|
|
|
(server, branch) = deployments[refname]
|
2013-02-20 01:16:55 +01:00
|
|
|
p = subprocess.Popen("/home/humbug/humbug/bots/githook-post-receive",
|
2013-02-15 23:01:55 +01:00
|
|
|
stdin=subprocess.PIPE)
|
|
|
|
p.communicate(input=ln)
|
2013-02-20 01:16:55 +01:00
|
|
|
update_deployment(server, oldrev, newrev, "origin/" + branch)
|