From 45fdc686fa19830045a97da8f648e6d481c03248 Mon Sep 17 00:00:00 2001 From: selman koc <64414348+skoc10@users.noreply.github.com> Date: Fri, 7 Feb 2025 15:12:22 +0300 Subject: [PATCH 1/5] Update update-versions.yml github action pipeline --- .github/workflows/update-versions.yml | 74 +++++++++++++++------------ 1 file changed, 41 insertions(+), 33 deletions(-) diff --git a/.github/workflows/update-versions.yml b/.github/workflows/update-versions.yml index d0a295884f..a46f7d6076 100644 --- a/.github/workflows/update-versions.yml +++ b/.github/workflows/update-versions.yml @@ -1,33 +1,41 @@ -name: Update Latest Versions - -on: - release: - types: - - published - -permissions: - contents: write - pull-requests: write - -jobs: - update-versions: - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v2 - - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: 3.x - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install PyGithub - - - name: Update latest-versions.json and create PR - env: - GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }} - run: | - python .github/scripts/update_versions.py +import os +import json +import xml.etree.ElementTree as ET + +def get_version_from_common_props(): + """ common.props dosyasındaki versiyon bilgilerini çeker. """ + tree = ET.parse("common.props") + root = tree.getroot() + + version = root.find(".//Version").text + leptonx_version = root.find(".//LeptonXVersion").text + + return version, leptonx_version + +def update_latest_versions(): + version, leptonx_version = get_version_from_common_props() + + # Eğer versiyon "preview" içeriyorsa PR oluşturma (sadece stable versiyonlar için) + if "preview" in version or "rc" in version: + return False + + with open("latest-versions.json", "r") as f: + latest_versions = json.load(f) + + # Yeni versiyon bilgisini en üst sıraya ekle + new_version_entry = { + "version": version, + "releaseDate": "", + "type": "stable", + "message": "", + "leptonx": { + "version": leptonx_version + } + } + + latest_versions.insert(0, new_version_entry) # Yeni versiyonu en üste ekliyoruz + + with open("latest-versions.json", "w") as f: + json.dump(latest_versions, f, indent=2) + + return True From 05efbb77ff1fcd586827f314c1ef1834962348cd Mon Sep 17 00:00:00 2001 From: selmankoc Date: Fri, 7 Feb 2025 15:15:43 +0300 Subject: [PATCH 2/5] Revert "Update update-versions.yml github action pipeline" This reverts commit 45fdc686fa19830045a97da8f648e6d481c03248. --- .github/workflows/update-versions.yml | 74 ++++++++++++--------------- 1 file changed, 33 insertions(+), 41 deletions(-) diff --git a/.github/workflows/update-versions.yml b/.github/workflows/update-versions.yml index a46f7d6076..d0a295884f 100644 --- a/.github/workflows/update-versions.yml +++ b/.github/workflows/update-versions.yml @@ -1,41 +1,33 @@ -import os -import json -import xml.etree.ElementTree as ET - -def get_version_from_common_props(): - """ common.props dosyasındaki versiyon bilgilerini çeker. """ - tree = ET.parse("common.props") - root = tree.getroot() - - version = root.find(".//Version").text - leptonx_version = root.find(".//LeptonXVersion").text - - return version, leptonx_version - -def update_latest_versions(): - version, leptonx_version = get_version_from_common_props() - - # Eğer versiyon "preview" içeriyorsa PR oluşturma (sadece stable versiyonlar için) - if "preview" in version or "rc" in version: - return False - - with open("latest-versions.json", "r") as f: - latest_versions = json.load(f) - - # Yeni versiyon bilgisini en üst sıraya ekle - new_version_entry = { - "version": version, - "releaseDate": "", - "type": "stable", - "message": "", - "leptonx": { - "version": leptonx_version - } - } - - latest_versions.insert(0, new_version_entry) # Yeni versiyonu en üste ekliyoruz - - with open("latest-versions.json", "w") as f: - json.dump(latest_versions, f, indent=2) - - return True +name: Update Latest Versions + +on: + release: + types: + - published + +permissions: + contents: write + pull-requests: write + +jobs: + update-versions: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.x + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install PyGithub + + - name: Update latest-versions.json and create PR + env: + GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }} + run: | + python .github/scripts/update_versions.py From 1bde19cdf11827afb1f91506313c72d6df56ae98 Mon Sep 17 00:00:00 2001 From: selmankoc Date: Fri, 7 Feb 2025 15:30:01 +0300 Subject: [PATCH 3/5] Enhance version update script to fetch latest release branch and version details from common.props --- .github/scripts/update_versions.py | 93 ++++++++++++++++++------------ 1 file changed, 55 insertions(+), 38 deletions(-) diff --git a/.github/scripts/update_versions.py b/.github/scripts/update_versions.py index dcbd749796..a0c45ea407 100644 --- a/.github/scripts/update_versions.py +++ b/.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() \ No newline at end of file From 88d220b64943c28c225d666d61bc7a0b8fcfc14d Mon Sep 17 00:00:00 2001 From: selmankoc Date: Fri, 7 Feb 2025 15:36:55 +0300 Subject: [PATCH 4/5] Update docstrings in update_versions.py for clarity and consistency --- .github/scripts/update_versions.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/scripts/update_versions.py b/.github/scripts/update_versions.py index a0c45ea407..93817e3f10 100644 --- a/.github/scripts/update_versions.py +++ b/.github/scripts/update_versions.py @@ -5,7 +5,7 @@ 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. """ + """ Lists all `rel-x.x` branches in the GitHub repository and returns the one with the highest version. """ g = Github(os.environ["GITHUB_TOKEN"]) repo = g.get_repo("abpframework/abp") @@ -28,7 +28,7 @@ def get_latest_release_branch(): return latest_branch def get_version_from_common_props(branch): - """ Belirtilen branch'teki `common.props` dosyasından `Version` ve `LeptonXVersion` bilgilerini çeker. """ + """ Fetches the `Version` and `LeptonXVersion` information from the `common.props` file in the specified branch. """ g = Github(os.environ["GITHUB_TOKEN"]) repo = g.get_repo("abpframework/abp") From c4c674eb5d1784dee7a3e3f167a1a4a512a871b2 Mon Sep 17 00:00:00 2001 From: selmankoc Date: Fri, 7 Feb 2025 16:33:49 +0300 Subject: [PATCH 5/5] Refactor version update logic to determine target release branch and improve error handling for common.props retrieval --- .github/scripts/update_versions.py | 80 ++++++++++++++++-------------- 1 file changed, 44 insertions(+), 36 deletions(-) diff --git a/.github/scripts/update_versions.py b/.github/scripts/update_versions.py index 93817e3f10..1f593273bc 100644 --- a/.github/scripts/update_versions.py +++ b/.github/scripts/update_versions.py @@ -4,55 +4,62 @@ import re import xml.etree.ElementTree as ET from github import Github -def get_latest_release_branch(): - """ Lists all `rel-x.x` branches in the GitHub repository and returns the one with the highest version. """ - 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_target_release_branch(version): + """ + 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}") + + major, minor = match.groups() + target_branch = f"rel-{major}.{minor}" + return target_branch def get_version_from_common_props(branch): - """ Fetches the `Version` and `LeptonXVersion` information from the `common.props` file in the specified branch. """ + """ + 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") - # 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") + try: + 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 + root = ET.fromstring(common_props_content) + version = root.find(".//Version").text + leptonx_version = root.find(".//LeptonXVersion").text - return version, leptonx_version + return version, leptonx_version + except Exception as e: + raise FileNotFoundError(f"common.props not found in branch {branch}: {e}") def update_latest_versions(): - latest_branch = get_latest_release_branch() - version, leptonx_version = get_version_from_common_props(latest_branch) - + """ + 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 + + # Determine the correct `rel-x.x` branch + target_branch = get_target_release_branch(release_version) + + # Retrieve `common.props` data from the target branch + version, leptonx_version = get_version_from_common_props(target_branch) + + # Skip if the version is a preview or release candidate if "preview" in version or "rc" in version: return False + # Read the `latest-versions.json` file with open("latest-versions.json", "r") as f: latest_versions = json.load(f) + # Add the new version entry new_version_entry = { "version": version, "releaseDate": "", @@ -62,9 +69,10 @@ def update_latest_versions(): "version": leptonx_version } } + + latest_versions.insert(0, new_version_entry) # Insert the new version at the top - latest_versions.insert(0, new_version_entry) # Add to the beginning of the list - + # Update the file with open("latest-versions.json", "w") as f: json.dump(latest_versions, f, indent=2)