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

Use regex.sub to replace old versions with new ones #89

Merged
merged 2 commits into from
Aug 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 19 additions & 11 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
from collections.abc import Generator
from functools import cache, cached_property
from typing import Any
Expand Down Expand Up @@ -169,8 +170,12 @@ def _update_workflow(self, workflow_path: str) -> set[str]:
gha_utils.echo(
f'Updating "{action}" with "{updated_action}"...'
)
updated_workflow_data = updated_workflow_data.replace(
action, updated_action
updated_workflow_data = re.sub(
rf"({action})(\s+|$)",
rf"{updated_action}\2",
updated_workflow_data,
0,
re.MULTILINE,
)
else:
gha_utils.echo(f'No updates found for "{action_repository}"')
Expand Down Expand Up @@ -213,7 +218,9 @@ def _generate_updated_item_markdown(
f"branch on {version_data['commit_date']}\n"
)

def _get_github_releases(self, action_repository: str) -> list[dict[str, Any]]:
def _get_github_releases(
self, action_repository: str
) -> list[dict[str, str | Version | LegacyVersion]]:
"""Get the GitHub releases using GitHub API"""
url = f"{self.github_api_url}/repos/{action_repository}/releases?per_page=50"

Expand Down Expand Up @@ -261,22 +268,23 @@ def _release_filter_function(self):
checks = []

if ReleaseType.MAJOR in self.user_config.release_types:
checks.append(lambda r, c: r["tag_name_parsed"].major > c.major)
checks.append(lambda r, c: r.major > c.major)

if ReleaseType.MINOR in self.user_config.release_types:
checks.append(
lambda r, c: r["tag_name_parsed"].major == c.major
and r["tag_name_parsed"].minor > c.minor,
lambda r, c: r.major == c.major and r.minor > c.minor,
)

if ReleaseType.PATCH in self.user_config.release_types:
checks.append(
lambda r, c: r["tag_name_parsed"].major == c.major
and r["tag_name_parsed"].minor == c.minor
and r["tag_name_parsed"].micro > c.micro
lambda r, c: r.major == c.major
and r.minor == c.minor
and r.micro > c.micro
)

def filter_func(release_tag: str, current_version: Version) -> bool:
def filter_func(
release_tag: LegacyVersion | Version, current_version: Version
) -> bool:
return any(check(release_tag, current_version) for check in checks)

return filter_func
Expand Down Expand Up @@ -305,7 +313,7 @@ def _get_latest_version_release(
latest_release = next(
filter(
lambda r: self._release_filter_function(
r, parsed_current_version
r["tag_name_parsed"], parsed_current_version
),
github_releases,
),
Expand Down