Skip to content

Commit f1087d3

Browse files
authored
Update changelog more consistently (readthedocs#3405)
* Get the last modified date from git, not local file as normally expected * Make sure we're on master to run * Don't do reset to master on release
1 parent f186791 commit f1087d3

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

tasks.py

+17-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
import os
77
import textwrap
88

9+
from dateutil.parser import parse
910
from future.moves.configparser import RawConfigParser
10-
from invoke import task
11+
from invoke import task, Exit
1112

1213

1314
@task
@@ -24,6 +25,13 @@ def prepare(ctx, version):
2425
updated. New entries will end up at the top of the file, under a heading
2526
for the new version.
2627
"""
28+
# Ensure we're on the master branch first
29+
git_rev_parse = ctx.run('git rev-parse --abbrev-ref HEAD', hide=True)
30+
current_branch = git_rev_parse.stdout.strip()
31+
if current_branch != 'rel':
32+
print('You must be on master branch!')
33+
raise Exit(1)
34+
2735
print('Updating release version in setup.cfg')
2836
setupcfg_path = os.path.join(os.path.dirname(__file__), 'setup.cfg')
2937
config = RawConfigParser()
@@ -33,6 +41,11 @@ def prepare(ctx, version):
3341
config.write(configfile)
3442

3543
print('Installing github-changelog')
44+
# Get last modified date from Git instead of assuming the file metadata is
45+
# correct. This can change depending on git reset, etc.
46+
git_log = ctx.run('git log -1 --format="%ad" -- CHANGELOG.rst')
47+
last_modified = parse(git_log.stdout.strip()).strftime('%Y-%m-%d')
48+
# Install and run
3649
ctx.run('npm install git+https://github.com/agjohnson/github-changelog.git')
3750
changelog_path = os.path.join(os.path.dirname(__file__), 'CHANGELOG.rst')
3851
template_path = os.path.join(
@@ -49,13 +62,15 @@ def prepare(ctx, version):
4962
'{bin_path}/gh-changelog '
5063
'-o rtfd -r readthedocs.org '
5164
'--file {changelog_path} '
65+
'--since {last_modified} '
5266
'--template {template_path} '
5367
'--header "Version {version}"'
5468
).format(
5569
bin_path=bin_path,
5670
version=version,
5771
template_path=template_path,
5872
changelog_path=changelog_path,
73+
last_modified=last_modified,
5974
) # yapf: disable
6075
try:
6176
token = os.environ['GITHUB_TOKEN']
@@ -82,6 +97,5 @@ def release(ctx, version):
8297
Do this after prepare task and manual cleanup/commit
8398
"""
8499
ctx.run(
85-
('git checkout master && '
86-
'git tag {version} && '
100+
('git tag {version} && '
87101
'git push --tags').format(version=version))

0 commit comments

Comments
 (0)