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 not checking out to PR branch #1325

Open
Lucasmiguelmac opened this issue May 16, 2023 · 1 comment
Open

Checkout not checking out to PR branch #1325

Lucasmiguelmac opened this issue May 16, 2023 · 1 comment

Comments

@Lucasmiguelmac
Copy link

Lucasmiguelmac commented May 16, 2023

Let's say I have a dev target branch and I want to set up a GH Action .yml file to run on every PR.

The first step,that is, the actions/checkout@v2 step, is no longer doing what it's supposed to. Which would be: checking out to the branch I'm wanting to merge.

name: Run tests
on:
  pull_request:
    types: [opened, reopened, synchronize]
jobs:
  trigger-job:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout 
        uses: actions/checkout@v2
      - name: Print current branch
        run: echo "$(git branch)" # --> echoes "(HEAD detached at pull/<pr-number>/merge)"

For demonstration purposes:

  1. I attach a side by side comparisson of the same pipeline run with a 4 days difference
    image
  2. I tried the same on another non related GH user and had the same error

Why is that? The same Print current branch step would print the actual name of the branch I'm trying to merge into dev a couple of days ago, but not anymore

@bangank36
Copy link

@Lucasmiguelmac by default the input ref will point to single commit
Setting fetch-depth: 0 can help pull all history and tags but it is not recommended if you have a large repo, therefore you can set the ref input like so to checkout the correct branch

name: Run tests
on:
  pull_request:
    types: [opened, reopened, synchronize]
jobs:
  trigger-job:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout 
        uses: actions/checkout@v2
        with: 
+               ref: ${{ github.head_ref }}
      - name: Print current branch
        run: echo "$(git branch)" # --> echoes "(HEAD detached at pull/<pr-number>/merge)"

You can see my action log that the correct branch has been checked out
image

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

No branches or pull requests

2 participants