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

chore: improve logic to configure release-please for previous major versions #1408

Merged
merged 4 commits into from
Apr 6, 2022
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
7 changes: 0 additions & 7 deletions blargh.yml

This file was deleted.

22 changes: 12 additions & 10 deletions synthtool/languages/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,25 +159,27 @@ def configure_previous_major_version_branches() -> None:
if the library version is currently 3.5.1, the release-please config
will include v2, v1, and v0.
"""
if list(Path(".").glob("google/**/version.py")):
version_file = list(Path(".").glob("google/**/version.py"))[0]
else:
version_file = Path("setup.py")

# In version.py: __version__ = "1.5.2"
# In setup.py: version = "1.5.2"
VERSION_REGEX = (
r"(?:__)?version(?:__)?\s*=\s*[\"'](?P<major_version>\d)\.[\d\.]+[\"']"
)
version_paths = list(Path(".").glob("google/**/version.py")) + [Path("setup.py")]

match = re.search(VERSION_REGEX, Path(version_file).read_text())
major_version = None

if match is not None:
major_version = int(match.group("major_version"))
else:
for p in version_paths:
match = re.search(VERSION_REGEX, Path(p).read_text())

if match is not None:
major_version = int(match.group("major_version"))
break

if major_version is None:
raise RuntimeError(
"Unable to find library version in {} with regex {}".format(
version_file, VERSION_REGEX
"Unable to find library version in files {} with regex {}".format(
version_paths, VERSION_REGEX
)
)

Expand Down