def finish_release(version_number, repo, conf, meta_repo): """Do the post tag release processes.""" working_dir = conf.get('working_dir') lock_dir = os.path.join(working_dir, 'lock') repo_config = repo.repo_config version_number_pieces = version_number.split('.') branch_number = '.'.join(version_number_pieces[:2]) with fasteners.InterProcessLock(os.path.join(lock_dir, repo.name)): # Pull latest master git.checkout_master(repo, pull=True) if repo_config.get('branch_on_release'): branch_name = 'stable/%s' % branch_number repo_branches = [x.name for x in repo.gh_repo.get_branches()] if int(version_number_pieces[2]) == 0 and \ branch_name not in repo_branches: git.checkout_master(repo, pull=True) git.create_branch(branch_name, version_number, repo, push=True) log_string = _get_log_string(version_number_pieces) categories = repo.get_local_config().get( 'categories', config.default_changelog_categories) create_github_release(repo, log_string, version_number, categories) git.checkout_master(repo, pull=True) def _meta_process(): with fasteners.InterProcessLock(os.path.join(lock_dir, meta_repo.name)): bump_meta(meta_repo, repo, version_number) git.checkout_master(meta_repo, pull=True) multiprocessing.Process(target=_meta_process).start()
def bump_meta(meta_repo, repo, version_number): repo_config = repo.repo_config git.checkout_master(meta_repo, pull=True) version_number_pieces = version_number.split('.') meta_version = git.get_latest_tag(meta_repo).decode('utf8') meta_version_pieces = meta_version.split('.') if int(version_number_pieces[2] ) == 0 and not repo_config.get('optional_package'): new_meta_version = '%s.%s.%s' % (meta_version_pieces[0], int(meta_version_pieces[1]) + 1, 0) else: new_meta_version = '%s.%s.%s' % (meta_version_pieces[0], meta_version_pieces[1], int(meta_version_pieces[2]) + 1) package_name = repo.repo_name.split('/')[1] pulls = meta_repo.gh_repo.get_pulls(state='open') setup_py_path = os.path.join(meta_repo.local_path, 'setup.py') docs_conf_path = os.path.join(os.path.join(meta_repo.local_path, 'docs'), 'conf.py') title = 'Bump Meta' requirements_str = package_name + '==' + version_number LOG.info("Processing meta repo bump for %s" % requirements_str) bump_pr = None for pull in pulls: if pull.title == title: bump_pr = pull git.checkout_ref(meta_repo, 'bump_meta') git.pull_remote_ref_to_local(meta_repo, 'bump_meta') break else: git.create_branch('bump_meta', 'origin/master', meta_repo) git.checkout_ref(meta_repo, 'bump_meta') # Update setup.py buf = io.StringIO() with open(setup_py_path, 'r') as fd: for line in fd: if package_name in line: old_version = re.search(package_name + '==(.*)', line)[1] out_line = line.replace(package_name + '==' + old_version, requirements_str) if not out_line.endswith('",\n') and out_line.endswith('\n'): buf.write(out_line.replace('\n', '",\n')) elif 'version=' in line: old_version = re.search('version=(.*)', line)[1] old_version = old_version.strip('",') old_version_pieces = old_version.split('.') new_version_pieces = new_meta_version.split('.') if old_version != new_meta_version and \ old_version_pieces[1] <= new_version_pieces[1]: LOG.debug('Bumping meta version %s to %s' % (old_version, new_meta_version)) out_line = line.replace('version="%s"' % old_version, 'version="%s"' % new_meta_version) buf.write(out_line) else: LOG.debug('Not bumping meta version %s it is the same or ' 'less than %s' % (old_version, new_meta_version)) buf.write(line) else: buf.write(line) buf.seek(0) with open(setup_py_path, 'w') as fd: shutil.copyfileobj(buf, fd) # Update docs/conf.py buf = io.StringIO() with open(docs_conf_path, 'r') as fd: for line in fd: if line.startswith('release = '): old_version = re.search("release = '(.*)'", line)[1] old_version = old_version.strip('",') old_version_pieces = old_version.split('.') new_version_pieces = new_meta_version.split('.') if old_version != new_meta_version and \ old_version_pieces[1] <= new_version_pieces[1]: out_line = line.replace(old_version, new_meta_version) buf.write(out_line) else: buf.write(line) else: buf.write(line) buf.seek(0) with open(docs_conf_path, 'w') as fd: shutil.copyfileobj(buf, fd) _regenerate_authors(meta_repo) body = """Bump the meta repo version to include: %s """ % requirements_str commit_msg = 'Bump version for %s\n\n%s' % (requirements_str, body) git.create_git_commit_for_all(meta_repo, commit_msg.encode('utf8')) git.push_ref_to_github(meta_repo, 'bump_meta') if not bump_pr: meta_repo.gh_repo.create_pull(title, base='master', head='bump_meta', body=body) else: old_body = bump_pr.body new_body = old_body + '\n' + requirements_str bump_pr.edit(body=new_body)
def test_create_branch_git_exception(self, subprocess_mock): repo = unittest.mock.MagicMock() res = git.create_branch('stable/0.9', 'sha1', repo) self.assertEqual(False, res)