Created
February 4, 2011 06:59
-
-
Save rantav/810823 to your computer and use it in GitHub Desktop.
Post commit hook at outbrain used for Continuous Deployment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# POST-COMMIT HOOK | |
# | |
# The post-commit hook is invoked after a commit. Subversion runs | |
# this hook by invoking a program (script, executable, binary, etc.) | |
# named 'post-commit' (for which this file is a template) with the | |
# following ordered arguments: | |
# | |
# [1] REPOS-PATH (the path to this repository) | |
# [2] REV (the number of the revision just committed) | |
# | |
# The default working directory for the invocation is undefined, so | |
# the program should set one explicitly if it cares. | |
REPOS="$1" | |
REV="$2" | |
# invoke a build on teamc | |
/usr/bin/python /outbrain/svn/repos/hooks/post-commit-trigger-build-deploy.py "$REPOS" "$REV" || exit 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# | |
# reviewboard-post-commit-hook | |
# This script should be invoked from the subversion post-commit hook like this: | |
# | |
# REPOS="$1" | |
# REV="$2" | |
# /usr/bin/python /some/path/reviewboard-post-commit-hook.py "$REPOS" "$REV" "$AUTHOR" || exit 1 | |
# | |
import sys | |
import re | |
import svn.fs | |
import svn.core | |
import svn.repos | |
import urllib | |
# If true, runs post-review in debug mode and outputs its diff | |
DEBUG = True | |
TEAM_C_USERNAME = "xxx" | |
TEAM_C_PASSWORD = "xxx" | |
TEAM_C_HOSTNAME_PORT = "ci.outbrain.com" | |
TEAM_C_API_ENDPOINT = "httpAuth/action.html" | |
TEAM_C_URL = "http://%s:%s@%s/%s" % (TEAM_C_USERNAME, TEAM_C_PASSWORD, TEAM_C_HOSTNAME_PORT, TEAM_C_API_ENDPOINT) | |
def main(): | |
if len(sys.argv) != 3: | |
sys.stderr.write('Usage: %s <repos> <rev>\n' % sys.argv[0]) | |
sys.exit(1) | |
repos = sys.argv[1] | |
rev = sys.argv[2] | |
# verify that rev parameter is an int | |
try: | |
int(rev) | |
except ValueError: | |
sys.stderr.write("Parameter <rev> must be an int, was given %s\n" % rev) | |
sys.exit(1) | |
# get the svn file system object | |
fs_ptr = svn.repos.svn_repos_fs(svn.repos.svn_repos_open(svn.core.svn_path_canonicalize(repos))) | |
# get the log message | |
log = svn.fs.svn_fs_revision_prop(fs_ptr, int(rev), svn.core.SVN_PROP_REVISION_LOG) | |
# get the author | |
author = svn.fs.svn_fs_revision_prop(fs_ptr, int(rev), svn.core.SVN_PROP_REVISION_AUTHOR) | |
if DEBUG: | |
print "log: " + log | |
# error if log message is blank | |
if len(log.strip()) < 1: | |
sys.stderr.write("Log message is empty, no review request created\n") | |
sys.exit(1) | |
# | |
# extract the list of deployed artifacts from #deploy:ImageServer,RecEngine | |
# | |
modules_list = re.findall('#deploy:([^ ]*)', log) | |
if modules_list: | |
modules = modules_list[0] | |
tags = "none" # by default we relase to none | |
tags_list = re.findall('#tags:([^ ]*)', log) | |
to_list = re.findall('#to:([^ ]*)', log) | |
if tags_list: | |
tags = tags_list[0] | |
elif to_list: | |
tags = to_list[0] | |
params = "add2Queue=bt3&system.name=ob.module&system.value=" + modules + "&system.name=ob.tags&system.value=" + tags + "&system.name=commitRevision&system.value=" + rev +"&system.name=committer&system.value=" + author + "&system.name=commitMessage&system.value=" + urllib.quote(log) +"&moveToTop=true" | |
url = TEAM_C_URL + "?" + params | |
fetch(url) | |
def fetch(url): | |
"""Fetches a url""" | |
if DEBUG: | |
print "sending: %s" % (url) | |
f = urllib.urlopen(url) | |
s = f.read() | |
print "url request sent OK %s" % (url) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment