Skip to content

Commit

Permalink
Prep fix (#60)
Browse files Browse the repository at this point in the history
* bump version `0.1.6`
* add min python and typing_extension requirements
* add `GE_RELEASE_LOG_LEVEL` env config
* iterate over version tags properly regardless of trunk

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
Kilo59 and pre-commit-ci[bot] authored May 22, 2024
1 parent 11a29dc commit cd5cddd
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 11 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,8 @@ Example: `export GE_RELEASE_TRUNK=0.18.x`
- Omit the `Reason` field and submit.

3. Draft a community announcement, have the team review it in `#topic-great_expectations`, and send the reviewed message to the community Slack channel `#announcements`.


#### Troubleshooting

Optionally you can set a `GE_RELEASER_LOG_LEVEL` environment variable to enable more verbose logging.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.5
0.1.6
9 changes: 9 additions & 0 deletions ge_releaser/cli.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import logging
import os
from typing import Final

import click

from ge_releaser.cmd.prep import prep
Expand All @@ -6,6 +10,11 @@
from ge_releaser.git import GitService
from ge_releaser.utils import setup

LOG_LEVEL_NAME: Final[str] = os.environ.get("GE_RELEASE_LOG_LEVEL", "WARNING")
LOG_LEVEL: Final[int] = logging.getLevelName(LOG_LEVEL_NAME.upper())

logging.basicConfig(level=LOG_LEVEL)


@click.group()
@click.pass_context
Expand Down
18 changes: 12 additions & 6 deletions ge_releaser/cmd/prep.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
import os
from typing import List, Tuple
from typing import Final, List, Tuple

import click
from github.PullRequest import PullRequest
Expand All @@ -10,6 +10,8 @@
from ge_releaser.constants import GxFile, GxURL
from ge_releaser.git import GitService

LOGGER: Final[logging.Logger] = logging.getLogger(__name__)


def prep(git: GitService) -> None:
click.secho("[prep]", bold=True, fg="blue")
Expand Down Expand Up @@ -55,12 +57,16 @@ def prep(git: GitService) -> None:
def _parse_versions(
git: GitService,
) -> Tuple[str, str]:
tags = git.get_tags()
release_version = version.parse(str(tags[-1]))
last_version = version.parse(str(tags[-2]))
tags_filter = "0." if git.trunk_is_0ver else "1."
tags_iterator = git.iter_recent_tags(prefix_filter=tags_filter, limit=2)

assert release_version > last_version, "Version provided to command is not valid"
release_version = version.parse(next(tags_iterator))
last_version = version.parse(next(tags_iterator))

LOGGER.info(f"{last_version=} {release_version=}")
assert (
release_version > last_version
), f"Version provided to command is not valid, {release_version} <= {last_version}"
return str(last_version), str(release_version)


Expand Down Expand Up @@ -153,7 +159,7 @@ def _collect_prs_since_last_release(
if not pr.merged or "RELEASE" in pr.title:
continue

logging.info(pr, pr.merged_at, counter)
LOGGER.info(pr, pr.merged_at, counter)
if pr.merged_at < last_release:
counter += 1
if pr.merged_at > last_release:
Expand Down
32 changes: 29 additions & 3 deletions ge_releaser/git.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import datetime as dt
from typing import Iterable, List
import logging
from typing import Final, Generator, Iterable, List

import git
import github
from github.PullRequest import PullRequest

from ge_releaser.constants import GxFile

LOGGER: Final[logging.Logger] = logging.getLogger(__name__)


class GitService:
def __init__(
Expand Down Expand Up @@ -35,8 +38,31 @@ def trunk_is_0ver(self) -> bool:
"""
return self._trunk.startswith("0.")

def get_tags(self) -> List[git.Tag]:
return sorted(self._git.tags, key=lambda t: t.commit.committed_datetime)
def get_tags(self, reverse: bool = False) -> List[git.Tag]:
"""See also `.iter_recent_tags()`"""
return sorted(
self._git.tags, key=lambda t: t.commit.committed_datetime, reverse=reverse
)

def iter_recent_tags(
self, prefix_filter: str, limit: int = 2
) -> Generator[str, None, None]:
"""
Iterate over tags that start with a given prefix, up to a limit.
Useful for filtering out unrelated tags.
"""
LOGGER.info(f"iter_tags: prefix_filter={prefix_filter}, limit={limit}")
if limit < 1:
raise ValueError("Limit must be greater than 0")
itered: int = 0
for tag in self.get_tags(reverse=True):
LOGGER.debug(f"tag: {tag.name}")
if itered >= limit:
return
if tag.name.startswith(prefix_filter):
LOGGER.info(f"yielding tag: {tag.name}")
yield tag.name
itered += 1

def tag_commit(self, commit: str, version: str) -> None:
self._git.git.checkout(commit)
Expand Down
2 changes: 1 addition & 1 deletion ge_releaser/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def check_if_in_gx_root() -> None:
def check_if_using_latest_version() -> None:
current_version = _get_current_version()
latest_version = _get_latest_version()
if current_version != latest_version:
if current_version < latest_version:
raise ValueError(
f"Your version of `ge_releaser` is outdated (local: {current_version}, remote: {latest_version}).\nPlease pull down latest changes before continuing."
)
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ packaging
PyGithub==1.55
python-dateutil==2.8.2
requests>=2.20
typing-extensions>=4.9
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def get_requirements() -> List[str]:
name="ge_releaser",
version=get_version(),
install_requires=get_requirements(),
python_requires=">=3.8",
entry_points="""
[console_scripts]
ge_releaser=ge_releaser.cli:cli
Expand Down

0 comments on commit cd5cddd

Please sign in to comment.