Skip to content

Conversation

tstellar
Copy link
Collaborator

We used to support a /branch comment to specify a branch with commits to backport to the release branch. However, now that we can use pull requests this is not needed.

This also simplifies the process, because now the cherry-pick job can create the pull request directly instead of having it split across two separate jobs.

We used to support a /branch comment to specify a branch with commits
to backport to the release branch.  However, now that we can use pull
requests this is not needed.

This also simplifies the process, because now the cherry-pick job
can create the pull request directly instead of having it split
across two separate jobs.
@llvmbot
Copy link
Member

llvmbot commented Jan 25, 2024

@llvm/pr-subscribers-github-workflow

Author: Tom Stellard (tstellar)

Changes

We used to support a /branch comment to specify a branch with commits to backport to the release branch. However, now that we can use pull requests this is not needed.

This also simplifies the process, because now the cherry-pick job can create the pull request directly instead of having it split across two separate jobs.


Full diff: https://github.com/llvm/llvm-project/pull/79481.diff

3 Files Affected:

  • (modified) .github/workflows/issue-release-workflow.yml (+1-32)
  • (modified) llvm/docs/GitHub.rst (+5-7)
  • (modified) llvm/utils/git/github-automation.py (+6-11)
diff --git a/.github/workflows/issue-release-workflow.yml b/.github/workflows/issue-release-workflow.yml
index 17209ec055f858e..112ece40bac9c1a 100644
--- a/.github/workflows/issue-release-workflow.yml
+++ b/.github/workflows/issue-release-workflow.yml
@@ -35,6 +35,7 @@ jobs:
     runs-on: ubuntu-latest
     permissions:
       issues: write
+      pull-requests: write
     if: >-
       (github.repository == 'llvm/llvm-project') &&
       !startswith(github.event.comment.body, '<!--IGNORE-->') &&
@@ -65,35 +66,3 @@ jobs:
           --branch-repo-token ${{ secrets.RELEASE_WORKFLOW_PUSH_SECRET }} \
           --issue-number ${{ github.event.issue.number }} \
           auto
-
-  create-pull-request:
-    name: Create Pull Request
-    runs-on: ubuntu-latest
-    permissions:
-      issues: write
-      pull-requests: write
-    if: >-
-      (github.repository == 'llvm/llvm-project') &&
-      !startswith(github.event.comment.body, '<!--IGNORE-->') &&
-      contains(github.event.comment.body, '/branch ')
-
-    steps:
-      - name: Fetch LLVM sources
-        uses: actions/checkout@v4
-        with:
-          persist-credentials: false
-
-      - name: Setup Environment
-        run: |
-          pip install -r ./llvm/utils/git/requirements.txt
-
-      - name: Create Pull Request
-        run: |
-          printf "%s" "$COMMENT_BODY" |
-          ./llvm/utils/git/github-automation.py \
-          --repo "$GITHUB_REPOSITORY" \
-          --token ${{ github.token }} \
-          release-workflow \
-          --branch-repo-token ${{ secrets.RELEASE_WORKFLOW_PUSH_SECRET }} \
-          --issue-number ${{ github.event.issue.number }} \
-          auto
diff --git a/llvm/docs/GitHub.rst b/llvm/docs/GitHub.rst
index a89a4d955fc08b2..b84d4953a9488f1 100644
--- a/llvm/docs/GitHub.rst
+++ b/llvm/docs/GitHub.rst
@@ -360,8 +360,8 @@ Releases
 Backporting Fixes to the Release Branches
 -----------------------------------------
 You can use special comments on issues to make backport requests for the
-release branches.  This is done by making a comment containing one of the
-following commands on any issue that has been added to one of the "X.Y.Z Release"
+release branches.  This is done by making a comment containing the following
+command on any issue that has been added to one of the "X.Y.Z Release"
 milestones.
 
 ::
@@ -376,8 +376,6 @@ be created with the specified commits.
 
 ::
 
