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

How to checkout current PR branch? #1108

Open
wolf99 opened this issue Jan 13, 2023 · 4 comments
Open

How to checkout current PR branch? #1108

wolf99 opened this issue Jan 13, 2023 · 4 comments

Comments

@wolf99
Copy link

wolf99 commented Jan 13, 2023

I am trying to create a PR workflow that checkouts out the PR branch, lints the markdown, and then makes a commit with the changes (on PR: google/osv-scanner#144).

This is running on the PR branch that is introducing this workflow, which is coming from my fork of this repo.

I am not understanding how to properly checkout the PR branch.

Looking at #20, and the docs for the Prettier action I am using for linting, it seems I should just

- uses: actions/checkout
  with:
    ref: ${{ github.ref }}

But using this causes checkout to fail, see job: https://github.com/google/osv-scanner/actions/runs/3914565858/jobs/6691777605

Fetching the repository
  /usr/bin/git -c protocol.version=2 fetch --no-tags --prune --progress --no-recurse-submodules --depth=1 origin +refs/heads/prettier-lint-md-workflow*:refs/remotes/origin/prettier-lint-md-workflow* +refs/tags/prettier-lint-md-workflow*:refs/tags/prettier-lint-md-workflow*
  The process '/usr/bin/git' failed with exit code 1
  Waiting 13 seconds before trying again
  /usr/bin/git -c protocol.version=2 fetch --no-tags --prune --progress --no-recurse-submodules --depth=1 origin +refs/heads/prettier-lint-md-workflow*:refs/remotes/origin/prettier-lint-md-workflow* +refs/tags/prettier-lint-md-workflow*:refs/tags/prettier-lint-md-workflow*
  The process '/usr/bin/git' failed with exit code 1
  Waiting 15 seconds before trying again
  /usr/bin/git -c protocol.version=2 fetch --no-tags --prune --progress --no-recurse-submodules --depth=1 origin +refs/heads/prettier-lint-md-workflow*:refs/remotes/origin/prettier-lint-md-workflow* +refs/tags/prettier-lint-md-workflow*:refs/tags/prettier-lint-md-workflow*
  Error: The process '/usr/bin/git' failed with exit code 1

My git-fu 🥷 isn't strong enough to figure out what is wrong here

@wolf99
Copy link
Author

wolf99 commented Jan 13, 2023

Added fetch-depth: 0 so in total:

- uses: actions/checkout
  with:
    ref: ${{ github.ref }}
    fetch-depth: 0

Now the checkout gets slightly further but results in:

Determining the checkout info
  /usr/bin/git branch --list --remote origin/prettier-lint-md-workflow
  /usr/bin/git tag --list prettier-lint-md-workflow
  Error: A branch or tag with the name 'prettier-lint-md-workflow' could not be found

https://github.com/google/osv-scanner/actions/runs/3914653689/jobs/6691959309

@wolf99
Copy link
Author

wolf99 commented Jan 13, 2023

Tried ref: ${{ github.event.pull_request.head.sha }} instead, but then the Prettier action is back to:

fatal: You are not currently on a branch.
To push the history leading to the current (detached HEAD)
state now, use

    git push origin HEAD:<name-of-remote-branch>

😟

@0ptim
Copy link

0ptim commented Feb 6, 2023

I think you need to use this: ref: ${{ github.head_ref }}.


Just found your issue because I have the following error when someone makes a PR from a cloned repo.

A branch or tag with the name 'some_branch_name' could not be found

I'm actually also using Prettier. I have this config.

name: Pull Request Check

on:
  pull_request:
    branches:
      - main

jobs:
  prettier:
    name: Format files using Prettier
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          ref: ${{ github.head_ref }}
          fetch-depth: 0

      - name: Prettify code
        uses: creyD/prettier_action@v4.2
        with:
          dry: True
          only_changed: True
          prettier_options: --check **/*.{js,css,md} --end-of-line lf

Maybe our problem is related. This is the run which fails: https://github.com/0ptim/DeFiChainWiki/actions/runs/4108092834/jobs/7088370243

@0ptim
Copy link

0ptim commented Feb 6, 2023

Just got it working! 🎉
Have a look here: #455

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