]> Frank Brehm's Git Trees - profitbricks/jenkins-build-scripts.git/commitdiff
debian_build: extend gitrepo object with a dict of all remotes
authorMathias Klette <mathias.klette@profitbricks.com>
Tue, 28 May 2013 14:40:22 +0000 (16:40 +0200)
committerMathias Klette <mathias.klette@profitbricks.com>
Tue, 28 May 2013 14:40:22 +0000 (16:40 +0200)
this dict is then used to verify whether any package shall have auto-increment
enabled.

debian_build.py

index 1a5b33dd3c815136c30e51a0dfad58b8841596e0..bb347690cf2b07821fc6f0b2f6150a911a1b9abd 100755 (executable)
@@ -119,10 +119,9 @@ if __name__ == '__main__':
     daily_date = BUILD_START.strftime('%Y%m%d%H%M%S')
 
     # .. repository related
+    gitrepo = git.Repo('.')
     local_branch = re.match('^(origin/)?(.*)', ENV['GIT_BRANCH']).groups()[1]
     remote_branch = os.path.join('origin', local_branch)
-    reports_file = os.path.join(ENV['WORKSPACE'], '../build-area/result/reports.tgz',)
-    gitrepo = git.Repo('.')
     curr_commit = gitrepo.commit(ENV['GIT_COMMIT'])
     # collect all 'trigger' expressions found in the commit message, i.e.
     #   <<< "[merge][no-test][provisioning] my commit message"
@@ -134,6 +133,15 @@ if __name__ == '__main__':
     # id attribute used in python-git 0.1.6-1 found in squeeze
     elif hasattr(curr_commit, 'id'):
         curr_commit_id = curr_commit.id
+    # this should be part of 'git' lib, but it isn't right now
+    gitrepo.remotes = {}
+    for remote in gitrepo.git.remote('-v').split('\n'):
+        name, url, type = remote.split()
+        type = type.strip('()')
+        if not gitrepo.remotes.has_key(name):
+            gitrepo.remotes.update({name: {type: url}})
+        else:
+            gitrepo.remotes[name].update({type: url})
 
     # Act II: make decissions
     # compatibility until call_jenkins was replaced
@@ -150,7 +158,7 @@ if __name__ == '__main__':
     if re.match(STABLE_BRANCHES_RE, ENV['GIT_BRANCH']):
         if re.match('^(ps_|dev_).*$', ENV['JOB_NAME']):
             logger.error('Use the appropriate job to build for branch "{branch}"!'.format(
-                branch=ENV['GIT_BRANCH'],
+                branch=local_branch,
             ))
             exit_error()
         new_dist = 'stable'
@@ -161,8 +169,7 @@ if __name__ == '__main__':
         # replace valid debian version chars that are invalid for git tagging
         new_tag = curr_version.replace('~', '_').replace(':', ',')
         # .. only take care of changelog automation if we want it to
-        # FIXME: this must be reponame in ...
-        if ENV['GIT_BRANCH'] in AUTO_CHANGELOG_REPONAMES:
+        if gitrepo.remotes['origin']['fetch'].split('/')[-1] in AUTO_CHANGELOG_REPONAMES:
             do_autoincrement = True
         # reset actions
         if curr_dist == 'squeeze':
@@ -185,7 +192,7 @@ if __name__ == '__main__':
     elif re.match(UNSTABLE_BRANCHES_RE, ENV['GIT_BRANCH']):
         if not re.match('^ps_.*$', ENV['JOB_NAME']):
             logger.error('Use the appropriate job to build for branch "{branch}"!'.format(
-                branch=ENV['GIT_BRANCH'],
+                branch=local_branch,
             ))
             exit_error()
         new_dist = 'unstable'
@@ -205,7 +212,7 @@ if __name__ == '__main__':
     elif re.match(EXPERIMENTAL_BRANCHES_RE, ENV['GIT_BRANCH']):
         if not re.match('^dev_.*$', ENV['JOB_NAME']):
             logger.error('Use the appropriate job to build for branch "{branch}"!'.format(
-                branch=ENV['GIT_BRANCH'],
+                branch=local_branch,
             ))
             exit_error()
 
@@ -221,7 +228,7 @@ if __name__ == '__main__':
 
     else:
         logger.error('Don\'t know how to handle branch "{branch}".'.format(
-            branch=ENV['GIT_BRANCH'],
+            branch=local_branch,
         ))
         exit_error()
 
@@ -454,6 +461,10 @@ if __name__ == '__main__':
         figlet('Reports skipped')
     else:
         try:
+            reports_file = os.path.join(
+                ENV['WORKSPACE'],
+                '../build-area/result/reports.tgz',
+            )
             if os.path.exists(reports_file):
                 for cmd in (['/bin/tar', 'xzvf', reports_file, '-C', ENV['WORKSPACE']],
                             ['/usr/bin/sudo', '/bin/rm', '-v', reports_file]):