Skip to content

Commit

Permalink
[chore](auto-pick)Optimize the cherry-pick script
Browse files Browse the repository at this point in the history
- removing unnecessary comments and using a temporary directory for the Git clone operation.
  • Loading branch information
CalvinKirs committed Nov 2, 2024
1 parent c3507f5 commit 51634e6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/auto-cherry-pick.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
pip install PyGithub
- name: Check SHA
run: |
expected_sha="80b7c6087f2a3e4f4c7f035a52e8e7b05ce00f27aa5c1bd52179df685c912447f94a96145fd3204a3958d8ed9777de5a5183b120e99e0e95bbca0366d69b0ac0"
expected_sha="92426ad4842f46e119fb6b91132c5f92d1114f8ae7990dde3544225e423f101a3f36535d75d0e0323f363636fa8b935b6eda65bee67fb316fb416df062678d42"
calculated_sha=$(sha512sum tools/auto-pick-script.py | awk '{ print $1 }')
if [ "$calculated_sha" != "$expected_sha" ]; then
echo "SHA mismatch! Expected: $expected_sha, but got: $calculated_sha"
Expand Down
13 changes: 10 additions & 3 deletions tools/auto-pick-script.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,16 @@

# Clone the repository locally and switch to the new branch
repo_url = f"https://x-access-token:{GITHUB_TOKEN}@github.com/{REPO_NAME}.git"
subprocess.run(["git", "clone", repo_url])
repo_dir = REPO_NAME.split("/")[-1] # Get the directory name
#create tmp dir
repo_tmp_dir = f"/tmp/{pr_number}/{TARGET_BRANCH}/"
if os.path.exists(repo_tmp_dir):
print(f"Directory {repo_tmp_dir} already exists. Deleting it.")
subprocess.run(["rm", "-rf", repo_tmp_dir])
# cd to tmp
os.chdir(repo_tmp_dir)
subprocess.run(["git", "clone", repo_url])

subprocess.run(["git", "checkout", new_branch_name], cwd=repo_dir)

# Set Git user identity for commits
Expand Down Expand Up @@ -89,11 +97,10 @@
# Create a new PR for the cherry-picked changes
new_pr = repo.create_pull(
title=f"{TARGET_BRANCH}: {pr.title}", # Prefix with branch name
body=f"PR Body: {pr.body} \n Cherry-picked from #{pr.number}", # Keep the original PR body
body=f"Cherry-picked from #{pr.number}", # Keep the original PR body
head=new_branch_name,
base=TARGET_BRANCH
)
new_pr.create_issue_comment("run buildall")
print(f"Created a new PR #{new_pr.number} for cherry-picked changes.")
else:
print(f"Commit {merge_commit_sha} was not found in {new_branch_name} after cherry-picking.")
Expand Down

0 comments on commit 51634e6

Please sign in to comment.