Browse Source

Enhance version update script to fetch latest release branch and version details from common.props

pull/22101/head
selmankoc 2 years ago
parent
commit
1bde19cdf1
  1. 93
      .github/scripts/update_versions.py

93
.github/scripts/update_versions.py

@ -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()
Loading…
Cancel
Save