【发布时间】:2020-10-01 12:52:16
【问题描述】:
当在 Github Actions 中的pull_request 上设置动作时,如何获取目标分支?用例是检索特定于 PR(并且希望是分支)的提交。
【问题讨论】:
标签: continuous-integration github-actions
当在 Github Actions 中的pull_request 上设置动作时,如何获取目标分支?用例是检索特定于 PR(并且希望是分支)的提交。
【问题讨论】:
标签: continuous-integration github-actions
您可以使用${{ github.event.pull_request.base.ref }} 访问目标分支。
要了解github.event 对象的完整属性列表,请尝试运行more $GITHUB_EVENT_PATH。
【讨论】:
| 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' }}
| 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!
【讨论】:
您可以看到所有 GitHub 操作拉取请求事件属性here。
【讨论】: