@@ -133,28 +133,57 @@ def test(ctx, checks=True):
133133
134134 ctx .run ('pytest --doctest-modules' )
135135
136+
137+ @task
138+ def prepare_changelog (ctx ):
139+ """Prepare changelog for next release."""
140+ UNRELEASED_CHANGELOG_TEMPLATE = '\n Unreleased\n ----------\n \n **Added**\n \n **Changed**\n \n **Fixed**\n \n **Deprecated**\n \n **Removed**\n '
141+
142+ with chdir (BASE_FOLDER ):
143+ # Preparing changelog for next release
144+ with open ('CHANGELOG.rst' , 'r+' ) as changelog :
145+ content = changelog .read ()
146+ start_index = content .index ('----------' )
147+ start_index = content .rindex ('\n ' , 0 , start_index - 1 )
148+ last_version = content [start_index :start_index + 11 ].strip ()
149+
150+ if last_version == 'Unreleased' :
151+ log .write ('Already up-to-date' )
152+ return
153+
154+ changelog .seek (0 )
155+ changelog .write (content [0 :start_index ] + UNRELEASED_CHANGELOG_TEMPLATE + content [start_index :])
156+
157+ ctx .run ('git add CHANGELOG.rst && git commit -m "Prepare changelog for next release"' )
158+
159+
136160@task (help = {
137161 'release_type' : 'Type of release follows semver rules. Must be one of: major, minor, patch.' })
138162def release (ctx , release_type ):
139163 """Releases the project in one swift command!"""
140164 if release_type not in ('patch' , 'minor' , 'major' ):
141165 raise Exit ('The release type parameter is invalid.\n Must be one of: major, minor, patch' )
142166
167+ # Run checks
168+ ctx .run ('invoke check test' )
169+
170+ # Bump version and git tag it
143171 ctx .run ('bump2version %s --verbose' % release_type )
144- ctx .run ('invoke docs test' )
172+
173+ # Build project
145174 ctx .run ('python setup.py clean --all sdist bdist_wheel' )
146175
147- if confirm ('You are about to upload the release to pypi.org. Are you sure? [y/N]' ):
148- files = ['dist/*.whl' , 'dist/*.gz' , 'dist/*.zip' ]
149- dist_files = ' ' .join ([pattern for f in files for pattern in glob .glob (f )])
176+ # Prepare changelog for next release
177+ prepare_changelog (ctx )
150178
151- if len (dist_files ):
152- ctx .run ('twine upload --skip-existing %s' % dist_files )
153- else :
154- raise Exit ('No files found to release' )
155- else :
156- raise Exit ('Aborted release' )
179+ # Clean up local artifacts
180+ clean (ctx )
157181
182+ # Upload to pypi
183+ if confirm ('Everything is ready. You are about to push to git which will trigger a release to pypi.org. Are you sure? [y/N]' ):
184+ ctx .run ('git push --tags && git push' )
185+ else :
186+ raise Exit ('You need to manually revert the tag/commits created.' )
158187
159188
160189@contextlib .contextmanager
0 commit comments