]> Frank Brehm's Git Trees - profitbricks/jenkins-build-scripts.git/commitdiff
revert most of the previous commit and make it work
authorHolger Levsen <holger@layer-acht.org>
Wed, 9 Nov 2011 15:20:09 +0000 (16:20 +0100)
committerHolger Levsen <holger@layer-acht.org>
Wed, 9 Nov 2011 15:20:09 +0000 (16:20 +0100)
debian_build.py

index b45f41af9b62c656d5a3ce08b05214b17acab4ae..268ccff01464d979803587735a0c59fcb49a9b56 100755 (executable)
@@ -47,13 +47,9 @@ BUILD_NUMBER = os.environ.get('BUILD_NUMBER')
 BUILD_ID = os.environ.get('BUILD_ID')
 BUILD_URL = os.environ.get('BUILD_URL')
 
-#GIT_REPO_PATH = os.environ.get('GIT_REPO_PATH')
-#GIT_REPO_NAME = os.path.basename(GIT_REPO_PATH)
-#GIT_OLD_ID = os.environ.get('GIT_OLD_ID')
-#GIT_NEW_ID = os.environ.get('GIT_NEW_ID')
-#GIT_UPSTREAM_BRANCH = os.environ.get('GIT_UPSTREAM_BRANCH')
-#GIT_DEBIAN_BRANCH = os.environ.get('GIT_DEBIAN_BRANCH')
-#GIT_DEBIAN_REMOTE_BRANCH = os.path.join('origin', '%s' %(GIT_DEBIAN_BRANCH))
+GIT_REPO_PATH = os.environ.get('GIT_REPO_PATH')
+GIT_REPO_NAME = os.path.basename(GIT_REPO_PATH)
+GIT_BRANCH_NAME = os.environ.get('GIT_BRANCH_NAME')
 GIT_TARGET_WORKSPACE = os.path.join(
         CWD,
         ('%s-build%s' %(BUILD_ID, BUILD_NUMBER))
@@ -229,69 +225,60 @@ if __name__ == '__main__':
     )
     logging.getLogger('lib.git_helper').setLevel(logging.DEBUG)
     options, args = getopts()
-    #if git_helper.git_clone_remote_repository(GIT_REPO_PATH, GIT_TARGET_DIR):
-    #    logger.info('git clone was successfull')
-    #else:
-    #    logger_loud_error('git clone was not successfull')
-    #    exit_error()
+    if git_helper.git_clone_remote_repository(GIT_REPO_PATH, GIT_TARGET_DIR):
+        logger.info('git clone was successfull')
+    else:
+        logger_loud_error('git clone was not successfull')
+        exit_error()
 
-    #atexit.register(remove_git_target_workspace)
+    atexit.register(remove_git_target_workspace)
     os.chdir(GIT_TARGET_DIR)
 
-    #if not GIT_DEBIAN_BRANCH:
-    #    if GIT_UPSTREAM_BRANCH:
-    #        GIT_DEBIAN_BRANCH = GIT_UPSTREAM_BRANCH
-    #        logging.debug(
-    #                'setting GIT_DEBIAN_BRANCH to %s',
-    #                GIT_UPSTREAM_BRANCH
-    #        )
-    #    else:
-    #        logger_loud_error('Could not determine GIT_DEBIAN_BRANCH')
-    #        exit_error()
-    #elif not GIT_UPSTREAM_BRANCH:
-    #    if GIT_DEBIAN_BRANCH:
-    #        GIT_UPSTREAM_BRANCH = GIT_DEBIAN_BRANCH
-    #        logging.debug(
-    #                'setting GIT_UPSTREAM_BRANCH to %s',
-    #                GIT_UPSTREAM_BRANCH
-    #        )
-    #    else:
-    #        logger_loud_error('Could not determine GIT_UPSTREAM_BRANCH')
-    #        exit_error()
-    ##
-    #repo = git.repo.Repo()
-    #
-    #if GIT_DEBIAN_BRANCH != 'master':
-    #    git_helper.git_new_branch_from(
-    #            GIT_DEBIAN_BRANCH,
-    #            os.path.join('origin', GIT_DEBIAN_BRANCH)
-    #    )
+    # FIXME: this is just needed for gbp and can go away eventually
+    if GIT_BRANCH_NAME:
+        GIT_UPSTREAM_BRANCH = GIT_BRANCH_NAME
+        GIT_DEBIAN_BRANCH = GIT_BRANCH_NAME
+        logging.debug(
+                'setting GIT_UPSTREAM_BRANCH and GIT_DEBIAN_BRANCH to %s',
+                GIT_UPSTREAM_BRANCH
+        )
+    else:
+        logger_loud_error('Could not determine GIT_UPSTREAM_BRANCH')
+        exit_error()
+
+    repo = git.repo.Repo()
+
+    if GIT_BRANCH_NAME != 'master':
+        git_helper.git_new_branch_from(
+                GIT_BRANCH_NAME,
+                os.path.join('origin', GIT_BRANCH_NAME)
+        )
 
     # git-buildpackage uses only treeish object in v0.5.10, so let's fetch the 
     # treeish refspec when a name was given (i.e. tag names, branch names, 
     # etc.)
     # TODO: upgrade git-buildpackage
