Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(ci): rewrite prune-branches to use GitHub API (#835)

Cindy Zhangfa883b197317
diff --git a/.github/workflows/prune-branches.yml b/.github/workflows/prune-branches.yml
index f0773104c4..35ba623847 100644
--- a/.github/workflows/prune-branches.yml
+++ b/.github/workflows/prune-branches.yml
@@ -13,29 +13,32 @@ jobs:
prune:
runs-on: ubuntu-latest
steps:
- - uses: actions/checkout@v4
- with:
- fetch-depth: 0
-
- name: Delete stale merged branches
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ shell: bash {0}
run: |
echo "Finding branches from merged PRs with no activity for > 1 day..."
CUTOFF=$(date -u -d '1 day ago' +%Y-%m-%dT%H:%M:%SZ)
- DELETED=0
- SKIPPED=0
- # Get all remote branches (excluding main, gh-pages)
- git branch -r --format='%(refname:short)' | sed 's|origin/||' | grep -vE '^(main|gh-pages)$' | while read branch; do
+ # List remote branches via API (no checkout needed)
+ BRANCHES=$(gh api repos/${{ github.repository }}/branches --paginate --jq '.[].name' | grep -vE '^(main|gh-pages)$' || true)
+
+ if [ -z "$BRANCHES" ]; then
+ echo "No candidate branches found."
+ exit 0
+ fi
+
+ DELETED=0
+ while IFS= read -r branch; do
# Check if this branch had a merged PR
PR_STATE=$(gh pr list --head "$branch" --state merged --json mergedAt --jq '.[0].mergedAt // empty' 2>/dev/null)
if [ -z "$PR_STATE" ]; then
continue
fi
- # Check last commit date on the branch
- LAST_COMMIT=$(git log -1 --format=%aI "origin/$branch" 2>/dev/null)
+ # Check last commit date on the branch via API
+ LAST_COMMIT=$(gh api "repos/${{ github.repository }}/branches/${branch}" --jq '.commit.commit.author.date' 2>/dev/null)
if [ -z "$LAST_COMMIT" ]; then
continue
fi
@@ -43,13 +46,13 @@ jobs:
# Compare: skip if last activity is within the cutoff
if [ "$(date -u -d "$LAST_COMMIT" +%s)" -gt "$(date -u -d "$CUTOFF" +%s)" ]; then
echo "⏭️ Skip (recent): $branch"
- SKIPPED=$((SKIPPED + 1))
continue
fi
echo "🗑️ Deleting: $branch (merged: $PR_STATE)"
- gh api repos/${{ github.repository }}/git/refs/heads/$branch -X DELETE 2>/dev/null && DELETED=$((DELETED + 1))
- done
+ gh api "repos/${{ github.repository }}/git/refs/heads/${branch}" -X DELETE 2>/dev/null || true
+ DELETED=$((DELETED + 1))
+ done <<< "$BRANCHES"
echo ""
echo "✅ Pruned $DELETED branches"