From d87ba59d621d59a61e27c5d5c6d9406ed7e6a7d0 Mon Sep 17 00:00:00 2001 From: Benjamin DeMann Date: Tue, 29 Oct 2024 13:00:54 -0600 Subject: [PATCH 1/2] add delete branches workflow --- .github/workflows/delete_branches.yml | 51 +++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 .github/workflows/delete_branches.yml diff --git a/.github/workflows/delete_branches.yml b/.github/workflows/delete_branches.yml new file mode 100644 index 0000000000..1320e458b9 --- /dev/null +++ b/.github/workflows/delete_branches.yml @@ -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/")' + 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" From 1d84fcea93d429bec86f61795d98892d0b5a7a67 Mon Sep 17 00:00:00 2001 From: Benjamin DeMann Date: Tue, 29 Oct 2024 13:21:43 -0600 Subject: [PATCH 2/2] pr fixes --- .github/workflows/delete_branches.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/delete_branches.yml b/.github/workflows/delete_branches.yml index 1320e458b9..8a8c593405 100644 --- a/.github/workflows/delete_branches.yml +++ b/.github/workflows/delete_branches.yml @@ -3,7 +3,7 @@ on: workflow_dispatch: inputs: branch-prefix: - description: 'Branch prefix to match (e.g., "deps/" or "feature/")' + description: 'Branch prefix to match (e.g., "update--0.24.2-rc.89-" or "benchmark--0.25.0-")' required: true type: string dry-run: @@ -45,7 +45,7 @@ jobs: echo "Branch deletion complete" - name: Dry run message - if: ${{ inputs.dry-run }} + if: ${{ inputs.dry-run == true }} run: | echo "DRY RUN - No branches were deleted" echo "The above branches would have been deleted if this wasn't a dry run"