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

Vin*_*ent 6 github-actions

事件触发 GitHub 操作是可能delete。然而,根据这些,GITHUB_REF变量然后指向默认分支,而不是被删除的分支。(同样地,对于push事件。)

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

pet*_*ans 13

您可以从 github 上下文访问github.event.ref和。github.event.ref_type

当其他引用类型也被删除时,该事件也会触发。所以你需要过滤branch删除的内容。

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 }}"
Run Code Online (Sandbox Code Playgroud)