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

git checkout invalid reference on existing PR #1073

Closed
jault-figure opened this issue Feb 25, 2022 · 3 comments
Closed

git checkout invalid reference on existing PR #1073

jault-figure opened this issue Feb 25, 2022 · 3 comments

Comments

@jault-figure
Copy link

Subject of the issue

I'm running into an error using this action in the Create or update the pull request branch step:

Pull request branch 'jault-figure/cpr-demo' already exists as remote branch 'origin/jault-figure/cpr-demo'
[83](https://github.com/jault-figure/cpr-demo/runs/5339446475?check_suite_focus=true#step:6:83)
  /usr/bin/git checkout --progress jault-figure/cpr-demo --
[84](https://github.com/jault-figure/cpr-demo/runs/5339446475?check_suite_focus=true#step:6:84)
  fatal: invalid reference: jault-figure/cpr-demo
[85](https://github.com/jault-figure/cpr-demo/runs/5339446475?check_suite_focus=true#step:6:85)
  Error: The process '/usr/bin/git' failed with exit code 128

This error only occurs if the action runs more than one time and the pull request is still open.

I originally saw this error on a private repo that is part of a gitops deploy pipeline. In my case, there are two repos: the application repo and the manifests repo. The application repo contains app source code and the manifests repo holds all the Kubernetes yaml files that ArgoCD automatically deploys when it hits the main branch.

The goal with using this action was to automatically open a pull request on the manifests repo whenever a commit was made to the main branch on the app repo. The yaml files would be auto generated in the app repo's workflow, and then a PR would be created on the manifests repo to add/update them. Since I don't necessarily want to deploy all changes immediately when they hit the main branch on the app repo, there may be more commits to that pull request after it's opened. Based on this action's docs:

The default behaviour of the action is to create a pull request that will be continually updated with new changes until it is merged or closed.

I assumed this would work, but I may be doing something incorrectly.

Steps to reproduce

Because the original repo I saw this error on is private, I've created a repo to demo the error here https://github.com/jault-figure/cpr-demo. The 2nd action run successfully created the pull request (https://github.com/jault-figure/cpr-demo/actions/runs/1900807797). The pull requests is here jault-figure/cpr-target#1

The 3rd action run was triggered by another commit to the app repo, but failed to update the existing pull request (https://github.com/jault-figure/cpr-demo/actions/runs/1900811622)

Just a quick note about this line https://github.com/jault-figure/cpr-demo/blob/main/.github/workflows/build.yaml#L13: In the original private repo where I saw this error, I'm using this create-pull-request action as part of a private composite action. Composite actions don't support post steps, so I have to run a clone manually instead of using the checkout action. Although, I think the checkout action does a shallow clone anyways, so I believe it's equivalent.

Any help would be appreciated!

@peter-evans
Copy link
Owner

Hi @jault-figure

What you want to do is definitely doable with this action, but I'm a bit confused by the demo implementation.

The goal with using this action was to automatically open a pull request on the manifests repo whenever a commit was made to the main branch on the app repo.

Just going off this as a description of what you want to do, here is a rough outline of how it should work.
This workflow needs to run in the app repo on push to the main branch.

      # Checkout app-repo to a different path from the default
      - uses: actions/checkout@v2
         with:
           path: app-repo

      # Checkout the manifiest repo on the base (target) of the pull request
      - uses: actions/checkout@v2
         with:
           repository: my-org/manifests-repo
           ref: main

      # Make changes to pull request here
      # Copy files from `app-repo` path to here
      # Alternatively, use upload-artifact/download-artifact actions to get the files you want copied here

      - name: Create Pull Request
        uses: peter-evans/create-pull-request@v3
        with:
          token: (use a PAT here that has write access to the manifests-repo)

@jault-figure
Copy link
Author

Hi @peter-evans , thanks for getting back to me. I did try and clear up that demo repo and removed a lot of the variables so it should be easier to read now. It essentially mirrors your example above, without using the checkout action twice.

It looks like I still get the error even with that. Any ideas what I might be doing wrong?

@jault-figure
Copy link
Author

I think I figured this one out today. It looks like you can't do a clone with a depth of 1. I didn't dig in too much further, but I would guess it's because --depth 1 assumes --single-branch on the clone. Without pulling down the remote branch that's being updated, this action throws the error above. It is a little bit confusing because the public actions/checkout action does default to a fetch depth of 1, so I'm not entirely sure why using that would work. Unless they explicitly override the --single-branch flag on the clone.

But either way, I can close this out.

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