6
6
import os
7
7
import textwrap
8
8
9
+ from dateutil .parser import parse
9
10
from future .moves .configparser import RawConfigParser
10
- from invoke import task
11
+ from invoke import task , Exit
11
12
12
13
13
14
@task
@@ -24,6 +25,13 @@ def prepare(ctx, version):
24
25
updated. New entries will end up at the top of the file, under a heading
25
26
for the new version.
26
27
"""
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
+
27
35
print ('Updating release version in setup.cfg' )
28
36
setupcfg_path = os .path .join (os .path .dirname (__file__ ), 'setup.cfg' )
29
37
config = RawConfigParser ()
@@ -33,6 +41,11 @@ def prepare(ctx, version):
33
41
config .write (configfile )
34
42
35
43
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
36
49
ctx .run ('npm install git+https://github.com/agjohnson/github-changelog.git' )
37
50
changelog_path = os .path .join (os .path .dirname (__file__ ), 'CHANGELOG.rst' )
38
51
template_path = os .path .join (
@@ -49,13 +62,15 @@ def prepare(ctx, version):
49
62
'{bin_path}/gh-changelog '
50
63
'-o rtfd -r readthedocs.org '
51
64
'--file {changelog_path} '
65
+ '--since {last_modified} '
52
66
'--template {template_path} '
53
67
'--header "Version {version}"'
54
68
).format (
55
69
bin_path = bin_path ,
56
70
version = version ,
57
71
template_path = template_path ,
58
72
changelog_path = changelog_path ,
73
+ last_modified = last_modified ,
59
74
) # yapf: disable
60
75
try :
61
76
token = os .environ ['GITHUB_TOKEN' ]
@@ -82,6 +97,5 @@ def release(ctx, version):
82
97
Do this after prepare task and manual cleanup/commit
83
98
"""
84
99
ctx .run (
85
- ('git checkout master && '
86
- 'git tag {version} && '
100
+ ('git tag {version} && '
87
101
'git push --tags' ).format (version = version ))
0 commit comments