Skip to content

Commit 690b711

Browse files
author
Steven Silvester
authored
Merge pull request #147 from jtpio/since-last-stable
Add Since Last Stable Option for Changelog
2 parents aefad8b + 90977b9 commit 690b711

File tree

9 files changed

+153
-26
lines changed

9 files changed

+153
-26
lines changed

.github/actions/draft-changelog/action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ inputs:
2424
since:
2525
description: Use PRs with activity since this date or git reference
2626
required: false
27+
since_last_stable:
28+
description: Use PRs with activity since the last stable git tag
29+
required: false
2730
outputs:
2831
pr_url:
2932
description: "The URL of the Changelog Pull Request"
@@ -47,6 +50,7 @@ runs:
4750
export RH_DRY_RUN=${{ inputs.dry_run }}
4851
export RH_REF=${GITHUB_REF}
4952
export RH_SINCE=${{ inputs.since }}
53+
export RH_SINCE_LAST_STABLE=${{ inputs.since_last_stable }}
5054
5155
# Install Jupyter Releaser from git
5256
pip install -q git+https://github.com/jupyter-server/jupyter_releaser.git@v1

.github/actions/draft-release/action.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,16 @@ inputs:
1616
post_version_spec:
1717
description: "Post Version Specifier"
1818
required: false
19-
changelog:
20-
description: "Changelog file"
21-
default: "CHANGELOG.md"
22-
required: false
2319
dry_run:
2420
description: "If set, do not push permanent changes"
2521
default: "false"
2622
required: false
2723
since:
2824
description: Use PRs with activity since this date or git reference
2925
required: false
26+
since_last_stable:
27+
description: Use PRs with activity since the last stable git tag
28+
required: false
3029
outputs:
3130
release_url:
3231
description: "The html URL of the draft GitHub release"
@@ -47,10 +46,10 @@ runs:
4746
fi
4847
export RH_REF=${GITHUB_REF}
4948
export RH_VERSION_SPEC=${{ inputs.version_spec }}
50-
export RH_CHANGELOG=${{ inputs.changelog }}
5149
export RH_POST_VERSION_SPEC=${{ inputs.post_version_spec }}
5250
export RH_DRY_RUN=${{ inputs.dry_run }}
5351
export RH_SINCE=${{ inputs.since }}
52+
export RH_SINCE_LAST_STABLE=$${{ inputs.since_last_stable }}
5453
5554
# Install Jupyter Releaser from git
5655
pip install -q git+https://github.com/jupyter-server/jupyter_releaser.git@v1

.github/workflows/draft-changelog.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ on:
1414
since:
1515
description: Use PRs with activity since this date or git reference
1616
required: false
17+
since_last_stable:
18+
description: Use PRs with activity since the last stable git tag
19+
required: false
1720
jobs:
1821
changelog:
1922
runs-on: ubuntu-latest
@@ -45,6 +48,7 @@ jobs:
4548
target: ${{ github.event.inputs.target }}
4649
branch: ${{ github.event.inputs.branch }}
4750
since: ${{ github.event.inputs.since }}
51+
since_last_stable: ${{ github.event.intputs.since_last_stable }}
4852
- name: "** Next Step **"
4953
run: |
5054
echo "Review PR: ${{ steps.draft-changelog.outputs.pr_url }}"

.github/workflows/draft-release.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ on:
1717
since:
1818
description: Use PRs with activity since this date or git reference
1919
required: false
20+
since_last_stable:
21+
description: Use PRs with activity since the last stable git tag
22+
required: false
2023
jobs:
2124
release:
2225
runs-on: ubuntu-latest
@@ -52,6 +55,7 @@ jobs:
5255
version_spec: ${{ github.event.inputs.version_spec }}
5356
post_version_spec: ${{ github.event.inputs.post_version_spec }}
5457
since: ${{ github.event.inputs.since }}
58+
since_last_stable: ${{ github.event.intputs.since_last_stable }}
5559
- name: "** Next Step **"
5660
run: |
5761
echo "Run the "Publish Release" Workflow with Release Url:"

