]> Frank Brehm's Git Trees - profitbricks/jenkins-build-scripts.git/commitdiff
debian_build: further changes intended to enable CI magic for vdc-bundles
authorMathias Klette <mathias.klette@profitbricks.com>
Wed, 22 May 2013 17:53:34 +0000 (19:53 +0200)
committerMathias Klette <mathias.klette@profitbricks.com>
Wed, 22 May 2013 17:53:34 +0000 (19:53 +0200)
debian_build.py

index 13516fb9de7966c3e870e36f829d22b8857b2065..d2e9bb4e57f092f043f25f8345ba8f949008e455 100755 (executable)
@@ -70,6 +70,8 @@ UNSTABLE_BRANCHES_RE = re.compile(
     '^(origin/)?(develop|pre-staging|release/.*)$')
 EXPERIMENTAL_BRANCHES_RE = re.compile(
     '^(origin/)?(experimental|integration|(feature|poc|bugfix)/.*)$')
+COMMIT_TRIGGER_BRANCHES_RE = re.compile(
+    '^(origin/)?(feature/.*)$')
 
 def getopts():
     usage = '%prog [options]'
@@ -121,6 +123,7 @@ if __name__ == '__main__':
     do_liveboot_request = False
     do_reports = True
     do_tagging = False
+    do_triggers = False
     do_uploads = True
 
     cl = changelog.Changelog()
@@ -136,12 +139,15 @@ if __name__ == '__main__':
     reports_file = os.path.join(ENV['WORKSPACE'], '../build-area/result/reports.tgz',)
     gitrepo = git.Repo('.')
     curr_commit = gitrepo.commit(ENV['GIT_COMMIT'])
-    # used in python-git 0.3.2~RC1-1 found in wheezy
+    # collect all 'trigger' expressions found in the commit message
+    commit_triggers = re.findall('\[([^\]]+)\]', curr_commit.message)
+    # id attribute used in python-git 0.3.2~RC1-1 found in wheezy
     if hasattr(curr_commit, 'hexsha'):
         curr_commit_id = curr_commit.hexsha
-    # used in python-git 0.1.6-1 found in squeeze
+    # id attribute used in python-git 0.1.6-1 found in squeeze
     elif hasattr(curr_commit, 'id'):
         curr_commit_id = curr_commit.id
+        
 
     # .. dput related (some overrides happening below, though)
     dput_obj = dput.Dput(
@@ -159,6 +165,9 @@ if __name__ == '__main__':
 
 
     # Act II: make decissions
+    if re.match(COMMIT_TRIGGER_BRANCHES_RE, ENV['GIT_BRANCH']):
+        do_triggers = True
+
     if re.match(STABLE_BRANCHES_RE, ENV['GIT_BRANCH']):
         new_dist = 'stable'
         new_version = '{version}'.format(
@@ -248,6 +257,7 @@ if __name__ == '__main__':
             ))
         exit_error()
 
+
     #FIXME: enable this once Florian acks.
     #FIXME: get rid of jenkins parameter, instead use git remote
     #if GIT_REPO_PATH.startswith('/srv/git/dev/'):
@@ -263,6 +273,8 @@ if __name__ == '__main__':
     logger.debug('Distribution: "%s" => "%s"' %(curr_dist,new_dist))
     logger.debug('Version: "%s" => "%s"' %(curr_version,new_version))
     logger.debug('PB_SUITE: ' + pb_suite)
+    if do_triggers:
+        logger.debug('Triggers found: ' + commit_triggers)
     if do_tagging:
         logger.debug('Tag to create: ' + new_tag)
     logger.debug('Upload configuration:\n%s' %(pformat(dput_obj.contents)))
@@ -297,30 +309,48 @@ if __name__ == '__main__':
 
             if len(files) > 0:
                 logger.info('Delete previous upstream tarball(s)')
-                cmd = [BIN_SUDO, BIN_RM, '-v']
-                cmd.extend(files)
-                ret = subprocess.Popen(
-                    cmd,
-                    shell=False,
-                    cwd='/',
-                    close_fds=True,
-                    stdout=sys.stdout,
-                    stderr=subprocess.STDOUT,
-                    env={'':''}
-                    ).wait()
-                logger.debug('"{cmd}" returns {exitcode}.'.format(
-                    cmd = cmd,
-                    exitcode = ret
-                    ))
+                cmd = [BIN_SUDO, BIN_RM, '-v'] + files
+                if subprocess.check_call(cmd):
+                    logger.info(cmd + ' succeeded.')
+                else:
+                    logger.warn(cmd + ' failed.')
+
         figlet('Cleanup OK')
 
+
+    # .. do some CI magic now, if requested
+    if do_triggers:
+
+        if 'merge' in commit_triggers:
+            if 'no-test' in commit_triggers:
+                logger.info('Force building with tests as we also merge your branch.')
+                commit_triggers.remove('no-test')
+
+            src_branch = ENV['GIT_BRANCH']   # save the original branch
+            dst_branch = 'integration'       # define the new branch
+            ENV['GIT_BRANCH'] = dst_branch   # reset env for git-buildpackage
+            # FIXME: error handling when rebase doesn't cleanly complete?
+            gitrepo.git.rebase('--onto', dst_branch, src_branch)
+            gitrepo.git.checkout(dst_branch)
+            logger.info('Checked out "%s" branch after rebase completed from branch "%s".' %(
+                dst_branch, src_branch))
+
+        if 'no-test' in commit_triggers:
+            # debian/rules from vdc-bundles determines maven options for tests
+            # depending whether DEB_NOTEST environment variable is defined
+            # FIXME: ensure this environment variable is available in chroot
+            #        (i.e. sudo)
+            ENV.update({'DEB_NOTEST':'TRUE'})
+        
+
     # .. NOW we can verify debian/control contents
     for line in fileinput.input('debian/control'):
         if line.lower().startswith('section: unknown'):
             raise Exception('debian/control sets "section" to unknown. This is not allowed, failing...')
             exit_error()
 
-    # .. update changelog if we trust the package
+
+    # .. and update changelog if we trust the package
     if do_autoincrement:
         subprocess.check_call([BIN_DCH, '-i', 'Released by jenkins.'])
         subprocess.check_call([BIN_GIT_DCH, '-R', '-a', '--spawn-editor=none'])
@@ -328,7 +358,7 @@ if __name__ == '__main__':
         gitrepo.git.push('origin', 'master')
         logger.info('Changelog incremented by jenkins using debian_build.py!')
 
-    # .. or to set approriate versions for development candidates
+    # .. or set approriate versions for our development candidates
     else:
         cmd = [
             BIN_DCH,
@@ -371,7 +401,7 @@ if __name__ == '__main__':
             logger.info('Changelog updated by Jenkins using debian_build.py!')
 
 
-    # let me see the first two changelog entries:
+    # let me see the first two entries or our adjusted changelog:
     # TODO: use changelog python libs instead of DCH calls, see above
     cl = changelog.Changelog()
     cl.parse_changelog(open('debian/changelog'))
@@ -392,6 +422,8 @@ if __name__ == '__main__':
     ret = gbp.build()
 
     # .. remove last commit (the one where we added the changelog entry)
+    # FIXME: when 'merge': reset only on original branch? 
+    #                      change checkout back to original branch?
     gitrepo.git.reset('--soft', 'HEAD~1')
 
     # .. now handle the result