-  /branch <owner>/<repo>/<branch>
-
-This command will create a pull request against the latest release branch using
-the <branch> from the <owner>/<repo> repository.  <branch> cannot contain any
-forward slash '/' characters.
+If a commit you want to backport does not apply cleanly, you may resolve
+the conflicts locally and then create a pull request against the release
+branch.  Just make sure to add the release milestone to the pull request.
diff --git a/llvm/utils/git/github-automation.py b/llvm/utils/git/github-automation.py
index 72db9995b0e8a59..0531915d5602772 100755
--- a/llvm/utils/git/github-automation.py
+++ b/llvm/utils/git/github-automation.py
@@ -308,6 +308,10 @@ def repo_name(self) -> str:
     def issue_number(self) -> int:
         return self._issue_number
 
+    @property
+    def branch_repo_owner(self) -> str:
+        return self.branch_repo_name.split('/')[0]
+
     @property
     def branch_repo_name(self) -> str:
         return self._branch_repo_name
@@ -394,7 +398,7 @@ def issue_notify_cherry_pick_failure(
         action_url = self.action_url
         if action_url:
             message += action_url + "\n\n"
-        message += "Please manually backport the fix and push it to your github fork.  Once this is done, please add a comment like this:\n\n`/branch <user>/<repo>/<branch>`"
+        message += "Please manually backport the fix and push it to your github fork.  Once this is done, please create a [pull request](https://github.com/llvm/llvm-project/compare)"
         issue = self.issue
         comment = issue.create_comment(message)
         issue.add_to_labels(self.CHERRY_PICK_FAILED_LABEL)
@@ -472,9 +476,8 @@ def create_branch(self, commits: List[str]) -> bool:
         print("Pushing to {} {}".format(push_url, branch_name))
         local_repo.git.push(push_url, "HEAD:{}".format(branch_name), force=True)
 
-        self.issue_notify_branch()
         self.issue_remove_cherry_pick_failed_label()
-        return True
+        return self.create_pull_request(self.branch_repo_owner, self.repo_name, branch_name)
 
     def check_if_pull_request_exists(
         self, repo: github.Repository.Repository, head: str
@@ -552,14 +555,6 @@ def execute_command(self) -> bool:
                 commits = list(map(lambda a: extract_commit_hash(a), arg_list))
                 return self.create_branch(commits)
 
-            if command == "branch":
-                m = re.match("([^/]+)/([^/]+)/(.+)", args)
-                if m:
-                    owner = m.group(1)
-                    repo = m.group(2)
-                    branch = m.group(3)
-                    return self.create_pull_request(owner, repo, branch)
-
         print("Do not understand input:")
         print(sys.stdin.readlines())
         return False

Copy link

@llvm/pr-subscribers-github-workflow

Author: Tom Stellard (tstellar)

Changes

We used to support a /branch comment to specify a branch with commits to backport to the release branch. However, now that we can use pull requests this is not needed.

This also simplifies the process, because now the cherry-pick job can create the pull request directly instead of having it split across two separate jobs.


Full diff: https://github.com/llvm/llvm-project/pull/79481.diff

3 Files Affected:

  • (modified) .github/workflows/issue-release-workflow.yml (+1-32)
  • (modified) llvm/docs/GitHub.rst (+5-7)
  • (modified) llvm/utils/git/github-automation.py (+6-11)
diff --git a/.github/workflows/issue-release-workflow.yml b/.github/workflows/issue-release-workflow.yml
index 17209ec055f858e..112ece40bac9c1a 100644
--- a/.github/workflows/issue-release-workflow.yml
+++ b/.github/workflows/issue-release-workflow.yml
@@ -35,6 +35,7 @@ jobs:
    runs-on: ubuntu-latest
    permissions:
      issues: write
+      pull-requests: write
    if: >-
      (github.repository == 'llvm/llvm-project') &&
      !startswith(github.event.comment.body, '<!--IGNORE-->') &&
@@ -65,35 +66,3 @@ jobs:
          --branch-repo-token ${{ secrets.RELEASE_WORKFLOW_PUSH_SECRET }} \
          --issue-number ${{ github.event.issue.number }} \
          auto
-
-  create-pull-request:
-    name: Create Pull Request
-    runs-on: ubuntu-latest
-    permissions:
-      issues: write
-      pull-requests: write
-    if: >-
-      (github.repository == 'llvm/llvm-project') &&
-      !startswith(github.event.comment.body, '<!--IGNORE-->') &&
-      contains(github.event.comment.body, '/branch ')
-
-    steps:
-      - name: Fetch LLVM sources
-        uses: actions/checkout@v4
-        with:
-          persist-credentials: false
-
-      - name: Setup Environment
-        run: |
-          pip install -r ./llvm/utils/git/requirements.txt
-
-      - name: Create Pull Request
-        run: |
-          printf "%s" "$COMMENT_BODY" |
-          ./llvm/utils/git/github-automation.py \
-          --repo "$GITHUB_REPOSITORY" \
-          --token ${{ github.token }} \
-          release-workflow \
-          --branch-repo-token ${{ secrets.RELEASE_WORKFLOW_PUSH_SECRET }} \
-          --issue-number ${{ github.event.issue.number }} \
-          auto
diff --git a/llvm/docs/GitHub.rst b/llvm/docs/GitHub.rst
index a89a4d955fc08b2..b84d4953a9488f1 100644
--- a/llvm/docs/GitHub.rst
+++ b/llvm/docs/GitHub.rst
@@ -360,8 +360,8 @@ Releases
Backporting Fixes to the Release Branches
-----------------------------------------
You can use special comments on issues to make backport requests for the
-release branches.  This is done by making a comment containing one of the
-following commands on any issue that has been added to one of the "X.Y.Z Release"
+release branches.  This is done by making a comment containing the following
+command on any issue that has been added to one of the "X.Y.Z Release"
milestones.

::
@@ -376,8 +376,6 @@ be created with the specified commits.

::

-  /branch <owner>/<repo>/<branch>
-
-This command will create a pull request against the latest release branch using
-the <branch> from the <owner>/<repo> repository.  <branch> cannot contain any
-forward slash '/' characters.
+If a commit you want to backport does not apply cleanly, you may resolve
+the conflicts locally and then create a pull request against the release
+branch.  Just make sure to add the release milestone to the pull request.
diff --git a/llvm/utils/git/github-automation.py b/llvm/utils/git/github-automation.py
index 72db9995b0e8a59..0531915d5602772 100755
--- a/llvm/utils/git/github-automation.py
+++ b/llvm/utils/git/github-automation.py
@@ -308,6 +308,10 @@ def repo_name(self) -> str:
    def issue_number(self) -> int:
        return self._issue_number

+    @property
+    def branch_repo_owner(self) -> str:
+        return self.branch_repo_name.split('/')[0]
+
    @property
    def branch_repo_name(self) -> str:
        return self._branch_repo_name
@@ -394,7 +398,7 @@ def issue_notify_cherry_pick_failure(
        action_url = self.action_url
        if action_url:
            message += action_url + "\n\n"
-        message += "Please manually backport the fix and push it to your github fork.  Once this is done, please add a comment like this:\n\n`/branch <user>/<repo>/<branch>`"
+        message += "Please manually backport the fix and push it to your github fork.  Once this is done, please create a [pull request](https://github.com/llvm/llvm-project/compare)"
        issue = self.issue
        comment = issue.create_comment(message)
        issue.add_to_labels(self.CHERRY_PICK_FAILED_LABEL)
@@ -472,9 +476,8 @@ def create_branch(self, commits: List[str]) -> bool:
        print("Pushing to {} {}".format(push_url, branch_name))
        local_repo.git.push(push_url, "HEAD:{}".format(branch_name), force=True)

-        self.issue_notify_branch()
        self.issue_remove_cherry_pick_failed_label()
-        return True
+        return self.create_pull_request(self.branch_repo_owner, self.repo_name, branch_name)

    def check_if_pull_request_exists(
        self, repo: github.Repository.Repository, head: str
@@ -552,14 +555,6 @@ def execute_command(self) -> bool:
                commits = list(map(lambda a: extract_commit_hash(a), arg_list))
                return self.create_branch(commits)

-            if command == "branch":
-                m = re.match("([^/]+)/([^/]+)/(.+)", args)
-                if m:
-                    owner = m.group(1)
-                    repo = m.group(2)
-                    branch = m.group(3)
-                    return self.create_pull_request(owner, repo, branch)
-
        print("Do not understand input:")
        print(sys.stdin.readlines())
        return False

Error: Command failed due to missing milestone.

Copy link

github-actions bot commented Jan 25, 2024

✅ With the latest revision this PR passed the Python code formatter.

Copy link
Member

@ldionne ldionne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like those changes!

@tstellar tstellar merged commit e99edf6 into llvm:main Jan 25, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants