在GitHub Actions中,是否可以访问已删除分支的名称?

问题描述:

通过 delete事件.但是,据此,GITHUB_REF变量然后指向 default 分支,而不是被删除的分支. (类似于 push事件.)

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.)

是否可以获取已删除的分支的名称?具体来说,我想使用为响应push事件而创建的分支名称的ID清理部署.

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.

您可以从github上下文访问github.event.refgithub.event.ref_type.

You can access github.event.ref and github.event.ref_type from the github context.

当其他引用类型也被删除时,该事件将触发.因此,您只需要过滤branch删除项即可.

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 }}"