From: Holger Levsen Date: Wed, 28 Sep 2011 14:37:13 +0000 (+0200) Subject: get rid of pb_version X-Git-Url: https://git.uhu-banane.org/?a=commitdiff_plain;h=6217a6c7253cbf1d0aa383023b5559f5e10869e0;p=profitbricks%2Fjenkins-build-scripts.git get rid of pb_version --- diff --git a/debian_build.py b/debian_build.py index 59a5c2e..f872856 100755 --- a/debian_build.py +++ b/debian_build.py @@ -313,55 +313,83 @@ if __name__ == '__main__': commit_files ) - pb_version_path = os.path.join('debian', 'pb_version') - if not os.path.exists(pb_version_path): - pb_version = '0.0' + if git_helper.git_checkout_branch(GIT_UPSTREAM_BRANCH): + logger.info('git checkout %s was successfull' % GIT_UPSTREAM_BRANCH) else: - fh = open(pb_version_path) - pb_version = fh.readline().rstrip() - fh.close() + logger_loud_error('git checkout %s was not successfull' % GIT_UPSTREAM_BRANCH) + exit_error() - fh = open('debian/control') - for line in fh: - if line.startswith('Source:'): - pkg_name = line.split(':')[-1].lstrip().rstrip() - break - fh.close() + cmd = ['dpkg-parsechangelog'] + parse_changelog = subprocess.Popen( + cmd, + shell=False, + close_fds=True, + stdout=subprocess.PIPE, + stderr=sys.stderr, + cwd='./' + ) + ret = parse_changelog.wait() + if ret: + logger_loud_error('%s was not successfull, return code was %s ' % (' '.join(cmd), ret)) + raise Exception( + '%s was not successfull, return code was %s ' % (' '.join(cmd), ret) + ) + exit_error() - if options.distribution in ('pre-staging', 'unstable', 'experimental'): + changelog = parse_changelog.stdout - daily_date = datetime.datetime.now().strftime('%Y%m%d%H%M%S') - version = '%s~%s-1' %(pb_version, daily_date) - os.unlink('debian/changelog') - cmd = ['/usr/bin/git', 'log', '--since=yesterday', '--abbrev-commit', '--format=format:"%cD -- %aN%n[%h] %s%n"'] - git_log = subprocess.Popen( - cmd, - shell=False, - close_fds=True, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - cwd='./', - universal_newlines=True + cmd = ['grep-dctrl', '-n', '-s', 'Source,Version,Distribution', ''] + grep_dctrl = subprocess.Popen( + cmd, + shell=False, + close_fds=True, + stdin=changelog, + stdout=subprocess.PIPE, + stderr=sys.stderr, + cwd=os.getcwd() + ) + ret = grep_dctrl.wait() + if ret: + logger_loud_error('%s was not successfull, return code was %s ' % (' '.join(cmd), ret)) + raise Exception( + '%s was not successfull, return code was %s ' % (' '.join(cmd), ret) ) + exit_error() - ret = git_log.wait() + pkg_name = grep_dctrl.stdout.readline() + pkg_name = version.strip() + logger.info('Source package name is %s' % (version)) - if ret: - raise Exception('git log was not successfull') + version = grep_dctrl.stdout.readline() + version = version.strip() + logger.info('Package version is %s' % (version)) + + distribution = grep_dctrl.stdout.readline() + distribution = distribution.strip() + logger.info('Package distribution is %s' % (distribution)) + + if (options.distribution in ('testing', 'staging') and not distribution in ('testing', 'staging')) \ + or (options.distribution in ('stable', 'stable-proposed-updates', 'production', 'production-proposed-updates') and not distribution in ('stable', 'stable-proposed-updates', 'production', 'production-proposed-updates')) \ + or (options.distribution in ('unstable', 'pre-staging') and not distribution in ('unstable', 'pre-staging', 'UNRELEASED')): + logger_loud_error('Distribution %s in debian/changelog did not match branch %s' % (distribution, options.distribution)) + raise Exception( + 'Distribution %s in debian/changelog did not match branch %s' % (distribution, options.distribution) + ) + exit_error() + + if (options.distribution in ('testing', 'staging') or (options.distribution in ('unstable', 'pre-staging'): + daily_date = datetime.datetime.now().strftime('%Y%m%d%H%M%S') + + if (options.distribution in ('testing', 'staging'): + version = '%s~rc%s-1' %(version, daily_date) else: - logger.info('git log was successfull') + version = '%s~develop%s-1' %(version, daily_date) - new_log = git_log.stdout.read() - if new_log == '': - logger.info('git log since yesterday is empty, aborting build.') - sys.exit(0) + new_log = 'Generated by jenkins build.' cmd = [ '/usr/bin/dch', - '--create', - '--package', - pkg_name, '--newversion', '%s' %(version), '--distribution', @@ -388,74 +416,14 @@ if __name__ == '__main__': raise Exception( '"%s" returned with exitcode: %s' %(' '.join(cmd), ret) ) - logger.info('debian/changelog written') # 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 changelog'] + cmd = ['/usr/bin/git', 'commit', '-a', '-m', 'add new changelog entry'] subprocess.check_call(cmd) - else: - # so we're in the master or release branches - # let's check it out :-D - 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() - - cmd = ['dpkg-parsechangelog'] - parse_changelog = subprocess.Popen( - cmd, - shell=False, - close_fds=True, - stdout=subprocess.PIPE, - stderr=sys.stderr, - cwd='./' - ) - ret = parse_changelog.wait() - if ret: - logger_loud_error('%s was not successfull, return code was %s ' % (' '.join(cmd), ret)) - raise Exception( - '%s was not successfull, return code was %s ' % (' '.join(cmd), ret) - ) - exit_error() - - changelog = parse_changelog.stdout - - cmd = ['grep-dctrl', '-n', '-s', 'Version,Distribution', ''] - grep_dctrl = subprocess.Popen( - cmd, - shell=False, - close_fds=True, - stdin=changelog, - stdout=subprocess.PIPE, - stderr=sys.stderr, - cwd=os.getcwd() - ) - ret = grep_dctrl.wait() - if ret: - logger_loud_error('%s was not successfull, return code was %s ' % (' '.join(cmd), ret)) - raise Exception( - '%s was not successfull, return code was %s ' % (' '.join(cmd), ret) - ) - exit_error() - - version = grep_dctrl.stdout.readline() - version = version.strip() - logger.info('Packet version is %s' % (version)) - - distribution = grep_dctrl.stdout.readline() - distribution = distribution.strip() - logger.info('Packet distribution is %s' % (distribution)) - if (options.distribution in ('testing', 'staging') and not distribution in ('testing', 'staging')) or (options.distribution in ('stable', 'stable-proposed-updates', 'production', 'production-proposed-updates') and not distribution in ('stable', 'stable-proposed-updates', 'production', 'production-proposed-updates')): - logger_loud_error('Distribution %s in debian/changelog did not match branch %s' % (distribution, options.distribution)) - raise Exception( - 'Distribution %s in debian/changelog did not match branch %s' % (distribution, options.distribution) - ) - exit_error() if not GIT_COMMITTER_EMAIL: for commit in repo.commits():