feat(ci): add workflow to auto-delete merged branches #1
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Branch Cleanup | |
| on: | |
| pull_request: | |
| types: [closed] | |
| branches: | |
| - main | |
| jobs: | |
| delete-branch: | |
| runs-on: ubuntu-latest | |
| if: github.event.pull_request.merged == true && github.event.pull_request.head.ref != 'develop' | |
| steps: | |
| - name: Delete head branch | |
| uses: actions/github-script@v7 | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| script: | | |
| const branch = context.payload.pull_request.head.ref; | |
| try { | |
| await github.rest.git.deleteRef({ | |
| owner: context.repo.owner, | |
| repo: context.repo.name, | |
| ref: `heads/${branch}` | |
| }); | |
| console.log(`Deleted branch ${branch}`); | |
| } catch (error) { | |
| console.error(`Error deleting branch ${branch}:`, error); | |
| } |