Nightly prune merged PR branches #93
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: Nightly prune merged PR branches | |
| on: | |
| schedule: | |
| - cron: '30 3 * * *' | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| pull-requests: read | |
| jobs: | |
| prune: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Delete merged PR branches (keep main & gnome43-44) | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| REPO: ${{ github.repository }} | |
| run: | | |
| set -e | |
| KEEP=" main gnome43-44 " | |
| mapfile -t heads < <(gh pr list --state merged --limit 500 -R "$REPO" --json headRefName --jq '.[].headRefName') | |
| for b in "${heads[@]}"; do | |
| if [[ "$KEEP" == *" $b "* ]]; then continue; fi | |
| echo "Deleting $b" | |
| gh api -X DELETE repos/$REPO/git/refs/heads/$b || true | |
| done |