def publish(**kwargs): """ Runs the version task before pushing to git and uploading to pypi. """ current_version = get_current_version() click.echo('Current version: {0}'.format(current_version)) retry = kwargs.get("retry") if retry: # The "new" version will actually be the current version, and the # "current" version will be the previous version. new_version = current_version current_version = get_previous_version(current_version) else: level_bump = evaluate_version_bump(current_version, kwargs['force_level']) new_version = get_new_version(current_version, level_bump) owner, name = get_repository_owner_and_name() ci_checks.check('master') checkout('master') if version(**kwargs): push_new_version( gh_token=os.environ.get('GH_TOKEN'), owner=owner, name=name ) if config.getboolean('semantic_release', 'upload_to_pypi'): upload_to_pypi( username=os.environ.get('PYPI_USERNAME'), password=os.environ.get('PYPI_PASSWORD'), # We are retrying, so we don't want errors for files that are already on PyPI. skip_existing=retry, repository_url=os.environ.get('PYPI_URL', None), ) if check_token(): click.echo('Updating changelog') try: log = generate_changelog(current_version, new_version) post_changelog( owner, name, new_version, markdown_changelog(new_version, log, header=False) ) except GitError: click.echo(click.style('Posting changelog failed.', 'red'), err=True) else: click.echo( click.style('Missing token: cannot post changelog', 'red'), err=True) click.echo(click.style('New release published', 'green')) else: click.echo('Version failed, no release will be published.', err=True)
def publish(**kwargs): """ Runs the version task before pushing to git and uploading to pypi. """ current_version = get_current_version() click.echo('Current version: {0}'.format(current_version)) level_bump = evaluate_version_bump(current_version, kwargs['force_level']) new_version = get_new_version(current_version, level_bump) owner, name = get_repository_owner_and_name() ci_checks.check('master') checkout('master') if version(**kwargs): push_new_version(gh_token=os.environ.get('GH_TOKEN'), owner=owner, name=name) if config.getboolean('semantic_release', 'upload_to_pypi'): upload_to_pypi( username=os.environ.get('PYPI_USERNAME'), password=os.environ.get('PYPI_PASSWORD'), ) if check_token(): click.echo('Updating changelog') try: log = generate_changelog(current_version, new_version) post_changelog( owner, name, new_version, markdown_changelog(new_version, log, header=False)) except GitError: click.echo(click.style('Posting changelog failed.', 'red'), err=True) else: click.echo(click.style('Missing token: cannot post changelog', 'red'), err=True) click.echo(click.style('New release published', 'green')) else: click.echo('Version failed, no release will be published.', err=True)
def publish(**kwargs): """ Runs the version task before pushing to git and uploading to pypi. """ current_version = get_current_version() click.echo('Current version: {0}'.format(current_version)) level_bump = evaluate_version_bump(current_version, kwargs['force_level']) new_version = get_new_version(current_version, level_bump) owner, name = get_repository_owner_and_name() ci_checks.check('master') checkout('master') if version(**kwargs): push_new_version( gh_token=os.environ.get('GH_TOKEN'), owner=owner, name=name ) if config.getboolean('semantic_release', 'upload_to_pypi'): upload_to_pypi( username=os.environ.get('PYPI_USERNAME'), password=os.environ.get('PYPI_PASSWORD'), ) if check_token(): click.echo('Updating changelog') log = generate_changelog(current_version, new_version) post_changelog( owner, name, new_version, markdown_changelog(new_version, log, header=False) ) else: click.echo( click.style('Missing token: cannot post changelog', 'red'), err=True) click.echo(click.style('New release published', 'green')) else: click.echo('Version failed, no release will be published.', err=True)
def publish(retry: bool = False, noop: bool = False, prerelease: bool = False, **kwargs): """Run the version task, then push to git and upload to an artifact repository / GitHub Releases.""" current_version = get_current_version() current_release_version = get_current_release_version() logger.info( f"Current version: {current_version}, Current release version: {current_release_version}" ) verbose = logger.isEnabledFor(logging.DEBUG) if retry: logger.info("Retry is on") # The "new" version will actually be the current version, and the # "current" version will be the previous version. level_bump = None new_version = current_version current_version = get_previous_release_version(current_version) else: # Calculate the new version level_bump = evaluate_version_bump(current_release_version, kwargs.get("force_level")) new_version = get_new_version(current_version, current_release_version, level_bump, prerelease) owner, name = get_repository_owner_and_name() branch = config.get("branch") logger.debug(f"Running publish on branch {branch}") ci_checks.check(branch) checkout(branch) if should_bump_version( current_version=current_version, new_version=new_version, current_release_version=current_release_version, prerelease=prerelease, retry=retry, noop=noop, ): log = generate_changelog(current_version) changelog_md = markdown_changelog( owner, name, new_version, log, header=False, previous_version=current_version, ) if should_run_pre_commit(): logger.info("Running pre-commit command") run_pre_commit() if not retry: update_changelog_file(new_version, changelog_md) update_additional_files() bump_version(new_version, level_bump) # A new version was released logger.info("Pushing new version") push_new_version( auth_token=get_token(), owner=owner, name=name, branch=branch, domain=get_domain(), ) # Get config options for uploads dist_path = config.get("dist_path") upload_release = config.get("upload_to_release") if should_build(): # We need to run the command to build wheels for releasing logger.info("Building distributions") if should_remove_dist(): # Remove old distributions before building remove_dists(dist_path) build_dists() if ArtifactRepo.upload_enabled(): logger.info("Uploading to artifact Repository") ArtifactRepo(Path(dist_path)).upload(noop=noop, verbose=verbose, skip_existing=retry) if check_token(): # Update changelog on HVCS logger.info("Posting changelog to HVCS") try: post_changelog(owner, name, new_version, changelog_md) except GitError: logger.error("Posting changelog failed") else: logger.warning("Missing token: cannot post changelog to HVCS") # Upload to GitHub Releases if upload_release: if check_token(): logger.info("Uploading to HVCS release") upload_to_release(owner, name, new_version, dist_path) logger.info("Upload to HVCS is complete") else: logger.warning("Missing token: cannot upload to HVCS") # Remove distribution files as they are no longer needed if should_remove_dist(): logger.info("Removing distribution files") remove_dists(dist_path) logger.info("Publish has finished")
def test_check_should_call_bitbucket_with_correct_env_variable( mocker, monkeypatch): mock_bitbucket = mocker.patch("semantic_release.ci_checks.bitbucket") monkeypatch.setenv("BITBUCKET_BUILD_NUMBER", "true") ci_checks.check("master") mock_bitbucket.assert_called_once_with("master")
def test_check_should_call_gitlab_with_correct_env_variable( mocker, monkeypatch): mock_gitlab = mocker.patch('semantic_release.ci_checks.gitlab') monkeypatch.setenv('GITLAB_CI', 'true') ci_checks.check('master') mock_gitlab.assert_called_once_with('master')
def test_check_should_call_travis_with_correct_env_variable(mocker, monkeypatch): mock_travis = mocker.patch('semantic_release.ci_checks.travis') monkeypatch.setenv('TRAVIS', 'true') ci_checks.check('master') mock_travis.assert_called_once_with('master')
def test_check_should_call_semaphore_with_correct_env_variable(mocker, monkeypatch): mock_semaphore = mocker.patch('semantic_release.ci_checks.semaphore') monkeypatch.setenv('SEMAPHORE', 'true') ci_checks.check('master') mock_semaphore.assert_called_once_with('master')
def test_check_should_call_frigg_with_correct_env_variable( mocker, monkeypatch): mock_frigg = mocker.patch("semantic_release.ci_checks.frigg") monkeypatch.setenv("FRIGG", "true") ci_checks.check("master") mock_frigg.assert_called_once_with("master")
def test_check_should_call_semaphore_with_correct_env_variable( mocker, monkeypatch): mock_semaphore = mocker.patch("semantic_release.ci_checks.semaphore") monkeypatch.setenv("SEMAPHORE", "true") ci_checks.check("master") mock_semaphore.assert_called_once_with("master")
def test_check_should_call_travis_with_correct_env_variable( mocker, monkeypatch): mock_travis = mocker.patch('semantic_release.ci_checks.travis') monkeypatch.setenv('TRAVIS', 'true') ci_checks.check('master') mock_travis.assert_called_once_with('master')
def test_check_should_call_frigg_with_correct_env_variable( mocker, monkeypatch): mock_frigg = mocker.patch('semantic_release.ci_checks.frigg') monkeypatch.setenv('FRIGG', 'true') ci_checks.check('master') mock_frigg.assert_called_once_with('master')
def test_check_should_call_semaphore_with_correct_env_variable( mocker, monkeypatch): mock_semaphore = mocker.patch('semantic_release.ci_checks.semaphore') monkeypatch.setenv('SEMAPHORE', 'true') ci_checks.check('master') mock_semaphore.assert_called_once_with('master')
def publish(**kwargs): """Run the version task, then push to git and upload to PyPI / GitHub Releases.""" current_version = get_current_version() retry = kwargs.get("retry") if retry: logger.info("Retry is on") # The "new" version will actually be the current version, and the # "current" version will be the previous version. new_version = current_version current_version = get_previous_version(current_version) else: # Calculate the new version level_bump = evaluate_version_bump(current_version, kwargs["force_level"]) new_version = get_new_version(current_version, level_bump) owner, name = get_repository_owner_and_name() branch = config.get("semantic_release", "branch") logger.debug(f"Running publish on branch {branch}") ci_checks.check(branch) checkout(branch) if version(**kwargs): # Bump to the new version if needed # A new version was released logger.info("Pushing new version") push_new_version( auth_token=get_token(), owner=owner, name=name, branch=branch, domain=get_domain(), ) # Get config options for uploads dist_path = config.get("semantic_release", "dist_path") remove_dist = config.getboolean("semantic_release", "remove_dist") upload_pypi = config.getboolean("semantic_release", "upload_to_pypi") upload_release = config.getboolean("semantic_release", "upload_to_release") if upload_pypi or upload_release: # We need to run the command to build wheels for releasing logger.info("Building distributions") if remove_dist: # Remove old distributions before building remove_dists(dist_path) build_dists() if upload_pypi: logger.info("Uploading to PyPI") upload_to_pypi( path=dist_path, username=os.environ.get("PYPI_USERNAME"), password=os.environ.get("PYPI_PASSWORD"), # If we are retrying, we don't want errors for files that are already on PyPI. skip_existing=retry, ) if check_token(): # Update changelog on HVCS logger.info("Posting changelog to HVCS") try: log = generate_changelog(current_version, new_version) post_changelog( owner, name, new_version, markdown_changelog(new_version, log, header=False), ) except GitError: logger.error("Posting changelog failed") else: logger.warning("Missing token: cannot post changelog to HVCS") # Upload to GitHub Releases if upload_release and check_token(): logger.info("Uploading to HVCS release") upload_to_release(owner, name, new_version, dist_path) # Remove distribution files as they are no longer needed if remove_dist: remove_dists(dist_path) logger.info("New release published")
def test_check_should_call_bitbucket_with_correct_env_variable( mocker, monkeypatch): mock_bitbucket = mocker.patch('semantic_release.ci_checks.bitbucket') monkeypatch.setenv('BITBUCKET_BUILD_NUMBER', 'true') ci_checks.check('master') mock_bitbucket.assert_called_once_with('master')
def publish(**kwargs): """Run the version task, then push to git and upload to PyPI / GitHub Releases.""" current_version = get_current_version() click.echo('Current version: {0}'.format(current_version)) retry = kwargs.get('retry') if retry: debug('publish: retry is on') # The "new" version will actually be the current version, and the # "current" version will be the previous version. new_version = current_version current_version = get_previous_version(current_version) else: # Calculate the new version level_bump = evaluate_version_bump(current_version, kwargs['force_level']) new_version = get_new_version(current_version, level_bump) owner, name = get_repository_owner_and_name() branch = config.get('semantic_release', 'branch') debug('branch=', branch) ci_checks.check(branch) checkout(branch) if version(**kwargs): # Bump to the new version if needed # A new version was released click.echo('Pushing new version') push_new_version( auth_token=get_token(), owner=owner, name=name, branch=branch, domain=get_domain(), ) # Get config options for uploads dist_path = config.get('semantic_release', 'dist_path') remove_dist = config.getboolean('semantic_release', 'remove_dist') upload_pypi = config.getboolean('semantic_release', 'upload_to_pypi') upload_release = config.getboolean('semantic_release', 'upload_to_release') if upload_pypi or upload_release: # We need to run the command to build wheels for releasing click.echo('Building distributions') if remove_dist: # Remove old distributions before building remove_dists(dist_path) build_dists() if upload_pypi: click.echo('Uploading to PyPI') upload_to_pypi( path=dist_path, username=os.environ.get('PYPI_USERNAME'), password=os.environ.get('PYPI_PASSWORD'), # If we are retrying, we don't want errors for files that are already on PyPI. skip_existing=retry) if check_token(): # Update changelog on HVCS click.echo('Updating changelog') try: log = generate_changelog(current_version, new_version) post_changelog( owner, name, new_version, markdown_changelog(new_version, log, header=False)) except GitError: click.echo(click.style('Posting changelog failed.', 'red'), err=True) else: click.echo(click.style('Missing token: cannot post changelog', 'red'), err=True) # Upload to GitHub Releases if upload_release and check_token(): click.echo('Uploading to HVCS release') upload_to_release(owner, name, new_version, dist_path) # Remove distribution files as they are no longer needed if remove_dist: remove_dists(dist_path) click.echo(click.style('New release published', 'green'))
def publish(**kwargs): """Run the version task, then push to git and upload to PyPI / GitHub Releases.""" current_version = get_current_version() retry = kwargs.get("retry") if retry: logger.info("Retry is on") # The "new" version will actually be the current version, and the # "current" version will be the previous version. level_bump = None new_version = current_version current_version = get_previous_version(current_version) else: # Calculate the new version level_bump = evaluate_version_bump(current_version, kwargs.get("force_level")) new_version = get_new_version(current_version, level_bump) owner, name = get_repository_owner_and_name() branch = config.get("branch") logger.debug(f"Running publish on branch {branch}") ci_checks.check(branch) checkout(branch) if should_bump_version( current_version=current_version, new_version=new_version, retry=retry, noop=kwargs.get("noop"), ): log = generate_changelog(current_version) changelog_md = markdown_changelog( owner, name, new_version, log, header=False, previous_version=current_version, ) if not retry: update_changelog_file(new_version, changelog_md) bump_version(new_version, level_bump) # A new version was released logger.info("Pushing new version") push_new_version( auth_token=get_token(), owner=owner, name=name, branch=branch, domain=get_domain(), ) # Get config options for uploads dist_path = config.get("dist_path") remove_dist = config.get("remove_dist") upload_pypi = config.get("upload_to_pypi") upload_to_pypi_glob_patterns = config.get("upload_to_pypi_glob_patterns") upload_release = config.get("upload_to_release") if upload_to_pypi_glob_patterns: upload_to_pypi_glob_patterns = upload_to_pypi_glob_patterns.split(",") if upload_pypi or upload_release: # We need to run the command to build wheels for releasing logger.info("Building distributions") if remove_dist: # Remove old distributions before building remove_dists(dist_path) build_dists() if upload_pypi: logger.info("Uploading to PyPI") upload_to_pypi( path=dist_path, # If we are retrying, we don't want errors for files that are already on PyPI. skip_existing=retry, glob_patterns=upload_to_pypi_glob_patterns, ) if check_token(): # Update changelog on HVCS logger.info("Posting changelog to HVCS") try: post_changelog(owner, name, new_version, changelog_md) except GitError: logger.error("Posting changelog failed") else: logger.warning("Missing token: cannot post changelog to HVCS") # Upload to GitHub Releases if upload_release and check_token(): logger.info("Uploading to HVCS release") upload_to_release(owner, name, new_version, dist_path) # Remove distribution files as they are no longer needed if (upload_pypi or upload_release) and remove_dist: remove_dists(dist_path) logger.info("New release published")
def test_check_should_call_circle_with_correct_env_variable( mocker, monkeypatch): mock_circle = mocker.patch("semantic_release.ci_checks.circle") monkeypatch.setenv("CIRCLECI", "true") ci_checks.check("master") mock_circle.assert_called_once_with("master")
def test_check_should_call_frigg_with_correct_env_variable(mocker, monkeypatch): mock_frigg = mocker.patch('semantic_release.ci_checks.frigg') monkeypatch.setenv('FRIGG', 'true') ci_checks.check('master') mock_frigg.assert_called_once_with('master')
def test_check_should_call_travis_with_correct_env_variable( mocker, monkeypatch): mock_travis = mocker.patch("semantic_release.ci_checks.travis") monkeypatch.setenv("TRAVIS", "true") ci_checks.check("master") mock_travis.assert_called_once_with("master")
def test_check_should_call_gitlab_with_correct_env_variable( mocker, monkeypatch): mock_gitlab = mocker.patch("semantic_release.ci_checks.gitlab") monkeypatch.setenv("GITLAB_CI", "true") ci_checks.check("master") mock_gitlab.assert_called_once_with("master")
def test_check_should_call_circle_with_correct_env_variable( mocker, monkeypatch): mock_circle = mocker.patch('semantic_release.ci_checks.circle') monkeypatch.setenv('CIRCLECI', 'true') ci_checks.check('master') mock_circle.assert_called_once_with('master')