It is possible to have a GitHub Action trigged by the delete
event. However, according to those, the GITHUB_REF
variable then points to the default branch, rather than the branch that was deleted. (Likewise for the push
event.)
Is it possible to obtain the name of the branch that was deleted? Specifically, I'd like to clean up a deployment with the branch name's ID that was created in response to the push
event.
Restoring a deleted branchOn GitHub.com, navigate to the main page of the repository. Under your repository name, click Pull requests. Click Closed to see a list of closed pull requests. In the list of pull requests, click the pull request that's associated with the branch that you want to restore.
If you delete a head branch after its pull request has been merged, GitHub checks for any open pull requests in the same repository that specify the deleted branch as their base branch. GitHub automatically updates any such pull requests, changing their base branch to the merged pull request's base branch.
A deleted Git branch can be restored at any time, regardless of when it was deleted. Open your repo on the web and select the Branches view. Search for the exact branch name using the Search all branches box in the upper right. Click the link to Search for exact match in deleted branches.
Previously, GitHub's web UI did not allow deleting a branch that was associated with an open pull request. Now you can delete such a branch from the UI. However, doing so will close all open pull requests associated with the branch. Before the branch is deleted, you must confirm that the pull requests may be closed.
You can access github.event.ref
and github.event.ref_type
from the github context.
The event will trigger when other ref types are deleted, too. So you need to filter just branch
deletions.
name: Branch Deleted
on: delete
jobs:
delete:
if: github.event.ref_type == 'branch'
runs-on: ubuntu-latest
steps:
- name: Clean up
run: |
echo "Clean up for branch ${{ github.event.ref }}"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With