Skip to content

Commit

Permalink
feat: Add --retry cli option (#78)
Browse files Browse the repository at this point in the history
* Add --retry cli option
* Post changelog correctly
* Add comments
* Add --retry to the docs
  • Loading branch information
skorokithakis authored and relekang committed Apr 11, 2018
1 parent 5411c8d commit 3e312c0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
1 change: 1 addition & 0 deletions readme.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ ignored. Running release can be run locally or from a CI service.
--patch Force patch version.
--noop No-operations mode, finds the new version number without changing it.
--post If used with the changelog command, the changelog will be posted to the release api.
--retry Retry the same release, do not bump.
--help Show this message and exit.

Commands
Expand Down
25 changes: 21 additions & 4 deletions semantic_release/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
click.option('--minor', 'force_level', flag_value='minor', help='Force minor version.'),
click.option('--patch', 'force_level', flag_value='patch', help='Force patch version.'),
click.option('--post', is_flag=True, help='Post changelog.'),
click.option('--retry', is_flag=True, help='Retry the same release, do not bump.'),
click.option('--noop', is_flag=True,
help='No-operations mode, finds the new version number without changing it.')
]
Expand All @@ -39,13 +40,17 @@ def version(**kwargs):
Detects the new version according to git log and semver. Writes the new version
number and commits it, unless the noop-option is True.
"""
click.echo('Creating new version..')
retry = kwargs.get("retry")
if retry:
click.echo('Retrying publication of the same version...')
else:
click.echo('Creating new version..')
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)

if new_version == current_version:
if new_version == current_version and not retry:
click.echo(click.style('No release will be made.', fg='yellow'))
return False

Expand All @@ -65,6 +70,10 @@ def version(**kwargs):
return False
click.echo(click.style('The build was a success, continuing the release', 'green'))

if retry:
# No need to make changes to the repo, we're just retrying.
return True

if config.get('semantic_release', 'version_source') == 'commit':
set_new_version(new_version)
commit_new_version(new_version)
Expand Down Expand Up @@ -111,8 +120,15 @@ def publish(**kwargs):
"""
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)
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')
Expand All @@ -129,6 +145,7 @@ def publish(**kwargs):
upload_to_pypi(
username=os.environ.get('PYPI_USERNAME'),
password=os.environ.get('PYPI_PASSWORD'),
skip_existing=retry, # We're retrying, so we don't want errors for files that are already on PyPI.
)

if check_token():
Expand Down
4 changes: 2 additions & 2 deletions semantic_release/pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from twine.commands import upload as twine_upload


def upload_to_pypi(dists='sdist bdist_wheel', username=None, password=None):
def upload_to_pypi(dists='sdist bdist_wheel', username=None, password=None, skip_existing=False):
"""
Creates the wheel and uploads to pypi with twine.
Expand All @@ -19,7 +19,7 @@ def upload_to_pypi(dists='sdist bdist_wheel', username=None, password=None):
comment=None,
sign_with='gpg',
config_file='~/.pypirc',
skip_existing=False,
skip_existing=skip_existing,
cert=None,
client_cert=None,
repository_url=None
Expand Down

0 comments on commit 3e312c0

Please sign in to comment.