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

Error: Not Found when trying to create a PR to a sparse-cloned repo. #652

Closed
ndac-todoroki opened this issue Dec 2, 2020 · 9 comments
Closed

Comments

@ndac-todoroki
Copy link

ndac-todoroki commented Dec 2, 2020

Possible related to #634, but not sure if the background is the same.

Subject of the issue

I'm not using the actions/checkout@v2 to clone the target repository, since it is huge (actions/checkout refuses to clone).
I sparseCheckout that repo, made changes to a certain directory.

create-pull-request crashes after successfully updating/creating a new branch to the remote.
image

Steps to reproduce

The checkout part is:

- name: Sparse checkout target
  shell: bash
  env:
    GITHUB_TOKEN: '${{ secrets.TOKEN }}'
    TARGET_REPOSITORY: foo/bar
    TARGET_BRANCH: ${{ steps.get-target-ref.outputs.target_ref }}  # target branch to open PR
    CLONE_DIR: .github/repositories/bar
    TARGET_DIRECTORY: "directory/to/sparse/checkout"
  run: |
    REPO="https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${TARGET_REPOSITORY}.git"
    BRANCH="${GITHUB_REF/#refs\/heads\//}"
    # Following code is based on logs of actions/checkout@v, with sparseCheckout stuff inserted in the middle
    echo "Syncing repository: $TARGET_REPOSITORY"
    echo "Working directory is '$(pwd)' GITHUB_WORKSPACE=$GITHUB_WORKSPACE BRANCH=$TARGET_BRANCH"
    git version
    git clone $REPO \
        --single-branch --branch $TARGET_BRANCH \
        --depth 1 \
        --sparse \
        --filter=blob:none \
        $GITHUB_WORKSPACE/$CLONE_DIR
    cd $GITHUB_WORKSPACE/$CLONE_DIR
    git config --local gc.auto 0
    git sparse-checkout add $TARGET_DIRECTORY
    echo $(/usr/bin/git config --local --get remote.origin.url) 

Then create-pull-request:

# Creates a PR according to the given target
- name: Create PR
  uses: peter-evans/create-pull-request@v3
  with:
    token: ${{ secrets.TOKEN }}
    commit-message: "CI did foo and bar"
    title: "TITLE"
    branch: auto-generated/${{ steps.get-pr-info.outputs.head_ref }}
    body: |
      BODY BODY
    path: .github/repositories/bar

Sorry this is a private repo and cannot paste the exact thing, but only the strings are edited.
sparse-checkout works correctly, and push is working too.

I wanted to look at the sources, but wasn't able to tell where the Not Found error message comes from :(

@peter-evans
Copy link
Owner

Hi @ndac-todoroki

"Not Found" is a 404 response returned from GitHub's API and I think occurs here: https://github.com/peter-evans/create-pull-request/blob/master/src/github-helper.ts#L64

That would indicate that this is an authentication problem, or the repository being targeted is incorrect.

In the log there should be line that says Pull request branch target repository set to <repository>. Is the repository correct? Is the branch being created in the correct repository? If so, it's probably an auth issue.

Double check the following for your secrets.TOKEN secret:

  • The secret TOKEN has been set in the repository secrets settings
  • The secret TOKEN is a PAT with repo scope
  • The PAT has been created on a user that has write access to the target repository

@raffaelespazzoli
Copy link

raffaelespazzoli commented Dec 8, 2020

@peter-evans I'm getting the same error:
here is the section with the error:

Pushing pull request branch to 'fork/volume-expander-operator-0.1.3'
  /usr/bin/git push --force-with-lease fork HEAD:refs/heads/volume-expander-operator-0.1.3
  To https://github.com/redhat-cop/community-operators
   + d51a1ca9...e8b8cd59 HEAD -> volume-expander-operator-0.1.3 (forced update)
Error: Not Found

here is the section you suggested we check

Pull request branch to create or update set to 'volume-expander-operator-0.1.3'

which looks good to me.
My code is public in case you want to review: https://github.com/redhat-cop/volume-expander-operator
This code used to work, the error started to appear when the target repo added a github actions-based workflow (before they were on travis).
The PAT used for the push has the following permissions:
image

@peter-evans
Copy link
Owner

peter-evans commented Dec 8, 2020

@raffaelespazzoli That does look like the same error. Thank you for providing details.

This code used to work, the error started to appear when the target repo added a github actions-based workflow (before they were on travis).

That seems unlikely to be the cause. The branch itself was actually pushed to the remote successfully. You can find it here:
https://github.com/redhat-cop/community-operators/tree/volume-expander-operator-0.1.3

If possible, could you try re-running the workflow for the same 0.1.3 tag to check whether or not this is just a transient error when calling the GitHub API. If that doesn't work, to recover from this error in the meantime you could manually create the pull request using the above branch. I'll investigate and try and figure out what the cause of this is.

@peter-evans
Copy link
Owner

@ndac-todoroki @raffaelespazzoli I believe I've identified how this error is occurring. The error was confusing because of a small mistake I made in error handling. I've fixed the mistake in version v3.5.2 / v3. While this won't fix the issue, it should hopefully show us the correct error message for the cause. My guess is that this is a transient error when calling the GitHub API and I might need to add retry logic. Please let me know if you experience further error messages.

@raffaelespazzoli
Copy link

I tested again and it worked for me this time, however the target PR had been closed in the meantime, so I am not sure if I am testing in the same exact conditions as before. Anyway the push worked. Thanks for the prompt fix.

@peter-evans
Copy link
Owner

@ndac-todoroki @raffaelespazzoli I'll close this issue for now, but if you have any further problems please let me know.

@JavierSegoviaCordoba
Copy link

JavierSegoviaCordoba commented Apr 27, 2021

I am having this issue, the PR is not created but the branch is created and pushed.


// ...

on:
  push:
    tags:
      - '**'

// ...

      - name: Create Pull Request
        uses: peter-evans/create-pull-request@v3
        with:
          token: ${{ secrets.TOKEN_GITHUB_ACTION }}
          base: main
          commit-message: "Bump internal Massive Catalogs version to ${{ steps.tags.outputs.version }}"
          title: "Bump internal Massive Catalogs version to ${{ steps.tags.outputs.version }}"
          branch: "bump-internal-massive-catalogs-version-to-${{ steps.tags.outputs.version }}"

I need to run it when a tag is pushed, exclusively. In the same project, I am using your action with no issues in a workflow_dispatch workflow.

I tried multiple times, and it fails

@peter-evans
Copy link
Owner

Hi @JavierSegoviaCordoba

I found the log where it returns Error: Not Found.
https://github.com/JavierSegoviaCordoba/massive-catalogs/runs/2448348790?check_suite_focus=true

The branch was pushed, so I think your token permissions are fine. The only explanation I can think of is that this is a transient error when calling the GitHub API, or some temporary problem on GitHub's side. It would be very helpful if you could test it again to see if it no longer returns an error.

I think I will try to add retry logic to the API calls to try and catch these errors.

@peter-evans
Copy link
Owner

In the latest version, v3.9.2, I've improved the log output during create/update of pull requests via the GitHub API. Hopefully this will help confirm which API is causing this issue. Please let me know if you run into this issue again.

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

4 participants