2013-02-19 01:00:54 +01:00
|
|
|
#!/usr/bin/env python
|
2012-08-31 19:46:12 +02:00
|
|
|
#
|
2013-08-06 21:41:49 +02:00
|
|
|
# Zulip's post-receive hook. There is a symlink
|
2013-10-07 18:32:26 +02:00
|
|
|
# from /home/git/repositories/eng/zulip.git/hooks/post-receive
|
2013-10-04 20:23:48 +02:00
|
|
|
# to ~zulip/zulip/tools/post-receive
|
2013-07-24 23:24:13 +02:00
|
|
|
# on git.zulip.net. So to deploy changes to this script, run
|
2012-10-30 21:15:57 +01:00
|
|
|
#
|
2013-10-04 20:23:48 +02:00
|
|
|
# ssh zulip@git.zulip.net 'cd zulip; git pull'
|
2012-08-31 19:46:12 +02:00
|
|
|
#
|
2013-08-06 21:41:49 +02:00
|
|
|
# To send the Zulip notices, this script calls out to our
|
2013-02-20 01:16:55 +01:00
|
|
|
# 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
|
2013-08-06 21:41:49 +02:00
|
|
|
# the Zulip configuration; for the moment those are
|
2013-08-07 17:55:22 +02:00
|
|
|
# bots/githook-post-receive and bots/zulip_git_config.py,
|
2013-02-20 01:16:55 +01:00
|
|
|
# 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
|
2013-08-06 22:39:20 +02:00
|
|
|
from zulip_tools import check_output, ENDC, FAIL
|
2012-10-03 20:48:51 +02:00
|
|
|
|
2013-07-02 17:17:16 +02:00
|
|
|
def update_deployment(server, refname):
|
2013-10-08 20:47:45 +02:00
|
|
|
return subprocess.call(["ssh", "-l", "zulip", server, "--", "env", "-u", "GIT_DIR",
|
2013-10-04 19:19:57 +02:00
|
|
|
"/home/zulip/deployments/current/tools/update-deployment", refname])
|
2013-05-30 20:08:25 +02:00
|
|
|
|
2013-08-06 22:47:45 +02:00
|
|
|
def send_deployment_finished_message(branch, message):
|
2013-10-04 19:19:57 +02:00
|
|
|
subprocess.check_call(["/home/zulip/zulip/api/bin/zulip-send", "--user=commit-bot@zulip.com",
|
2013-05-30 20:08:25 +02:00
|
|
|
"--api-key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "--stream=commits",
|
2013-07-24 20:19:19 +02:00
|
|
|
"--site=https://staging.zulip.com",
|
2013-08-08 16:32:16 +02:00
|
|
|
(u"--subject=deploy \u21D2 %s" % (branch,)).encode("utf-8"), "--message=%s" % (message,)])
|
2012-10-17 03:02:21 +02:00
|
|
|
|
2013-02-15 23:01:55 +01:00
|
|
|
deployments = {
|
2013-07-14 06:11:00 +02:00
|
|
|
'refs/heads/prod': ('prod0.zulip.net', 'prod'),
|
|
|
|
'refs/heads/master': ('staging.zulip.net', 'master'),
|
2013-03-18 22:21:13 +01:00
|
|
|
'refs/heads/test-post-receive': None,
|
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:
|
2013-10-04 19:19:57 +02:00
|
|
|
p = subprocess.Popen("/home/zulip/zulip/bots/githook-post-receive",
|
2013-02-15 23:01:55 +01:00
|
|
|
stdin=subprocess.PIPE)
|
|
|
|
p.communicate(input=ln)
|
2013-03-18 22:21:13 +01:00
|
|
|
|
|
|
|
if deployments[refname]:
|
|
|
|
server, branch = deployments[refname]
|
2013-07-02 17:17:16 +02:00
|
|
|
ret = update_deployment(server, branch)
|
2013-05-30 20:08:25 +02:00
|
|
|
if ret == 0:
|
2013-08-06 22:47:45 +02:00
|
|
|
send_deployment_finished_message(branch, "deployment of `%s` finished successfully!" % (newrev[:12],))
|
2013-05-30 20:08:25 +02:00
|
|
|
else:
|
2013-08-06 22:47:45 +02:00
|
|
|
send_deployment_finished_message(branch, "deployment of `%s` failed!" % (newrev[:12],))
|
2013-06-05 00:17:32 +02:00
|
|
|
|
|
|
|
if newrev == '0000000000000000000000000000000000000000':
|
|
|
|
# 0000000000000000000000000000000000000000 means we're deleting the ref
|
|
|
|
commits = ''
|
|
|
|
else:
|
|
|
|
commits = check_output(["git", "log", "%s..%s" % (oldrev, newrev)])
|
|
|
|
|
|
|
|
if '[schema]' in commits:
|
|
|
|
print
|
|
|
|
print FAIL + "Schema change detected! Please make the appropriate changes manually." + ENDC
|
|
|
|
print
|