Skip to content

Commit

Permalink
Add Wf to update Gear tag in cargo.toml (#415)
Browse files Browse the repository at this point in the history
  • Loading branch information
Magorsky authored Jul 20, 2024
1 parent 6863b0a commit ae63bb8
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/UpdateGearDependency.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
38 changes: 38 additions & 0 deletions scripts/update_cargo_toml.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit ae63bb8

Please sign in to comment.