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

ci: Fix semver assertions and values for development releases #125

Merged
merged 8 commits into from
Jun 5, 2024
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: 2 additions & 2 deletions .github/workflows/build-and-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ jobs:
then
if [ "$GITHUB_REF" = "refs/heads/main" ]
then
echo "::set-output name=version::0.0.0.rc0"
echo "::set-output name=version::0.0.0-rc.0"
else
PR_NUMBER=$(echo $GITHUB_REF | awk 'BEGIN { FS = "/" } ; { print $3 }')
echo "::set-output name=version::0.0.0.dev${PR_NUMBER}"
echo "::set-output name=version::0.0.0-dev.${PR_NUMBER}"
fi
else
SEMVER="${TAG_NAME:1}"
Expand Down
32 changes: 23 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,45 @@
raise Exception("ibapi version must be set via the IB_VERSION environment variable.")


def version_assert_format(version: str) -> None:
def is_valid_semver(version: str, allow_zero_prefix: bool=False):
"""
Checks if a string is in valid semver format.

Args:
version: The version string to validate.
allow_zero_prefix: Allow zero prefixes

Returns:
True if the string is in valid semver format, False otherwise.
"""
if allow_zero_prefix:
pattern = r'^([0-9]\d*)\.([0-9]\d*)\.([0-9]\d*)(-([0-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(\.([0-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*)?(\+[0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*)?$'
else:
pattern = r'^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(-(0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*)?(\+[0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*)?$'

return bool(re.match(pattern, version))


def version_assert_format(version: str, allow_zero_prefix: bool=False) -> None:
"""Assert that a version string is formatted correctly.

Args:
version: The version string to check.
allow_zero_prefix: Allow zero prefixes

Raises:
ValueError: If the version string is not formatted correctly.
"""
if not version:
raise ValueError("Version string is empty.")

# check if the version string is in semver format
# check if the version string is in semver format
pattern1 = re.compile(r"^([0-9]\d*)\.([0-9]\d*)\.([0-9]\d*)$")
pattern2 = re.compile(r"^([0-9]\d*)\.([0-9]\d*)\.([0-9]\d*)\.dev([0-9]\d*)$")
is_semver = bool(pattern1.match(version)) or bool(pattern2.match(version))

if not is_semver:
if not is_valid_semver(version, allow_zero_prefix=allow_zero_prefix):
raise ValueError(f"Version string is not in semver format: {version}")


version_assert_format(dh_ib_version)
version_assert_format(dh_version)
version_assert_format(ib_version)
version_assert_format(ib_version, allow_zero_prefix=True)

setuptools.setup(
name="deephaven_ib",
Expand Down
Loading