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

Add Since Last Stable Option for Changelog #147

Merged
merged 1 commit into from
Sep 11, 2021
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions .github/actions/draft-changelog/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ inputs:
since:
description: Use PRs with activity since this date or git reference
required: false
since_last_stable:
description: Use PRs with activity since the last stable git tag
required: false
outputs:
pr_url:
description: "The URL of the Changelog Pull Request"
Expand All @@ -47,6 +50,7 @@ runs:
export RH_DRY_RUN=${{ inputs.dry_run }}
export RH_REF=${GITHUB_REF}
export RH_SINCE=${{ inputs.since }}
export RH_SINCE_LAST_STABLE=${{ inputs.since_last_stable }}

# Install Jupyter Releaser from git
pip install -q git+https://github.com/jupyter-server/jupyter_releaser.git@v1
Expand Down
9 changes: 4 additions & 5 deletions .github/actions/draft-release/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,16 @@ inputs:
post_version_spec:
description: "Post Version Specifier"
required: false
changelog:
description: "Changelog file"
default: "CHANGELOG.md"
required: false
dry_run:
description: "If set, do not push permanent changes"
default: "false"
required: false
since:
description: Use PRs with activity since this date or git reference
required: false
since_last_stable:
description: Use PRs with activity since the last stable git tag
required: false
outputs:
release_url:
description: "The html URL of the draft GitHub release"
Expand All @@ -47,10 +46,10 @@ runs:
fi
export RH_REF=${GITHUB_REF}
export RH_VERSION_SPEC=${{ inputs.version_spec }}
export RH_CHANGELOG=${{ inputs.changelog }}
export RH_POST_VERSION_SPEC=${{ inputs.post_version_spec }}
export RH_DRY_RUN=${{ inputs.dry_run }}
export RH_SINCE=${{ inputs.since }}
export RH_SINCE_LAST_STABLE=$${{ inputs.since_last_stable }}

