@@ -45,9 +45,16 @@ def get_build_dir(ctx):
45
45
return _get_git_root (ctx ) / "build"
46
46
47
47
48
- def _render_log ():
48
+ def _render_log (ctx = None , version = None ):
49
49
"""Totally tap into Towncrier internals to get an in-memory result."""
50
- rendered = subprocess .check_output (["towncrier" , "--draft" ]).decode ("utf-8" )
50
+ if ctx and not version :
51
+ version = find_version (ctx )
52
+
53
+ cmd = ["towncrier" , "--draft" ]
54
+ if version :
55
+ cmd .extend (["--version" , version ])
56
+
57
+ rendered = subprocess .check_output (cmd ).decode ("utf-8" )
51
58
return rendered
52
59
53
60
@@ -69,20 +76,23 @@ def release(
69
76
dry_run = dry_run ,
70
77
pre = pre ,
71
78
)
72
- tag_content = _render_log ()
79
+ tag_content = _render_log (ctx , version )
73
80
if dry_run :
74
- ctx .run ("towncrier --draft > CHANGELOG.draft.md" )
81
+ # Use the correct version when generating the draft
82
+ ctx .run (f"towncrier --draft --version={ version } > CHANGELOG.draft.md" )
75
83
log ("would remove: news/*" )
76
84
log ("would remove: CHANGELOG.draft.md" )
77
85
log ("would update: pipenv/pipenv.1" )
78
86
log (f'Would commit with message: "Release v{ version } "' )
79
87
else :
80
88
if pre :
81
89
log ("generating towncrier draft..." )
82
- ctx .run ("towncrier --draft > CHANGELOG.draft.md" )
90
+ # Use the correct version when generating the draft
91
+ ctx .run (f"towncrier --draft --version={ version } > CHANGELOG.draft.md" )
83
92
ctx .run (f"git add { get_version_file (ctx ).as_posix ()} " )
84
93
else :
85
- ctx .run ("towncrier" )
94
+ # Use the correct version when generating the changelog
95
+ ctx .run (f"towncrier --version={ version } " )
86
96
ctx .run (f"git add CHANGELOG.md news/ { get_version_file (ctx ).as_posix ()} " )
87
97
log ("removing changelog draft if present" )
88
98
draft_changelog = pathlib .Path ("CHANGELOG.draft.md" )
@@ -185,12 +195,14 @@ def generate_contributing_md(ctx, commit=False):
185
195
@invoke .task
186
196
def generate_changelog (ctx , commit = False , draft = False ):
187
197
log ("Generating changelog..." )
198
+ # Get the current version to ensure it's used in the changelog
199
+ version = find_version (ctx )
188
200
if draft :
189
201
commit = False
190
202
log ("Writing draft to file..." )
191
- ctx .run ("towncrier --draft > CHANGELOG.draft.md" )
203
+ ctx .run (f "towncrier --draft --version= { version } > CHANGELOG.draft.md" )
192
204
else :
193
- ctx .run ("towncrier" )
205
+ ctx .run (f "towncrier --version= { version } " )
194
206
if commit :
195
207
log ("Committing..." )
196
208
ctx .run ("git add CHANGELOG.md" )
0 commit comments