mirror of https://github.com/abpframework/abp.git
committed by
GitHub
1 changed files with 63 additions and 38 deletions
@ -1,54 +1,79 @@ |
|||||
import os |
import os |
||||
import json |
import json |
||||
|
import re |
||||
|
import xml.etree.ElementTree as ET |
||||
from github import Github |
from github import Github |
||||
|
|
||||
def update_latest_versions(): |
def get_target_release_branch(version): |
||||
version = os.environ["GITHUB_REF"].split("/")[-1] |
""" |
||||
|
Extracts the first two numbers from the release version (`9.0.5` → `rel-9.0`) |
||||
|
to determine the corresponding `rel-x.x` branch. |
||||
|
""" |
||||
|
match = re.match(r"(\d+)\.(\d+)\.\d+", version) |
||||
|
if not match: |
||||
|
raise ValueError(f"Invalid version format: {version}") |
||||
|
|
||||
if "rc" in version: |
major, minor = match.groups() |
||||
return False |
target_branch = f"rel-{major}.{minor}" |
||||
|
return target_branch |
||||
|
|
||||
with open("latest-versions.json", "r") as f: |
def get_version_from_common_props(branch): |
||||
latest_versions = json.load(f) |
""" |
||||
|
Retrieves `Version` and `LeptonXVersion` from the `common.props` file in the specified branch. |
||||
|
""" |
||||
|
g = Github(os.environ["GITHUB_TOKEN"]) |
||||
|
repo = g.get_repo("abpframework/abp") |
||||
|
|
||||
latest_versions[0]["version"] = version |
try: |
||||
|
file_content = repo.get_contents("common.props", ref=branch) |
||||
|
common_props_content = file_content.decoded_content.decode("utf-8") |
||||
|
|
||||
with open("latest-versions.json", "w") as f: |
root = ET.fromstring(common_props_content) |
||||
json.dump(latest_versions, f, indent=2) |
version = root.find(".//Version").text |
||||
|
leptonx_version = root.find(".//LeptonXVersion").text |
||||
|
|
||||
return True |
return version, leptonx_version |
||||
|
except Exception as e: |
||||
|
raise FileNotFoundError(f"common.props not found in branch {branch}: {e}") |
||||
|
|
||||
def create_pr(): |
def update_latest_versions(): |
||||
g = Github(os.environ["GITHUB_TOKEN"]) |
""" |
||||
repo = g.get_repo("abpframework/abp") |
Updates `latest-versions.json` based on the most relevant release branch. |
||||
|
""" |
||||
|
# Get the release version from GitHub reference |
||||
|
release_version = os.environ["GITHUB_REF"].split("/")[-1] # Example: "refs/tags/v9.0.5" → "v9.0.5" |
||||
|
if release_version.startswith("v"): |
||||
|
release_version = release_version[1:] # Convert to "9.0.5" format |
||||
|
|
||||
branch_name = f"update-latest-versions-{os.environ['GITHUB_REF'].split('/')[-1]}" |
# Determine the correct `rel-x.x` branch |
||||
base = repo.get_branch("dev") |
target_branch = get_target_release_branch(release_version) |
||||
repo.create_git_ref(ref=f"refs/heads/{branch_name}", sha=base.commit.sha) |
|
||||
|
# Retrieve `common.props` data from the target branch |
||||
|
version, leptonx_version = get_version_from_common_props(target_branch) |
||||
|
|
||||
# Get the current latest-versions.json file and its sha |
# Skip if the version is a preview or release candidate |
||||
contents = repo.get_contents("latest-versions.json", ref="dev") |
if "preview" in version or "rc" in version: |
||||
file_sha = contents.sha |
return False |
||||
|
|
||||
# Update the file in the repo |
# Read the `latest-versions.json` file |
||||
repo.update_file( |
with open("latest-versions.json", "r") as f: |
||||
path="latest-versions.json", |
latest_versions = json.load(f) |
||||
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: |
# Add the new version entry |
||||
pr = repo.create_pull(title="Update latest-versions.json", |
new_version_entry = { |
||||
body="Automated PR to update the latest-versions.json file.", |
"version": version, |
||||
head=branch_name, base="dev") |
"releaseDate": "", |
||||
except Exception as e: |
"type": "stable", |
||||
print(f"Error while creating PR: {e}") |
"message": "", |
||||
|
"leptonx": { |
||||
|
"version": leptonx_version |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
latest_versions.insert(0, new_version_entry) # Insert the new version at the top |
||||
|
|
||||
pr.create_review_request(reviewers=["ebicoglu", "gizemmutukurt", "skoc10"]) |
# Update the file |
||||
|
with open("latest-versions.json", "w") as f: |
||||
|
json.dump(latest_versions, f, indent=2) |
||||
|
|
||||
if __name__ == "__main__": |
return True |
||||
should_create_pr = update_latest_versions() |
|
||||
if should_create_pr: |
|
||||
create_pr() |
|
||||
|
|||||
Loading…
Reference in new issue