diff --git a/.github/workflows/UpdateGearDependency.yml b/.github/workflows/UpdateGearDependency.yml index 880b142bb..79faecb05 100644 --- a/.github/workflows/UpdateGearDependency.yml +++ b/.github/workflows/UpdateGearDependency.yml @@ -25,14 +25,17 @@ jobs: - name: Install GitPython run: | python -m pip install --upgrade pip - pip install gitpython + pip install requests packaging gitpython - name: Check for new tag and update Cargo.toml + env: + GITHUB_TOKEN: ${{ secrets.UPDATE_GEAR_TAG_TOKEN }} run: | python update_cargo_toml.py if ! git diff --exit-code; then git config user.name "github-actions[bot]" git config user.email "41898282+github-actions[bot]@users.noreply.github.com" - git add Cargo.toml - git commit -m "Update dependencies to latest tag" + git add ../contracts/Cargo.toml + git commit -m "Update GEAR dependencies to latest tag in contracts" git push + fi diff --git a/scripts/update_cargo_toml.py b/scripts/update_cargo_toml.py new file mode 100644 index 000000000..9bb071516 --- /dev/null +++ b/scripts/update_cargo_toml.py @@ -0,0 +1,38 @@ +import re +import requests +from packaging import version + +# GitHub API URL to get the latest tags +GEAR_REPO_TAGS_URL = "https://api.github.com/repos/gear-tech/gear/tags" + +# ABSOLUTE PATH to cargo file +CARGO_FILE_PATH = '../contracts/Cargo.toml' + +def get_latest_semver_tag(): + response = requests.get(GEAR_REPO_TAGS_URL) + response.raise_for_status() + tags = response.json() + # Filter out tags that are not valid semantic versions + valid_tags = [tag['name'] for tag in tags if re.match(r'^v?\d+\.\d+\.\d+$', tag['name'])] + # Sort the valid tags by version + valid_tags.sort(key=lambda s: version.parse(s.lstrip('v')), reverse=True) + return valid_tags[0] if valid_tags else None + +def update_cargo_toml(file_path, new_version): + with open(file_path, 'r') as file: + content = file.read() + + content = re.sub(r'gstd = ".*?"', f'gstd = "{new_version}"', content) + content = re.sub(r'gear-wasm-builder = ".*?"', f'gear-wasm-builder = "{new_version}"', content) + content = re.sub(r'gmeta = ".*?"', f'gmeta = "{new_version}"', content) + content = re.sub(r'gclient = ".*?"', f'gclient = "{new_version}"', content) + content = re.sub(r'gtest = { git = "https://github.com/gear-tech/gear", tag = ".*?" }', f'gtest = {{ git = "https://github.com/gear-tech/gear", tag = "v{new_version}" }}', content) + content = re.sub(r'gear-core = ".*?"', f'gear-core = "{new_version}"', content) + + with open(file_path, 'w') as file: + file.write(content) + +if __name__ == "__main__": + new_version = get_latest_semver_tag().lstrip('v') + if new_version: + update_cargo_toml('../contracts/Cargo.toml', new_version)