Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add delete branches workflow #2250

Merged
merged 2 commits into from
Oct 29, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions .github/workflows/delete_branches.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Delete Branches by Prefix
on:
workflow_dispatch:
inputs:
branch-prefix:
description: 'Branch prefix to match (e.g., "deps/" or "feature/")'
lastmjs marked this conversation as resolved.
Show resolved Hide resolved
required: true
type: string
dry-run:
description: 'Dry run (show branches that would be deleted without deleting)'
required: true
type: boolean
default: true

jobs:
delete-branches:
name: Delete Branches
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}

- name: Collect branches
id: collect-branches
run: |
# Get branches and convert to space-separated list
BRANCHES=$(git branch -r | grep "origin/${{ inputs.branch-prefix }}" | sed 's/origin\///' | xargs)
echo "branches=$BRANCHES" >> $GITHUB_OUTPUT

- name: Display collected branches
run: |
echo "Branches matching prefix '${{ inputs.branch-prefix }}':"
for branch in ${{ steps.collect-branches.outputs.branches }}; do
echo " - $branch"
done
echo "End of branch list"

- name: Delete branches
if: ${{ inputs.dry-run == false && steps.collect-branches.outputs.branches != '' }}
run: |
echo "Deleting branches..."
git push origin --delete ${{ steps.collect-branches.outputs.branches }}
echo "Branch deletion complete"

- name: Dry run message
if: ${{ inputs.dry-run }}
run: |
echo "DRY RUN - No branches were deleted"
echo "The above branches would have been deleted if this wasn't a dry run"
Loading