From 82d774089900276f84a6fcc1ab3c0a5ef36adb13 Mon Sep 17 00:00:00 2001 From: sergey filyanin Date: Wed, 27 Nov 2024 14:32:47 +0100 Subject: [PATCH] Update update_gear_version.py --- scripts/update_gear_version.py | 39 +++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/scripts/update_gear_version.py b/scripts/update_gear_version.py index 94b431fa9..19e8b0bab 100644 --- a/scripts/update_gear_version.py +++ b/scripts/update_gear_version.py @@ -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): @@ -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)