Skip to content

Commit

Permalink
Merge branch 'dev' into net9locking
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkCiliaVincenti authored Feb 8, 2025
2 parents 35baacf + 1aa86ad commit e7c158c
Show file tree
Hide file tree
Showing 1,142 changed files with 21,684 additions and 8,565 deletions.
101 changes: 63 additions & 38 deletions .github/scripts/update_versions.py
Original file line number Diff line number Diff line change
@@ -1,54 +1,79 @@
import os
import json
import re
import xml.etree.ElementTree as ET
from github import Github

def update_latest_versions():
version = os.environ["GITHUB_REF"].split("/")[-1]
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}")

if "rc" in version:
return False
major, minor = match.groups()
target_branch = f"rel-{major}.{minor}"
return target_branch

with open("latest-versions.json", "r") as f:
latest_versions = json.load(f)
def get_version_from_common_props(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")

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:
json.dump(latest_versions, f, indent=2)
root = ET.fromstring(common_props_content)
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():
g = Github(os.environ["GITHUB_TOKEN"])
repo = g.get_repo("abpframework/abp")
def update_latest_versions():
"""
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]}"
base = repo.get_branch("dev")
repo.create_git_ref(ref=f"refs/heads/{branch_name}", sha=base.commit.sha)
# 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)

# Get the current latest-versions.json file and its sha
contents = repo.get_contents("latest-versions.json", ref="dev")
file_sha = contents.sha
# Skip if the version is a preview or release candidate
if "preview" in version or "rc" in version:
return False

# 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,
)
# Read the `latest-versions.json` file
with open("latest-versions.json", "r") as f:
latest_versions = json.load(f)

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}")
# Add the new version entry
new_version_entry = {
"version": version,
"releaseDate": "",
"type": "stable",
"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__":
should_create_pr = update_latest_versions()
if should_create_pr:
create_pr()
return True
20 changes: 10 additions & 10 deletions .github/workflows/auto-pr.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
name: Merge branch dev with rel-9.0
name: Merge branch dev with rel-9.1
on:
push:
branches:
- rel-9.0
- rel-9.1
permissions:
contents: read

jobs:
merge-dev-with-rel-9-0:
merge-dev-with-rel-9-1:
permissions:
contents: write # for peter-evans/create-pull-request to create branch
pull-requests: write # for peter-evans/create-pull-request to create a PR
Expand All @@ -18,14 +18,14 @@ jobs:
ref: dev
- name: Reset promotion branch
run: |
git fetch origin rel-9.0:rel-9.0
git reset --hard rel-9.0
git fetch origin rel-9.1:rel-9.1
git reset --hard rel-9.1
- name: Create Pull Request
uses: peter-evans/create-pull-request@v3
with:
branch: auto-merge/rel-9-0/${{github.run_number}}
title: Merge branch dev with rel-9.0
body: This PR generated automatically to merge dev with rel-9.0. Please review the changed files before merging to prevent any errors that may occur.
branch: auto-merge/rel-9-1/${{github.run_number}}
title: Merge branch dev with rel-9.1
body: This PR generated automatically to merge dev with rel-9.1. Please review the changed files before merging to prevent any errors that may occur.
reviewers: maliming
draft: true
token: ${{ github.token }}
Expand All @@ -34,5 +34,5 @@ jobs:
GH_TOKEN: ${{ secrets.BOT_SECRET }}
run: |
gh pr ready
gh pr review auto-merge/rel-9-0/${{github.run_number}} --approve
gh pr merge auto-merge/rel-9-0/${{github.run_number}} --merge --auto --delete-branch
gh pr review auto-merge/rel-9-1/${{github.run_number}} --approve
gh pr merge auto-merge/rel-9-1/${{github.run_number}} --merge --auto --delete-branch
5 changes: 4 additions & 1 deletion .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ on:
- 'templates/**/*.razor'
- 'Directory.Build.props'
- 'Directory.Packages.props'
- '.github/workflows/build-and-test.yml'

pull_request:
paths:
Expand All @@ -35,6 +36,7 @@ on:
- 'templates/**/*.razor'
- 'Directory.Build.props'
- 'Directory.Packages.props'
- '.github/workflows/build-and-test.yml'
types:
- opened
- synchronize
Expand All @@ -45,7 +47,8 @@ permissions:

jobs:
build-test:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
timeout-minutes: 40
if: ${{ !github.event.pull_request.draft }}
steps:
- uses: actions/checkout@v2
Expand Down
Loading

0 comments on commit e7c158c

Please sign in to comment.