Skip to content

Commit 667dca8

Browse files
committed
Added tag and validatetag invoke tasks to tasks.py
Also: - Updated Changelog
1 parent 24ab3dd commit 667dca8

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

CHANGELOG.md

+11-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7-
## Unreleased
8-
### Added
9-
- Initial extract from cmd2 codebase
107

8+
## [0.3.0] - 2018-10-21
9+
### Fixed
10+
- Fixed bug due to how help works in cmd2
11+
12+
### Changed
13+
- cmd2-submenu now requires cmd2 version 0.9.6+
14+
15+
16+
## [0.2.0] - 2018-10-15
17+
### Initial release to PyPI
18+
- Version 0.1.0 had been "released" on GitHub but we had forgotten to publish it to PyPI

tasks.py

+31-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
"""Development related tasks to be run with 'invoke'"""
44

55
import os
6+
import re
67
import shutil
8+
import sys
79

810
import invoke
911

@@ -135,6 +137,33 @@ def clean_all(context):
135137
pass
136138
namespace_clean.add_task(clean_all, 'all')
137139

140+
141+
@invoke.task
142+
def tag(context, name, message=''):
143+
"Add a Git tag and push it to origin"
144+
# If a tag was provided on the command-line, then add a Git tag and push it to origin
145+
if name:
146+
context.run('git tag -a {} -m {!r}'.format(name, message))
147+
context.run('git push origin {}'.format(name))
148+
namespace.add_task(tag)
149+
150+
@invoke.task()
151+
def validatetag(context):
152+
"Check to make sure that a tag exists for the current HEAD and it looks like a valid version number"
153+
# Validate that a Git tag exists for the current commit HEAD
154+
result = context.run("git describe --exact-match --tags $(git log -n1 --pretty='%h')")
155+
tag = result.stdout.rstrip()
156+
157+
# Validate that the Git tag appears to be a valid version number
158+
ver_regex = re.compile('(\d+)\.(\d+)\.(\d+)')
159+
match = ver_regex.fullmatch(tag)
160+
if match is None:
161+
print('Tag {!r} does not appear to be a valid version number'.format(tag))
162+
sys.exit(-1)
163+
else:
164+
print('Tag {!r} appears to be a valid version number'.format(tag))
165+
namespace.add_task(validatetag)
166+
138167
@invoke.task(pre=[clean_all])
139168
def sdist(context):
140169
"Create a source distribution"
@@ -147,13 +176,13 @@ def wheel(context):
147176
context.run('python setup.py bdist_wheel')
148177
namespace.add_task(wheel)
149178

150-
@invoke.task(pre=[sdist, wheel])
179+
@invoke.task(pre=[validatetag, sdist, wheel])
151180
def pypi(context):
152181
"Build and upload a distribution to pypi"
153182
context.run('twine upload dist/*')
154183
namespace.add_task(pypi)
155184

156-
@invoke.task(pre=[sdist, wheel])
185+
@invoke.task(pre=[validatetag, sdist, wheel])
157186
def pypi_test(context):
158187
"Build and upload a distribution to https://test.pypi.org"
159188
context.run('twine upload --repository-url https://test.pypi.org/legacy/ dist/*')

0 commit comments

Comments
 (0)