[llvm] [Github] Make prune-unused-branches workflow save branch list (PR #181194)

Aiden Grossman via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 12 10:27:40 PST 2026


https://github.com/boomanaiden154 updated https://github.com/llvm/llvm-project/pull/181194

>From bf9dd63d8966bcfb91ed60efe46978b2440a6c2d Mon Sep 17 00:00:00 2001
From: Aiden Grossman <aidengrossman at google.com>
Date: Thu, 12 Feb 2026 17:49:16 +0000
Subject: [PATCH 1/3] [Github] Make prune-unused-branches workflow save branch
 list

So that we can retrieve it later to only download branches that are more
than a day old. This prevents unlikely but potential race conditions for
tools like spr and graphite, but more importantly for people manually
creating user branches where there branch getting deleted by the
workflow would be surprising.
---
 .github/workflows/prune-branches.yml       | 8 +++++++-
 .github/workflows/prune-unused-branches.py | 7 +++++--
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/.github/workflows/prune-branches.yml b/.github/workflows/prune-branches.yml
index 73a1e6a97bee8..a96da966ed7d2 100644
--- a/.github/workflows/prune-branches.yml
+++ b/.github/workflows/prune-branches.yml
@@ -30,10 +30,16 @@ jobs:
           GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
         run: |
           mkdir patches
-          python3 .github/workflows/prune-unused-branches.py patches/
+          python3 .github/workflows/prune-unused-branches.py .
       - name: Upload Patches
         uses: actions/upload-artifact at b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
         with:
           name: BranchDiffs
           retention-days: 90
           path: patches/*.patch
+      - name: Upload Branch List
+        uses: actions/upload-artifact at b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
+        with:
+          name: BranchDiffs
+          retention-days: 90
+          path: branches.txt
diff --git a/.github/workflows/prune-unused-branches.py b/.github/workflows/prune-unused-branches.py
index ac8d87f4241e0..2ae88b08f9386 100644
--- a/.github/workflows/prune-unused-branches.py
+++ b/.github/workflows/prune-unused-branches.py
@@ -121,11 +121,14 @@ def delete_branches(branches_to_remove: list[str]):
 def main(github_token):
     if len(sys.argv) != 2:
         print(
-            "Invalid invocation. Correct usage: python3 prune-unused-branches.py <patch output diectory>"
+            "Invalid invocation. Correct usage: python3 prune-unused-branches.py <output diectory>"
         )
         sys.exit(1)
 
     user_branches = get_branches()
+    output_dir = sys.argv[1]
+    with open(os.path.join(output_dir, "branches.txt"), "w") as branches_file:
+        branches_file.writelines(user_branches)
     user_branches_from_prs = get_branches_from_open_prs(github_token)
     print(f"Found {len(user_branches)} user branches in the repository")
     print(f"Found {len(user_branches_from_prs)} user branches associated with PRs")
@@ -133,7 +136,7 @@ def main(github_token):
         user_branches, user_branches_from_prs
     )
     print(f"Deleting {len(user_branches_to_remove)} user branches.")
-    generate_patches_for_all_branches(user_branches_to_remove, sys.argv[1])
+    generate_patches_for_all_branches(user_branches_to_remove, os.path.join(output_dir, "patches"))
     delete_branches(user_branches_to_remove)
 
 

>From a1f8e02566a47c60c56f7b821890dc353fa190e7 Mon Sep 17 00:00:00 2001
From: Aiden Grossman <aidengrossman at google.com>
Date: Thu, 12 Feb 2026 17:56:12 +0000
Subject: [PATCH 2/3] Formatting

---
 .github/workflows/prune-unused-branches.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/.github/workflows/prune-unused-branches.py b/.github/workflows/prune-unused-branches.py
index 2ae88b08f9386..0713ff5ca810d 100644
--- a/.github/workflows/prune-unused-branches.py
+++ b/.github/workflows/prune-unused-branches.py
@@ -136,7 +136,9 @@ def main(github_token):
         user_branches, user_branches_from_prs
     )
     print(f"Deleting {len(user_branches_to_remove)} user branches.")
-    generate_patches_for_all_branches(user_branches_to_remove, os.path.join(output_dir, "patches"))
+    generate_patches_for_all_branches(
+        user_branches_to_remove, os.path.join(output_dir, "patches")
+    )
     delete_branches(user_branches_to_remove)
 
 

>From 93b5d29b9fd50de7342a68cdb895c800cdd6a845 Mon Sep 17 00:00:00 2001
From: Aiden Grossman <aidengrossman at google.com>
Date: Thu, 12 Feb 2026 18:27:26 +0000
Subject: [PATCH 3/3] fix

---
 .github/workflows/prune-branches.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.github/workflows/prune-branches.yml b/.github/workflows/prune-branches.yml
index a96da966ed7d2..5b131e731e9a9 100644
--- a/.github/workflows/prune-branches.yml
+++ b/.github/workflows/prune-branches.yml
@@ -40,6 +40,6 @@ jobs:
       - name: Upload Branch List
         uses: actions/upload-artifact at b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
         with:
-          name: BranchDiffs
+          name: BranchList
           retention-days: 90
           path: branches.txt



More information about the llvm-commits mailing list