2015-10-04 18:56:26 +02:00
|
|
|
#!/usr/bin/env python2.7
|
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
|
|
|
|
|
2016-03-10 17:15:34 +01:00
|
|
|
from __future__ import print_function
|
2013-10-25 23:46:02 +02:00
|
|
|
import os
|
2012-08-31 19:46:12 +02:00
|
|
|
import sys
|
|
|
|
import subprocess
|
2013-10-25 23:46:02 +02:00
|
|
|
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
|
2013-11-08 22:45:20 +01:00
|
|
|
from zulip_tools import 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-31 18:44:49 +01: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",
|
2015-02-06 07:10:02 +01:00
|
|
|
"--site=https://zulip.com",
|
2013-12-11 17:41:54 +01:00
|
|
|
(u"--subject=%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'),
|
2014-09-12 02:14:24 +02:00
|
|
|
'refs/heads/dbx': ('dbx.zulip.net', 'dbx'),
|
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:
|
2013-11-08 22:45:20 +01:00
|
|
|
commits = subprocess.check_output(["git", "log", "%s..%s" % (oldrev, newrev)])
|
2013-06-05 00:17:32 +02:00
|
|
|
|
|
|
|
if '[schema]' in commits:
|
2016-03-10 17:15:34 +01:00
|
|
|
print()
|
|
|
|
print(FAIL + "Schema change detected! Please make the appropriate changes manually." + ENDC)
|
|
|
|
print()
|