-    #GIT_UPSTREAM_BRANCH = git_helper.git_get_treeish(
-    #    os.path.join('origin', GIT_UPSTREAM_BRANCH)
-    #)
+    GIT_UPSTREAM_BRANCH = git_helper.git_get_treeish(
+        os.path.join('origin', GIT_UPSTREAM_BRANCH)
+    )
 
     # now checkout the requested branch
-    #if git_helper.git_checkout_branch(GIT_UPSTREAM_BRANCH):
-    #    logger.info('git checkout %s was successfull' % GIT_UPSTREAM_BRANCH)
-    #else:
-    #    logger_loud_error('git checkout %s was not successfull' % GIT_UPSTREAM_BRANCH)
-    #    exit_error()
+    if git_helper.git_checkout_branch(GIT_UPSTREAM_BRANCH):
+        logger.info('git checkout %s was successfull' % GIT_UPSTREAM_BRANCH)
+    else:
+        logger_loud_error('git checkout %s was not successfull' % GIT_UPSTREAM_BRANCH)
+        exit_error()
 
     # we need to make sure our jenkins config is used, so let's delete any 
     # other config available in repository that might be prefered 
-    #cleanup_files = ('.gbp.conf', 'debian/gbp.conf', '.git/gbp.conf')
-    #result = git_helper.git_cleanup_branch(cleanup_files)
-    #commit_files = result["goods"].keys()
-    #if len(commit_files) > 0:
-    #    git_helper.git_commit(
-    #        "Cleanup branch for correct builds.",
-    #        commit_files
-    #    )
+    cleanup_files = ('.gbp.conf', 'debian/gbp.conf', '.git/gbp.conf')
+    result = git_helper.git_cleanup_branch(cleanup_files)
+    commit_files = result["goods"].keys()
+    if len(commit_files) > 0:
+        git_helper.git_commit(
+            "Cleanup branch for correct builds.",
+            commit_files
+        )
 
     cmd = ['dpkg-parsechangelog']
     parse_changelog =  subprocess.Popen(
@@ -357,7 +344,6 @@ if __name__ == '__main__':
         else:
             version = '%s~develop%s' %(version, daily_date)
 
-        # FIXME: check this is still correct
         new_log = 'Generated by jenkins build of %s' % git_helper.git_get_commit_id()
 
         cmd = [
@@ -402,21 +388,10 @@ if __name__ == '__main__':
     # we need to commit here else git-buildpackage will use the existing debian/changelog...
     # TODO: Later we should investigate why the "--ignore-new" trick
     # did not work!
-    #cmd = ['/usr/bin/git', 'add', '-A']
-    #subprocess.check_call(cmd)
-    #cmd = ['/usr/bin/git', 'commit', '-a', '-m', 'add new changelog entry']
-    #subprocess.check_call(cmd)
-
-    if not GIT_COMMITTER_EMAIL:
-        #for commit in repo.commits():
-        #    if commit.id == GIT_NEW_ID:
-        #        GIT_COMMITTER_EMAIL = commit.committer.email
-        #        logger.debug(
-        #                'Found "%s" in commit-id "%s" at "%s"'
-        #                %(GIT_COMMITTER_EMAIL, commit.id, repo.active_branch)
-        #        )
-        #else:
-        raise Exception('No git_committer_email found')
+    cmd = ['/usr/bin/git', 'add', '-A']
+    subprocess.check_call(cmd)
+    cmd = ['/usr/bin/git', 'commit', '-a', '-m', 'add new changelog entry']
+    subprocess.check_call(cmd)
 
     if options.distribution in ('unstable' , 'experimental', 'pre-staging'):
       pb_suite='pre-staging'
@@ -425,17 +400,16 @@ if __name__ == '__main__':
     elif options.distribution in ('stable', 'stable-proposed-updates', 'production', 'production-proposed-updates'):
       pb_suite='production-proposed-updates'
        
-    #gbp = git_buildpackage.GitBuildPackage(
-    #        upstream_branch=GIT_UPSTREAM_BRANCH,
-    #        debian_branch=GIT_DEBIAN_BRANCH,
-    #        dist='squeeze',
-    #        arch='amd64',
-    #      pb_suite=pb_suite
-    #)
+    gbp = git_buildpackage.GitBuildPackage(
+            upstream_branch=GIT_UPSTREAM_BRANCH,
+            debian_branch=GIT_DEBIAN_BRANCH,
+            dist='squeeze',
+            arch='amd64',
+            pb_suite=pb_suite
+    )
 
     logger.info('used to start git-buildpackage here...')
-    #ret = gbp.build()
-    ret = 0
+    ret = gbp.build()
     if ret:
         logger_loud_error(
                 'git-buildpackage returned non-zero. exitcode was: %s' % ret