Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update changelog more consistently #3405

Merged
merged 1 commit into from
Dec 15, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
import os
import textwrap

from dateutil.parser import parse
from future.moves.configparser import RawConfigParser
from invoke import task
from invoke import task, Exit


@task
Expand All @@ -24,6 +25,13 @@ def prepare(ctx, version):
updated. New entries will end up at the top of the file, under a heading
for the new version.
"""
# Ensure we're on the master branch first
git_rev_parse = ctx.run('git rev-parse --abbrev-ref HEAD', hide=True)
current_branch = git_rev_parse.stdout.strip()
if current_branch != 'rel':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why rel here? shouldn't be master?

I mean, it checks if we are in rel and if not, it says "hey, you need to be on master"

Other, we want to ensure we are on rel not on master, right?

print('You must be on master branch!')
raise Exit(1)

print('Updating release version in setup.cfg')
setupcfg_path = os.path.join(os.path.dirname(__file__), 'setup.cfg')
config = RawConfigParser()
Expand All @@ -33,6 +41,11 @@ def prepare(ctx, version):
config.write(configfile)

print('Installing github-changelog')
# Get last modified date from Git instead of assuming the file metadata is
# correct. This can change depending on git reset, etc.
git_log = ctx.run('git log -1 --format="%ad" -- CHANGELOG.rst')
last_modified = parse(git_log.stdout.strip()).strftime('%Y-%m-%d')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should put a note in the changelog that it's auto-generated, and not to touch it manually.

Copy link
Contributor Author

@agjohnson agjohnson Dec 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, one of the benefits of this tool is that it only updates the changelog for last release. It does allow for authoring in between generating and commiting, so we can add deployment and migration notes, or more general description of some of the changes

# Install and run
ctx.run('npm install git+https://github.com/agjohnson/github-changelog.git')
changelog_path = os.path.join(os.path.dirname(__file__), 'CHANGELOG.rst')
template_path = os.path.join(
Expand All @@ -44,12 +57,14 @@ def prepare(ctx, version):
'gh-changelog '
'-o rtfd -r readthedocs.org '
'--file {changelog_path} '
'--since {last_modified} '
'--template {template_path} '
'--header "Version {version}"'
).format(
version=version,
template_path=template_path,
changelog_path=changelog_path,
last_modified=last_modified,
) # yapf: disable
try:
token = os.environ['GITHUB_TOKEN']
Expand All @@ -76,6 +91,5 @@ def release(ctx, version):
Do this after prepare task and manual cleanup/commit
"""
ctx.run(
('git checkout master && '
'git tag {version} && '
('git tag {version} && '
'git push --tags').format(version=version))