【问题标题】:How to get the target branch of the GitHub pull request from an Actions?如何从 Actions 中获取 GitHub 拉取请求的目标分支?
【发布时间】:2020-10-01 12:52:16
【问题描述】:

当在 Github Actions 中的pull_request 上设置动作时,如何获取目标分支?用例是检索特定于 PR(并且希望是分支)的提交。

【问题讨论】:

    标签: continuous-integration github-actions


    【解决方案1】:

    您可以使用${{ github.event.pull_request.base.ref }} 访问目标分支。

    要了解github.event 对象的完整属性列表,请尝试运行more $GITHUB_EVENT_PATH

    【讨论】:

      【解决方案2】:
      1. 当您需要表达式中的数据时 (Source):
      Property name Type Description
      github.base_ref string The base_ref or target branch of the pull request in a workflow run. This property is only available when the event that triggers a workflow run is a pull_request.
      github.head_ref string The head_ref or source branch of the pull request in a workflow run. This property is only available when the event that triggers a workflow run is a pull_request.

      一个例子(修改自the documentation):

      steps:
        - uses: actions/hello-world-javascript-action@v1.1
          if: ${{ github.base_ref == 'main' }}
      

      1. 当您需要数据作为环境变量时 (Source):
      Environment variable Description
      GITHUB_HEAD_REF Only set for pull request events. The name of the head branch.
      GITHUB_BASE_REF Only set for pull request events. The name of the base branch.

      一个例子(修改自the documentation):

      steps:
        - name: Hello world
          run: echo Hello world from $GITHUB_HEAD_REF!
      

      【讨论】:

        【解决方案3】:

        您可以看到所有 GitHub 操作拉取请求事件属性here

        【讨论】:

          猜你喜欢
          • 2023-02-24
          • 2013-12-31
          • 2020-03-23
          • 2014-11-30
          • 1970-01-01
          • 2022-06-21
          • 2013-02-12
          • 2013-04-24
          • 2020-01-21
          相关资源
          最近更新 更多