Skip to content

Commit

Permalink
Update update_gear_version.py
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeyfilyanin authored Nov 27, 2024
1 parent a32a4ac commit 82d7740
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions scripts/update_gear_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,32 @@
# ABSOLUTE PATH to cargo file
CARGO_FILE_PATH = '../contracts/Cargo.toml'

def get_latest_semver_tag(repo_url, prefix=''):
def get_latest_gear_version(repo_url):
"""Fetch the latest GEAR version, assuming tags are in standard semantic version format."""
response = requests.get(repo_url)
response.raise_for_status()
tags = response.json()

# Filter out tags that are not valid semantic versions with the given prefix
pattern = r'^' + re.escape(prefix) + r'\d+\.\d+\.\d+$'
valid_tags = [tag['name'] for tag in tags if re.match(pattern, tag['name'])]
# Filter tags that match a standard semantic version
valid_tags = [tag['name'] for tag in tags if re.match(r'^v?\d+\.\d+\.\d+$', tag['name'])]

if not valid_tags:
print(f"No valid tags found in repository {repo_url}")
return None

# Remove prefix and sort by version
valid_tags = [tag.lstrip(prefix) for tag in valid_tags]
# Sort the valid tags by version and return the latest
valid_tags.sort(key=lambda s: version.parse(s.lstrip('v')), reverse=True)

return valid_tags[0] if valid_tags else None

def get_latest_sails_version(repo_url):
"""Fetch the latest SAILS version, considering tags with the 'rs/' prefix."""
response = requests.get(repo_url)
response.raise_for_status()
tags = response.json()

# Filter tags with 'rs/' prefix followed by a semantic version
valid_tags = [tag['name'] for tag in tags if re.match(r'^rs/\d+\.\d+\.\d+$', tag['name'])]

# Sort the valid tags by version and return the latest
valid_tags.sort(key=lambda s: version.parse(s.lstrip('rs/').lstrip('v')), reverse=True)

return valid_tags[0] if valid_tags else None

def update_cargo_toml(file_path, gear_version, sails_version):
Expand Down Expand Up @@ -59,12 +68,12 @@ def update_wf_contracts(file_path, gear_version):
file.write(content)

if __name__ == "__main__":
# Get the latest GEAR version (without prefix)
gear_version = get_latest_semver_tag(GEAR_REPO_TAGS_URL).lstrip('v')

# Get the latest SAILS version (with 'rs/' prefix)
sails_version = get_latest_semver_tag(SAILS_REPO_TAGS_URL, prefix='rs/').lstrip('v')
# Get the latest GEAR version (from gear repo)
gear_version = get_latest_gear_version(GEAR_REPO_TAGS_URL).lstrip('v')

# Get the latest SAILS version (from sails repo with 'rs/' prefix)
sails_version = get_latest_sails_version(SAILS_REPO_TAGS_URL).lstrip('rs/')

if gear_version and sails_version:
update_cargo_toml('../contracts/Cargo.toml', gear_version, sails_version)
update_wf_contracts('../.github/workflows/contracts-tests.yml', gear_version)

0 comments on commit 82d7740

Please sign in to comment.