docs: improve Further Reading section in deployment.md #57
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: Cleanup Merged Branches | |
| on: | |
| pull_request: | |
| types: [closed] | |
| permissions: | |
| contents: write | |
| jobs: | |
| delete-branch: | |
| runs-on: ubuntu-latest | |
| if: github.event.pull_request.merged == true | |
| steps: | |
| - name: Delete merged branch | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const branchName = context.payload.pull_request.head.ref; | |
| const owner = context.repo.owner; | |
| const repo = context.repo.repo; | |
| // Don't delete protected branches or branches that match special patterns | |
| const protectedPatterns = ['main', 'master', 'develop', 'release/', 'hotfix/']; | |
| const shouldProtect = protectedPatterns.some(pattern => | |
| branchName === pattern || branchName.startsWith(pattern) | |
| ); | |
| if (shouldProtect) { | |
| console.log(`Branch ${branchName} matches protected pattern. Skipping deletion.`); | |
| return; | |
| } | |
| // Only delete if the branch is from the same repository (not from a fork) | |
| if (context.payload.pull_request.head.repo.full_name === context.payload.pull_request.base.repo.full_name) { | |
| try { | |
| await github.rest.git.deleteRef({ | |
| owner, | |
| repo, | |
| ref: `heads/${branchName}` | |
| }); | |
| console.log(`Successfully deleted branch: ${branchName}`); | |
| } catch (error) { | |
| console.log(`Failed to delete branch ${branchName}: ${error.message}`); | |
| } | |
| } else { | |
| console.log(`Branch ${branchName} is from a fork. Skipping deletion.`); | |
| } |