Skip to content

Cleanup release candidate branches #1095

Cleanup release candidate branches

Cleanup release candidate branches #1095

name: Cleanup release candidate branches
on:
delete:
branches:
- '!candidates/*'
env:
GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }}
REPO_URL: ${{ github.server_url }}/${{ github.repository }}
jobs:
delete-release-candidate:
runs-on: ubuntu-latest
steps:
# This step is only for credential setup
- name: Check out repo
uses: actions/checkout@v2
- name: 'Delete orphaned release candidates'
run: |
while read candidate_sha1 candidate_ref; do
test "$candidate_ref" || continue
source_branch=${candidate_ref#refs/heads/candidates/}
source_ref=refs/heads/$source_branch
if ! [[ $(git ls-remote "$REPO_URL" "$source_ref") ]]; then
printf 'Pruning orphaned release candidate: %s\n' "$candidate_ref"
git push "$REPO_URL" --delete "$candidate_ref"
fi
done <<< "$(git ls-remote "$REPO_URL" 'refs/heads/candidates/*')"
printf 'All orphaned release candidates successfully pruned\n'