Skip to content

Commit

Permalink
ci: Fix semver assertions and values for development releases (#125)
Browse files Browse the repository at this point in the history
* Make the semver for release canddiates valid

* Adjust the release canddiate semvers

* Fix semver format check bug.

* Fixing the build

* More experiments

* Another try at semver validation

* More work on semver checking
  • Loading branch information
chipkent authored Jun 5, 2024
1 parent f6a0762 commit 334f6c3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
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

0 comments on commit 334f6c3

Please sign in to comment.