Skip to content

Commit

Permalink
Enhance version update script to fetch latest release branch and vers…
Browse files Browse the repository at this point in the history
…ion details from common.props
  • Loading branch information
skoc10 committed Feb 7, 2025
1 parent 05efbb7 commit 1bde19c
Showing 1 changed file with 55 additions and 38 deletions.
93 changes: 55 additions & 38 deletions .github/scripts/update_versions.py
Original file line number Diff line number Diff line change
@@ -1,54 +1,71 @@
import os
import json
import re
import xml.etree.ElementTree as ET
from github import Github

def get_latest_release_branch():
""" GitHub repository'deki tüm `rel-x.x` branch'lerini listeleyerek en büyük sürüme sahip olanı döndürür. """
g = Github(os.environ["GITHUB_TOKEN"])
repo = g.get_repo("abpframework/abp")

branches = repo.get_branches()
release_branches = []

# `rel-x.x` look for pattern
pattern = re.compile(r"rel-(\d+\.\d+)")

for branch in branches:
match = pattern.match(branch.name)
if match:
release_branches.append((branch.name, float(match.group(1)))) # (branch_name, version)

if not release_branches:
raise ValueError("No release branches found!")

# Find the branch with the highest version
latest_branch = max(release_branches, key=lambda x: x[1])[0]
return latest_branch

def get_version_from_common_props(branch):
""" Belirtilen branch'teki `common.props` dosyasından `Version` ve `LeptonXVersion` bilgilerini çeker. """
g = Github(os.environ["GITHUB_TOKEN"])
repo = g.get_repo("abpframework/abp")

# Take the content of the file
file_content = repo.get_contents("common.props", ref=branch)
common_props_content = file_content.decoded_content.decode("utf-8")

# XML parse it
root = ET.fromstring(common_props_content)
version = root.find(".//Version").text
leptonx_version = root.find(".//LeptonXVersion").text

return version, leptonx_version

def update_latest_versions():
version = os.environ["GITHUB_REF"].split("/")[-1]
latest_branch = get_latest_release_branch()
version, leptonx_version = get_version_from_common_props(latest_branch)

if "rc" in version:
if "preview" in version or "rc" in version:
return False

with open("latest-versions.json", "r") as f:
latest_versions = json.load(f)

latest_versions[0]["version"] = version
new_version_entry = {
"version": version,
"releaseDate": "",
"type": "stable",
"message": "",
"leptonx": {
"version": leptonx_version
}
}

latest_versions.insert(0, new_version_entry) # Add to the beginning of the list

with open("latest-versions.json", "w") as f:
json.dump(latest_versions, f, indent=2)

return True

def create_pr():
g = Github(os.environ["GITHUB_TOKEN"])
repo = g.get_repo("abpframework/abp")

branch_name = f"update-latest-versions-{os.environ['GITHUB_REF'].split('/')[-1]}"
base = repo.get_branch("dev")
repo.create_git_ref(ref=f"refs/heads/{branch_name}", sha=base.commit.sha)

# Get the current latest-versions.json file and its sha
contents = repo.get_contents("latest-versions.json", ref="dev")
file_sha = contents.sha

# Update the file in the repo
repo.update_file(
path="latest-versions.json",
message=f"Update latest-versions.json to version {os.environ['GITHUB_REF'].split('/')[-1]}",
content=open("latest-versions.json", "r").read().encode("utf-8"),
sha=file_sha,
branch=branch_name,
)

try:
pr = repo.create_pull(title="Update latest-versions.json",
body="Automated PR to update the latest-versions.json file.",
head=branch_name, base="dev")
except Exception as e:
print(f"Error while creating PR: {e}")

pr.create_review_request(reviewers=["ebicoglu", "gizemmutukurt", "skoc10"])

if __name__ == "__main__":
should_create_pr = update_latest_versions()
if should_create_pr:
create_pr()

0 comments on commit 1bde19c

Please sign in to comment.