Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checkout on pull_request -> closed event #45

Closed
luludan opened this issue Sep 24, 2019 · 6 comments · Fixed by #112
Closed

Checkout on pull_request -> closed event #45

luludan opened this issue Sep 24, 2019 · 6 comments · Fixed by #112
Assignees
Labels
documentation Improvements or additions to documentation

Comments

@luludan
Copy link

luludan commented Sep 24, 2019

Is there a way to checkout the code of a PR when closing the PR?

We are spinning up an environment per PR and need some config from the repo to help tear it down when closing the PR.

Currently it tries to checkout the branch based off the special github pr branch

image

@fsilva3
Copy link

fsilva3 commented Sep 26, 2019

hi @luludan try to use another ref, by default, actions/checkout uses ${{ github.ref }} which referes to something like: refs/pull/#/merge

an example, referencing another ref:

- uses: actions/checkout@v1
  with:
    ref: refs/heads/${{ github.head_ref }} # it could be ${{ github.base_ref }} also

@ericsciple
Copy link
Contributor

i'll play around with this, i think i might know a way.

if you have the on: syntax handy, please provide

@ericsciple ericsciple added the documentation Improvements or additions to documentation label Dec 13, 2019
@fsilva3
Copy link

fsilva3 commented Dec 13, 2019

hi @ericsciple thanks for your support,

here is a sample of .yml:

name: Build

on:
  pull_request:
    branches:
    - master
    types: [opened, synchronize, closed]

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
    - name: Git Checkout PR Ref
      if: github.event.action != 'closed'
      uses: actions/checkout@v1

    - name: Git Checkout Base Ref
      if: github.event.pull_request.merged == true
      uses: actions/checkout@v1
      with:
        ref: refs/heads/${{ github.base_ref }}

@ericsciple
Copy link
Contributor

@luludan v2 happens to fix the issue you were hitting. V2 fetches the specific SHA rather than the ref.

This just works:

on:
  pull_request:
    branches:
    - master
    types: [opened, synchronize, closed]
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

@fezho
Copy link

fezho commented Jan 10, 2020

@ericsciple I got an issue when using goveralls, mattn/goveralls#150
And I think it's because checkout fetches the specific SHA rather than the ref, however goveralls gets the wrong sha:

	if os.Getenv("GITHUB_EVENT_NAME") == "pull_request" {
		ghPR := getGithubEvent()["pull_request"].(map[string]interface{})
		ghHead := ghPR["head"].(map[string]interface{})
		commitRef = ghHead["sha"].(string)
	}

This can be fixed by using ref: ${{ github.event.pull_request.head.sha }}, but i do not want to use it when push to master. Any advice to fix this issue?

@Gopikrishna19
Copy link

@fezho you can add event check:

    steps:
      - uses: actions/checkout@v2
        name: Checkout PR
        if: github.event_name == 'pull_request'
        with:
          ref: ${{ github.event.pull_request.head.sha }}

      - uses: actions/checkout@v2
        name: Checkout Branch
        if: github.event_name == 'push'

When in pull request
On PR

When in a branch
On Branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants
@fsilva3 @Gopikrishna19 @ericsciple @luludan @fezho and others