Skip to content

Commit

Permalink
Increase major version on definition new Major version - #23
Browse files Browse the repository at this point in the history
  • Loading branch information
haimkastner committed Jul 12, 2024
1 parent e4dc343 commit 4721a8d
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 7 deletions.
13 changes: 8 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@ jobs:
if: github.ref == 'refs/heads/main'
id: update_version
run: |
VERSION=$(python setup.py --version)
DEFINITION_VERSION=$(grep -oP "(?<=definition_version = ')[^']+" setup.py)
CURRENT_DEFINITION=$(python ./scripts/definition-version.py)
NEXT_VERSION=$(python ./scripts/next-package-version.py $VERSION $DEFINITION_VERSION $CURRENT_DEFINITION)
old_version=$(python setup.py --version)
IFS='.' read -ra parts <<< "$old_version"
version="${parts[0]}.${parts[1]}.$((parts[2]+1))"
sed -i 's|'$old_version'|'$version'|g' setup.py
echo "VERSION=$version" >> $GITHUB_OUTPUT
sed -i 's|'$VERSION'|'$NEXT_VERSION'|g' setup.py
sed -i "s/definition_version = '[^']*'/definition_version = '$CURRENT_DEFINITION'/" setup.py
echo "VERSION=$NEXT_VERSION" >> $GITHUB_OUTPUT
- name: Get version info
id: version_info
Expand Down
22 changes: 22 additions & 0 deletions scripts/definition-version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import requests
import xml.etree.ElementTree as ET

url = 'https://raw.githubusercontent.com/angularsen/UnitsNet/master/UnitsNet/UnitsNet.csproj'

try:
response = requests.get(url)
response.raise_for_status() # Raise an exception for HTTP errors

xml = response.text
root = ET.fromstring(xml)

# Assuming the structure of the XML is consistent with the example
version = root.find('.//PropertyGroup/Version').text
print(version)

except requests.exceptions.RequestException as e:
print('Error fetching the URL:', e)
except ET.ParseError as e:
print('Error parsing XML:', e)
except Exception as e:
print('Error:', e)
29 changes: 29 additions & 0 deletions scripts/next-package-version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import sys

# Function to parse version string to major, minor, patch
def parse_version(version):
major, minor, patch = map(int, version.split('.'))
return {'major': major, 'minor': minor, 'patch': patch}

# Function to increment the version
def increment_version(current_version, definition_version, current_definition_version):
current = parse_version(current_version)
definition = parse_version(definition_version)
current_definition = parse_version(current_definition_version)

if current_definition['major'] > definition['major']:
# Increment major version
return f"{current['major'] + 1}.0.0"
else:
# Increment patch version
return f"{current['major']}.{current['minor']}.{current['patch'] + 1}"

# Get the current version from command line arguments
if len(sys.argv) < 4:
print('Please provide the current version, definition version, and current definition version as arguments.')
sys.exit(1)

current_version, definition_version, current_definition_version = sys.argv[1:4]

new_version = increment_version(current_version, definition_version, current_definition_version)
print(new_version)
8 changes: 6 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
package_data = \
{'': ['*']}

# The UnitNet definition version that the current package is based on to generate units classes
# see
definition_version = '5.54.0'

setup_kwargs = {
'name': 'unitsnet-py',
'version': '0.1.117',
Expand All @@ -19,9 +23,9 @@
'long_description': long_description,
'long_description_content_type': "text/markdown",
'author': 'Haim Kastner',
'author_email': 'haim.kastner@gmail.com',
'author_email': 'hello@haim-kastner.com',
'maintainer': 'Haim Kastner',
'maintainer_email': 'haim.kastner@gmail.com',
'maintainer_email': 'hello@haim-kastner.com',
'url': 'https://github.com/haimkastner/unitsnet-py',
'packages': packages,
'package_data': package_data,
Expand Down

0 comments on commit 4721a8d

Please sign in to comment.