jupyter_releaser/changelog.py

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def get_version_entry(
4747
version,
4848
*,
4949
since=None,
50+
since_last_stable=None,
5051
until=None,
5152
auth=None,
5253
resolve_backports=False,
@@ -65,6 +66,8 @@ def get_version_entry(
6566
The new version
6667
since: str
6768
Use PRs with activity since this date or git reference
69+
since_last_stable:
70+
Use PRs with activity since the last stable git tag
6871
until: str, optional
6972
Use PRs until this date or git reference
7073
auth : str, optional
@@ -77,14 +80,7 @@ def get_version_entry(
7780
str
7881
A formatted changelog entry with markers
7982
"""
80-
81-
if not since:
82-
source = ref or branch
83-
tags = util.run(
84-
f"git --no-pager tag --sort=-creatordate --merged {source}", quiet=True
85-
)
86-
if tags:
87-
since = tags.splitlines()[0]
83+
since = since or _get_since(ref or branch, since_last_stable)
8884

8985
util.log(f"Getting changes to {repo} since {since} on branch {branch}...")
9086

@@ -142,7 +138,9 @@ def get_version_entry(
142138
return output
143139

144140

145-
def build_entry(ref, branch, repo, auth, changelog_path, since, resolve_backports):
141+
def build_entry(
142+
ref, branch, repo, auth, changelog_path, since, since_last_stable, resolve_backports
143+
):
146144
"""Build a python version entry"""
147145
branch = branch or util.get_branch()
148146
repo = repo or util.get_repo()
@@ -166,6 +164,7 @@ def build_entry(ref, branch, repo, auth, changelog_path, since, resolve_backport
166164
repo,
167165
version,
168166
since=since,
167+
since_last_stable=since_last_stable,
169168
auth=auth,
170169
resolve_backports=resolve_backports,
171170
)
@@ -211,7 +210,15 @@ def format(changelog):
211210

212211

213212
def check_entry(
214-
ref, branch, repo, auth, changelog_path, since, resolve_backports, output
213+
ref,
214+
branch,
215+
repo,
216+
auth,
217+
changelog_path,
218+
since,
219+
since_last_stable,
220+
resolve_backports,
221+
output,
215222
):
216223
"""Check changelog entry"""
217224
branch = branch or util.get_branch()
@@ -241,6 +248,7 @@ def check_entry(
241248
repo,
242249
version,
243250
since=since,
251+
since_last_stable=since_last_stable,
244252
auth=auth,
245253
resolve_backports=resolve_backports,
246254
)
@@ -282,3 +290,23 @@ def extract_current(changelog_path):
282290
if start != -1 and end != -1:
283291
body = changelog[start + len(START_MARKER) : end]
284292
return body
293+
294+
295+
def _get_since(source, since_last_stable=False):
296+
"""Get the appropriate since reference or None"""
297+
tags = util.run(
298+
f"git --no-pager tag --sort=-creatordate --merged {source}", quiet=True
299+
)
300+
if not tags:
301+
return
302+
303+
tags = tags.splitlines()
304+
305+
if since_last_stable:
306+
stable_tag = re.compile(r"\d\.\d\.\d$")
307+
tags = [t for t in tags if re.search(stable_tag, t)]
308+
if not tags:
309+
return
310+
return tags[0]
311+
312+
return tags[0]

jupyter_releaser/cli.py

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,13 @@ def main(force):
198198
envvar="RH_SINCE",
199199
default=None,
200200
help="Use PRs with activity since this date or git reference",
201-
)
201+
),
202+
click.option(
203+
"--since-last-stable",
204+
is_flag=True,
205+
envvar="RH_SINCE_LAST_STABLE",
206+
help="Use PRs with activity since the last stable git tag",
207+
),
202208
]
203209

204210
changelog_options = (
@@ -276,10 +282,19 @@ def bump_version(version_spec, version_cmd):
276282
@main.command()
277283
@add_options(changelog_options)
278284
@use_checkout_dir()
279-
def build_changelog(ref, branch, repo, auth, changelog_path, since, resolve_backports):
285+
def build_changelog(
286+
ref, branch, repo, auth, changelog_path, since, since_last_stable, resolve_backports
287+
):
280288
"""Build changelog entry"""
281289
changelog.build_entry(
282-
ref, branch, repo, auth, changelog_path, since, resolve_backports
290+
ref,
291+
branch,
292+
repo,
293+
auth,
294+
changelog_path,
295+
since,
296+
since_last_stable,
297+
resolve_backports,
283298
)
284299

285300

@@ -292,11 +307,26 @@ def build_changelog(ref, branch, repo, auth, changelog_path, since, resolve_back
292307
@add_options(dry_run_options)
293308
@use_checkout_dir()
294309
def draft_changelog(
295-
version_spec, ref, branch, repo, since, auth, changelog_path, dry_run
310+
version_spec,
311+
ref,
312+
branch,
313+
repo,
314+
since,
315+
since_last_stable,
316+
auth,
317+
changelog_path,
318+
dry_run,
296319
):
297320
"""Create a changelog entry PR"""
298321
lib.draft_changelog(
299-
version_spec, branch, repo, since, auth, changelog_path, dry_run
322+
version_spec,
323+
branch,
324+
repo,
325+
since,
326+
since_last_stable,
327+
auth,
328+
changelog_path,
329+
dry_run,
300330
)
301331

302332

@@ -307,11 +337,27 @@ def draft_changelog(
307337
)
308338
@use_checkout_dir()
309339
def check_changelog(
310-
ref, branch, repo, auth, changelog_path, since, resolve_backports, output
340+
ref,
341+
branch,
342+
repo,
343+
auth,
344+
changelog_path,
345+
since,
346+
since_last_stable,
347+
resolve_backports,
348+
output,
311349
):
312350
"""Check changelog entry"""
313351
changelog.check_entry(
314-
ref, branch, repo, auth, changelog_path, since, resolve_backports, output
352+
ref,
353+
branch,
354+
repo,
355+
auth,
356+
changelog_path,
357+
since,
358+
since_last_stable,
359+
resolve_backports,
360+
output,
315361
)
316362

317363

jupyter_releaser/lib.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ def check_links(ignore_glob, ignore_links, cache_file, links_expire):
8383
util.run(file_cmd + " --lf", shell=False)
8484

8585

86-
def draft_changelog(version_spec, branch, repo, since, auth, changelog_path, dry_run):
86+
def draft_changelog(
87+
version_spec, branch, repo, since, since_last_stable, auth, changelog_path, dry_run
88+
):
8789
"""Create a changelog entry PR"""
8890
repo = repo or util.get_repo()
8991
branch = branch or util.get_branch()
@@ -124,7 +126,9 @@ def draft_changelog(version_spec, branch, repo, since, auth, changelog_path, dry
124126
| Branch | {branch} |
125127
| Version Spec | {version_spec} |
126128
"""
127-
if since:
129+
if since_last_stable:
130+
body += "| Since Last Stable | true |"
131+
elif since:
128132
body += f"| Since | {since} |"
129133
util.log(body)
130134

jupyter_releaser/tests/test_cli.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ def test_list_envvars(runner):
166166
repo: RH_REPOSITORY
167167
resolve-backports: RH_RESOLVE_BACKPORTS
168168
since: RH_SINCE
169+
since-last-stable: RH_SINCE_LAST_STABLE
169170
tag-format: RH_TAG_FORMAT
170171
tag-message: RH_TAG_MESSAGE
171172
twine-cmd: TWINE_COMMAND
@@ -315,13 +316,23 @@ def test_draft_changelog_skip(py_package, mocker, runner, open_mock, git_prep):
315316
config["skip"] = ["draft-changelog"]
316317
config_path.write_text(util.toml.dumps(config), encoding="utf-8")
317318

318-
runner(["draft-changelog", "--version-spec", VERSION_SPEC])
319+
runner(["draft-changelog", "--version-spec", VERSION_SPEC, "--since", "foo"])
319320
open_mock.assert_not_called()
320321

321322

322323
def test_draft_changelog_dry_run(npm_package, mocker, runner, git_prep):
323324
mock_changelog_entry(npm_package, runner, mocker)
324-
runner(["draft-changelog", "--dry-run", "--version-spec", VERSION_SPEC])
325+
os.environ["RH_SINCE_LAST_STABLE"] = "true"
326+
runner(
327+
[
328+
"draft-changelog",
329+
"--dry-run",
330+
"--version-spec",
331+
VERSION_SPEC,
332+
"--since-last-stable",
333+
]
334+
)
335+
del os.environ["RH_SINCE_LAST_STABLE"]
325336

326337

327338
def test_draft_changelog_lerna(workspace_package, mocker, runner, open_mock, git_prep):

jupyter_releaser/tests/test_functions.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,33 @@ def test_get_changelog_version_entry(py_package, mocker):
8787
assert testutil.PR_ENTRY in resp
8888

8989

90+
def test_get_changelog_version_entry_since_last_stable(py_package, mocker):
91+
version = util.get_version()
92+
93+
mocked_gen = mocker.patch("jupyter_releaser.changelog.generate_activity_md")
94+
mocked_gen.return_value = testutil.CHANGELOG_ENTRY
95+
branch = "foo"
96+
util.run("git branch baz/bar")
97+
util.run("git tag v1.0.0 baz/bar")
98+
util.run("git tag v1.1.0a0 baz/bar")
99+
ref = "heads/baz/bar"
100+
resp = changelog.get_version_entry(
101+
ref, branch, "baz/bar", version, since_last_stable=True
102+
)
103+
mocked_gen.assert_called_with(
104+
"baz/bar",
105+
since="v1.0.0",
106+
until=None,
107+
kind="pr",
108+
branch=branch,
109+
heading_level=2,
110+
auth=None,
111+
)
112+
113+
assert f"## {version}" in resp
114+
assert testutil.PR_ENTRY in resp
115+
116+
90117
def test_compute_sha256(py_package):
91118
assert len(util.compute_sha256(py_package / "CHANGELOG.md")) == 64
92119

0 commit comments

Comments
 (0)