Skip to content

Commit

Permalink
✨ Add publish command
Browse files Browse the repository at this point in the history
  • Loading branch information
relekang committed Jul 28, 2015
1 parent 1d3ee00 commit d8116c9
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -25,6 +25,7 @@ Options:
### Commands

* `version` - Create a new release. Will change the version, commit it and tag it.
* `publish` - Runs version before pushing to git and uploading to pypi.

### Configuration
All configuration described here belongs in `setup.cfg` in a section: `semantic-release`.
Expand Down
22 changes: 18 additions & 4 deletions semantic_release/cli.py
@@ -1,7 +1,8 @@
import click

from semantic_release.git_helpers import commit_new_version, tag_new_version
from semantic_release.helpers import get_current_version, get_new_version, set_new_version
from semantic_release.git_helpers import commit_new_version, push_new_version, tag_new_version
from semantic_release.helpers import (get_current_version, get_new_version, set_new_version,
upload_to_pypi)
from semantic_release.history import evaluate_version_bump


Expand Down Expand Up @@ -35,20 +36,33 @@ def version(**kwargs):

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

if kwargs['noop'] is True:
click.echo('{} Should have bumped from {} to {}.'.format(
click.style('No operation mode.', fg='yellow'),
current_version,
new_version
))
return
return False

set_new_version(new_version)
commit_new_version(new_version)
tag_new_version(new_version)
click.echo('Bumping with a {0} version to {1}.'.format(level_bump, new_version))
return True


def publish(**kwargs):
"""
Runs the version task before pushing to git and uploading to pypi.
"""
if version(**kwargs):
push_new_version()
upload_to_pypi()
click.echo(click.style('New release published', 'green'))
else:
click.echo('Version failed, no release will be published.')


if __name__ == '__main__':
Expand Down
4 changes: 4 additions & 0 deletions semantic_release/git_helpers.py
Expand Up @@ -18,3 +18,7 @@ def commit_new_version(version):

def tag_new_version(version):
return run('git tag v{} HEAD'.format(version), hide=True)


def push_new_version():
return run('git ps && git ps --tags', hide=True)
4 changes: 4 additions & 0 deletions semantic_release/helpers.py
Expand Up @@ -10,6 +10,10 @@ def get_current_version():
return run('python setup.py --version', hide=True).stdout.strip()


def upload_to_pypi(dists='bdist_wheel'):
return run('python setup.py {} upload && rm -rf build dist'.format(dists))


def get_new_version(current_version, level_bump):
if not level_bump:
return current_version
Expand Down
20 changes: 20 additions & 0 deletions tests/test_cli.py
Expand Up @@ -83,3 +83,23 @@ def test_version_no_change(self, mock_current_version, mock_evaluate_bump,
self.assertFalse(mock_set_new_version.called)
self.assertFalse(mock_commit_new_version.called)
self.assertFalse(mock_tag_new_version.called)

@mock.patch('semantic_release.cli.upload_to_pypi')
@mock.patch('semantic_release.cli.push_new_version')
@mock.patch('semantic_release.cli.version', return_value=False)
def test_publish_should_do_nothing(self, mock_version, mock_push, mock_upload):
result = self.runner.invoke(main, ['publish'])
self.assertEqual(result.exit_code, 0)
mock_version.assert_called_once()
self.assertFalse(mock_push.called)
self.assertFalse(mock_upload.called)

@mock.patch('semantic_release.cli.upload_to_pypi')
@mock.patch('semantic_release.cli.push_new_version')
@mock.patch('semantic_release.cli.version', return_value=True)
def test_publish_should_call_functions(self, mock_version, mock_push, mock_upload):
result = self.runner.invoke(main, ['publish'])
self.assertEqual(result.exit_code, 0)
mock_version.assert_called_once()
mock_push.assert_called_once()
mock_upload.assert_called_once()

0 comments on commit d8116c9

Please sign in to comment.