# Install Jupyter Releaser from git
pip install -q git+https://github.com/jupyter-server/jupyter_releaser.git@v1
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/draft-changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ on:
since:
description: Use PRs with activity since this date or git reference
required: false
since_last_stable:
description: Use PRs with activity since the last stable git tag
required: false
jobs:
changelog:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -45,6 +48,7 @@ jobs:
target: ${{ github.event.inputs.target }}
branch: ${{ github.event.inputs.branch }}
since: ${{ github.event.inputs.since }}
since_last_stable: ${{ github.event.intputs.since_last_stable }}
- name: "** Next Step **"
run: |
echo "Review PR: ${{ steps.draft-changelog.outputs.pr_url }}"
4 changes: 4 additions & 0 deletions .github/workflows/draft-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ on:
since:
description: Use PRs with activity since this date or git reference
required: false
since_last_stable:
description: Use PRs with activity since the last stable git tag
required: false
jobs:
release:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -52,6 +55,7 @@ jobs:
version_spec: ${{ github.event.inputs.version_spec }}
post_version_spec: ${{ github.event.inputs.post_version_spec }}
since: ${{ github.event.inputs.since }}
since_last_stable: ${{ github.event.intputs.since_last_stable }}
- name: "** Next Step **"
run: |
echo "Run the "Publish Release" Workflow with Release Url:"
Expand Down
48 changes: 38 additions & 10 deletions jupyter_releaser/changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def get_version_entry(
version,
*,
since=None,
since_last_stable=None,
until=None,
auth=None,
resolve_backports=False,
Expand All @@ -65,6 +66,8 @@ def get_version_entry(
The new version
since: str
Use PRs with activity since this date or git reference
since_last_stable:
Use PRs with activity since the last stable git tag
until: str, optional
Use PRs until this date or git reference
auth : str, optional
Expand All @@ -77,14 +80,7 @@ def get_version_entry(
str
A formatted changelog entry with markers
"""

if not since:
source = ref or branch
tags = util.run(
f"git --no-pager tag --sort=-creatordate --merged {source}", quiet=True
)
if tags:
since = tags.splitlines()[0]
since = since or _get_since(ref or branch, since_last_stable)

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

Expand Down Expand Up @@ -142,7 +138,9 @@ def get_version_entry(
return output


def build_entry(ref, branch, repo, auth, changelog_path, since, resolve_backports):
def build_entry(
ref, branch, repo, auth, changelog_path, since, since_last_stable, resolve_backports
):
"""Build a python version entry"""
branch = branch or util.get_branch()
repo = repo or util.get_repo()
Expand All @@ -166,6 +164,7 @@ def build_entry(ref, branch, repo, auth, changelog_path, since, resolve_backport
repo,
version,
since=since,
since_last_stable=since_last_stable,
auth=auth,
resolve_backports=resolve_backports,
)
Expand Down Expand Up @@ -211,7 +210,15 @@ def format(changelog):


def check_entry(
ref, branch, repo, auth, changelog_path, since, resolve_backports, output
ref,
branch,
repo,
auth,
changelog_path,
since,
since_last_stable,
resolve_backports,
output,
):
"""Check changelog entry"""
branch = branch or util.get_branch()
Expand Down Expand Up @@ -241,6 +248,7 @@ def check_entry(
repo,
version,
since=since,
since_last_stable=since_last_stable,
auth=auth,
resolve_backports=resolve_backports,
)
Expand Down Expand Up @@ -282,3 +290,23 @@ def extract_current(changelog_path):
if start != -1 and end != -1:
body = changelog[start + len(START_MARKER) : end]
return body


def _get_since(source, since_last_stable=False):
"""Get the appropriate since reference or None"""
tags = util.run(
f"git --no-pager tag --sort=-creatordate --merged {source}", quiet=True
)
if not tags:
return

tags = tags.splitlines()

if since_last_stable:
stable_tag = re.compile(r"\d\.\d\.\d$")
tags = [t for t in tags if re.search(stable_tag, t)]
if not tags:
return
return tags[0]

return tags[0]
60 changes: 53 additions & 7 deletions jupyter_releaser/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,13 @@ def main(force):
envvar="RH_SINCE",
default=None,
help="Use PRs with activity since this date or git reference",
)
),
click.option(
"--since-last-stable",
is_flag=True,
envvar="RH_SINCE_LAST_STABLE",
help="Use PRs with activity since the last stable git tag",
),
]

changelog_options = (
Expand Down Expand Up @@ -276,10 +282,19 @@ def bump_version(version_spec, version_cmd):
@main.command()
@add_options(changelog_options)
@use_checkout_dir()
def build_changelog(ref, branch, repo, auth, changelog_path, since, resolve_backports):
def build_changelog(
ref, branch, repo, auth, changelog_path, since, since_last_stable, resolve_backports
):
"""Build changelog entry"""
changelog.build_entry(
ref, branch, repo, auth, changelog_path, since, resolve_backports
ref,
branch,
repo,
auth,
changelog_path,
since,
since_last_stable,
resolve_backports,
)


Expand All @@ -292,11 +307,26 @@ def build_changelog(ref, branch, repo, auth, changelog_path, since, resolve_back
@add_options(dry_run_options)
@use_checkout_dir()
def draft_changelog(
version_spec, ref, branch, repo, since, auth, changelog_path, dry_run
version_spec,
ref,
branch,
repo,
since,
since_last_stable,
auth,
changelog_path,
dry_run,
):
"""Create a changelog entry PR"""
lib.draft_changelog(
version_spec, branch, repo, since, auth, changelog_path, dry_run
version_spec,
branch,
repo,
since,
since_last_stable,
auth,
changelog_path,
dry_run,
)


Expand All @@ -307,11 +337,27 @@ def draft_changelog(
)
@use_checkout_dir()
def check_changelog(
ref, branch, repo, auth, changelog_path, since, resolve_backports, output
ref,
branch,
repo,
auth,
changelog_path,
since,
since_last_stable,
resolve_backports,
output,
):
"""Check changelog entry"""
changelog.check_entry(
ref, branch, repo, auth, changelog_path, since, resolve_backports, output
ref,
branch,
repo,
auth,
changelog_path,
since,
since_last_stable,
resolve_backports,
output,
)


Expand Down
8 changes: 6 additions & 2 deletions jupyter_releaser/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ def check_links(ignore_glob, ignore_links, cache_file, links_expire):
util.run(file_cmd + " --lf", shell=False)


def draft_changelog(version_spec, branch, repo, since, auth, changelog_path, dry_run):
def draft_changelog(
version_spec, branch, repo, since, since_last_stable, auth, changelog_path, dry_run
):
"""Create a changelog entry PR"""
repo = repo or util.get_repo()
branch = branch or util.get_branch()
Expand Down Expand Up @@ -124,7 +126,9 @@ def draft_changelog(version_spec, branch, repo, since, auth, changelog_path, dry
| Branch | {branch} |
| Version Spec | {version_spec} |
"""
if since:
if since_last_stable:
body += "| Since Last Stable | true |"
elif since:
body += f"| Since | {since} |"
util.log(body)

Expand Down
15 changes: 13 additions & 2 deletions jupyter_releaser/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ def test_list_envvars(runner):
repo: RH_REPOSITORY
resolve-backports: RH_RESOLVE_BACKPORTS
since: RH_SINCE
since-last-stable: RH_SINCE_LAST_STABLE
tag-format: RH_TAG_FORMAT
tag-message: RH_TAG_MESSAGE
twine-cmd: TWINE_COMMAND
Expand Down Expand Up @@ -315,13 +316,23 @@ def test_draft_changelog_skip(py_package, mocker, runner, open_mock, git_prep):
config["skip"] = ["draft-changelog"]
config_path.write_text(util.toml.dumps(config), encoding="utf-8")

runner(["draft-changelog", "--version-spec", VERSION_SPEC])
runner(["draft-changelog", "--version-spec", VERSION_SPEC, "--since", "foo"])
open_mock.assert_not_called()


def test_draft_changelog_dry_run(npm_package, mocker, runner, git_prep):
mock_changelog_entry(npm_package, runner, mocker)
runner(["draft-changelog", "--dry-run", "--version-spec", VERSION_SPEC])
os.environ["RH_SINCE_LAST_STABLE"] = "true"
runner(
[
"draft-changelog",
"--dry-run",
"--version-spec",
VERSION_SPEC,
"--since-last-stable",
]
)
del os.environ["RH_SINCE_LAST_STABLE"]


def test_draft_changelog_lerna(workspace_package, mocker, runner, open_mock, git_prep):
Expand Down
27 changes: 27 additions & 0 deletions jupyter_releaser/tests/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,33 @@ def test_get_changelog_version_entry(py_package, mocker):
assert testutil.PR_ENTRY in resp


def test_get_changelog_version_entry_since_last_stable(py_package, mocker):
version = util.get_version()

mocked_gen = mocker.patch("jupyter_releaser.changelog.generate_activity_md")
mocked_gen.return_value = testutil.CHANGELOG_ENTRY
branch = "foo"
util.run("git branch baz/bar")
util.run("git tag v1.0.0 baz/bar")
util.run("git tag v1.1.0a0 baz/bar")
ref = "heads/baz/bar"
resp = changelog.get_version_entry(
ref, branch, "baz/bar", version, since_last_stable=True
)
mocked_gen.assert_called_with(
"baz/bar",
since="v1.0.0",
until=None,
kind="pr",
branch=branch,
heading_level=2,
auth=None,
)

assert f"## {version}" in resp
assert testutil.PR_ENTRY in resp


def test_compute_sha256(py_package):
assert len(util.compute_sha256(py_package / "CHANGELOG.md")) == 64

Expand Down