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

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
i'll play around with this, i think i might know a way.
if you have the on: syntax handy, please provide
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 }}
@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
@ericsciple I got an issue when using goveralls, https://github.com/mattn/goveralls/issues/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?
Most helpful comment
@luludan v2 happens to fix the issue you were hitting. V2 fetches the specific SHA rather than the ref.
This just works: