How to get the target branch of the GitHub pull request from an Actions?

前端 未结 3 1773
隐瞒了意图╮
隐瞒了意图╮ 2021-01-20 14:56

When an action is set on pull_request in Github Actions, how to get the target branch? The use case is to retrieve the PR- (and hopefully, branch)-specific comm

3条回答
  •  天命终不由人
    2021-01-20 15:38

    1. When you need the data in expressions (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.

    An example (modified from the documentation):

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

    1. When you need the data as environment variables (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.

    An example (modified from the documentation):

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

提交回复
热议问题