Skip to content

Commit

Permalink
Merge branch 'master' into unused-vmcs-import
Browse files Browse the repository at this point in the history
  • Loading branch information
smallkirby authored Jan 18, 2025
2 parents fe01841 + ef243d5 commit 4f87804
Show file tree
Hide file tree
Showing 10 changed files with 474 additions and 5 deletions.
30 changes: 30 additions & 0 deletions .github/scripts/branch-order.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
whiz-vmm-vmc
whiz-vmm-initramfs
whiz-vmm-intr_injection
whiz-vmm-io
whiz-vmm-cr
whiz-vmm-msr
whiz-vmm-cpuid
whiz-vmm-ept
whiz-vmm-linux_boot
whiz-vmm-vmentry_vmexit
whiz-vmm-vmcs
whiz-vmm-vmlaunch
whiz-vmm-vmx_root
whiz-ymir-general_allocator
whiz-ymir-pic
whiz-ymir-page_allocator
whiz-ymir-paging
whiz-ymir-panic
whiz-ymir-interrupt
whiz-ymir-gdt
whiz-ymir-serial_logsystem
whiz-ymir-bit_and_test
whiz-ymir-serial_output
whiz-surtr-jump_to_ymir
whiz-surtr-cleanup_memmap
whiz-surtr-load_kernel
whiz-surtr-simple_pg
whiz-surtr-parse_kernel
whiz-surtr-uefi_log
whiz-surtr-hello_uefi
113 changes: 113 additions & 0 deletions .github/scripts/cherry-picker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import os
import subprocess
from github import Github


def read_branch_order(filename=".github/scripts/branch-order.txt"):
with open(filename, "r") as f:
return [
line.strip()
for line in f
if (line.strip() and not line.strip().startswith("#"))
]


def get_current_branch(pr_number):
g = Github(os.environ["GITHUB_TOKEN"])
repo = g.get_repo(os.environ["REPO"])
pr = repo.get_pull(int(pr_number))
return pr.base.ref


def get_child_branches(current_branch, branches):
try:
current_index = branches.index(current_branch)
return branches[:current_index]
except ValueError:
return []


def cherry_pick_to_branch(commit_sha, target_branch):
try:
# Fetch and checkout target branch
subprocess.run(["git", "fetch", "origin", target_branch], check=True)
subprocess.run(["git", "checkout", target_branch], check=True)

# Cherry-pick the commit
result = subprocess.run(
["git", "cherry-pick", "-m", "1", commit_sha],
capture_output=True,
text=True,
)
print(result.stderr)

if result.returncode == 0:
# Push the changes
subprocess.run(
["git", "push", "origin", target_branch],
check=True
)
return True
else:
# If there's a conflict, abort the cherry-pick
subprocess.run(["git", "cherry-pick", "--abort"])
return False
except subprocess.CalledProcessError:
return False


def main():
# Get PR number from environment
pr_number = os.environ["PR_NUMBER"]

# Initialize GitHub client
g = Github(os.environ["GITHUB_TOKEN"])
repo = g.get_repo(os.environ["REPO"])
pr = repo.get_pull(int(pr_number))

# Check if the PR is merged
if not pr.merged:
print("❌ PR is not yet merged.")
return

# Get the merge commit SHA
merge_commit_sha = pr.merge_commit_sha
if not merge_commit_sha:
print("No merge commit found")
return
print(f"merge_commit_sha: {merge_commit_sha}")

# Read branch order
branches = read_branch_order()

# Get current branch and find children
current_branch = get_current_branch(pr_number)
child_branches = get_child_branches(current_branch, branches)

if len(child_branches) == 0:
pr.create_issue_comment(
"💤 No target branches found. Cherry-pick skipped."
)
return

# Cherry-pick to each child branch
failed_branches = []
for branch in child_branches:
success = cherry_pick_to_branch(merge_commit_sha, branch)
if not success:
failed_branches.append(branch)

if len(failed_branches) == 0:
pr.create_issue_comment(
f"✅ Successfully cherry-picked to {len(child_branches)} branches."
)
else:
pr.create_issue_comment(
"❌ Cherry-pick failed for the following branches "
"(manual intervention required):\n" +
"\n".join([f"- {branch}" for branch in failed_branches])
)


if __name__ == "__main__":
main()
40 changes: 40 additions & 0 deletions .github/workflows/cherry-pick-bot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Cherry Pick Bot

on:
issue_comment:
types: [created]

jobs:
cherry-pick:
if: contains(github.event.comment.body, '@.ymir cherry-pick') && github.event.comment.user.login == 'smallkirby'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Generate a token
id: generate-token
uses: actions/create-github-app-token@v1
with:
app_id: ${{ vars.APP_ID }}
private_key: ${{ secrets.APP_PRIVATE_KEY }}

- name: Setup uv
uses: astral-sh/setup-uv@v5

- name: Setup Python
run: |
uv python install
uv sync --all-extras
- name: Setup Git
run: |
git config --global user.name 'smallkirby-ymir[bot]'
git config --global user.email '195134948+smallkirby-ymir[bot]@users.noreply.github.com'
git fetch --all
- name: Run Cherry Pick Script
env:
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}
PR_NUMBER: ${{ github.event.issue.number }}
REPO: ${{ github.repository }}
run: uv run .github/scripts/cherry-picker.py
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/docs

.gdb_history
.venv
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.12
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[project]
name = "ymir-cherry-pick-bot"
version = "0.0.0"
requires-python = ">=3.12"
dependencies = [
"pygithub>=2.5.0",
]
Loading

0 comments on commit 4f87804

Please sign in to comment.