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

[BUG] Locate the merge-base of a PR branch instead of a relying on the fetch-depth. #704

Closed
3 tasks done
lpulley opened this issue Oct 20, 2022 · 8 comments · Fixed by #709
Closed
3 tasks done

[BUG] Locate the merge-base of a PR branch instead of a relying on the fetch-depth. #704

lpulley opened this issue Oct 20, 2022 · 8 comments · Fixed by #709
Labels
bug Something isn't working

Comments

@lpulley
Copy link
Contributor

lpulley commented Oct 20, 2022

Is there an existing issue for this?

  • I have searched the existing issues

Does this issue exist in the latest version?

  • I'm using the latest release

Describe the bug?

We tried fetch-depth: 0, but it was too slow in our large repository. fetch-depth: 2 usually works, but occasionally changed-files seems to be determining the wrong GITHUB_EVENT_PULL_REQUEST_BASE_SHA.

To Reproduce

We're encountering this issue on a private repository. What I can say is that in this case, I have a developer who branched from the main branch, did work, committed a few commits, and created a PR. In the meantime, the main branch had some commits merged into it. Business as usual.

All the previous changed-files jobs in this PR worked fine, but the most recent one didn't. Its GITHUB_EVENT_PULL_REQUEST_BASE_SHA seems to be wrong -- the GitHub merge commit that the job ran on has a parent that is a descendant of GITHUB_EVENT_PULL_REQUEST_BASE_SHA.

We check out 746c624:

image
image

whose main branch parent is df0d28b:

image

and for some reason changed-files is expecting to find df0d28b's ancestor e7b29ba:

image

but it can't, so it complains that we haven't fetched deeply enough:

image

What OS are you seeing the problem on?

all

Expected behavior?

I expect fetch-depth: 2 to work as it usually does. I also would expect GITHUB_EVENT_PULL_REQUEST_BASE_SHA to be the parent of the check merge commit, and not some older ancestor of it.

Relevant log output

No response

Anything else?

Git version is 2.38.1. Runner is our own (self-hosted).

Code of Conduct

  • I agree to follow this project's Code of Conduct
@lpulley lpulley added the bug Something isn't working label Oct 20, 2022
@github-actions
Copy link
Contributor

Thanks for reporting this issue, don't forget to star this project if you haven't already to help us reach a wider audience.

@jackton1
Copy link
Member

jackton1 commented Oct 21, 2022

@lpulley Given that this is an expected behaviour I’ll recommend you take a look at https://github.com/orgs/community/discussions/25437#discussioncomment-3247910

You can also increase the depth of the base branch history that is pulled by using the target_branch_fetch_depth input.

See inputs for more information.

@jackton1 jackton1 closed this as not planned Won't fix, can't repro, duplicate, stale Oct 21, 2022
@lpulley
Copy link
Contributor Author

lpulley commented Oct 21, 2022

I understand how the GitHub merge commits work and that they are not entirely up to date with the target branch if the target branch moves after the PR has been synchronized. I get that.

My problem is that changed-files is occasionally (but not most of the time, apparently) expecting that some arbitrary (to me) ancestor of the GitHub merge commit is checked out already, when it is not -- fetch-depth: 2 fetches the GitHub merge commit and its parents, from which changed-files usually does some more checkouts, figures out the merge base, and provides the changed files.

The reason I believe this is a bug is that in the case I outlined above, changed-files is failing with fetch-depth: 2 because it is expecting to already have a commit that is not one of the commits that would be checked out with fetch-depth: 2. Doesn't that seem like a problem?

@lpulley
Copy link
Contributor Author

lpulley commented Oct 21, 2022

Are you saying that this is happening because it's giving up after fetching 20 commits back by default?

@lpulley
Copy link
Contributor Author

lpulley commented Oct 21, 2022

@jackton1 is there a reason why changed-files doesn't just git fetch --deepen until the merge base is found? That way, this would never just fail.

@jackton1
Copy link
Member

Are you saying that this is happening because it's giving up after fetching 20 commits back by default?

Yes

@jackton1
Copy link
Member

jackton1 commented Oct 21, 2022

@jackton1 is there a reason why changed-files doesn't just git fetch --deepen until the merge base is found? That way, this would never just fail.

You can increase the number i.e target_branch_fetch_depth: 100for now. I'll take a stab at implementing it this weekend.

@jackton1 jackton1 reopened this Oct 21, 2022
@jackton1 jackton1 changed the title [BUG] GITHUB_EVENT_PULL_REQUEST_BASE_SHA isn't actually the head of the base branch, and fetch-depth: 2 fails [BUG] Locate the merge base of a PR branch instead of a generic fetch-depth. Oct 21, 2022
@jackton1 jackton1 changed the title [BUG] Locate the merge base of a PR branch instead of a generic fetch-depth. [BUG] Locate the merge-base of a PR branch instead of a relying on the fetch-depth. Oct 21, 2022
ericLemanissier added a commit to ericLemanissier/conan-center-index that referenced this issue Oct 25, 2022
@jackton1 jackton1 linked a pull request Oct 25, 2022 that will close this issue
@jackton1
Copy link
Member

jackton1 commented Oct 25, 2022

@lpulley @ericLemanissier This should now be available in the latest release.

prince-chrismc pushed a commit to prince-chrismc/conan-center-index that referenced this issue Nov 16, 2022
* github actions: don't use tj-actions/changed-files

avoids all its bugs alltogether
eg tj-actions/changed-files#704

* fix forks

* add github token

* don't use PurePath.is_relative_to

* fixup

* add yml error

* add conanfile.py error

* add test error

* touch linter

* use fnmatch

* fxup

* use a dedicated action

* Update config.yml

* Update conanfile.py

* Update conanfile.py

* Update conanv2_transition.py

Co-authored-by: ericLemanissier <ericLemanissier@users.noreply.github.com>
conan-center-bot pushed a commit to conan-io/conan-center-index that referenced this issue Nov 23, 2022
* github actions: don't use tj-actions/changed-files

avoids all its bugs alltogether
eg tj-actions/changed-files#704

* fix forks

* add github token

* don't use PurePath.is_relative_to

* fixup

* add yml error

* add conanfile.py error

* add test error

* touch linter

* use fnmatch

* fxup

* use a dedicated action

* Update config.yml

* Update conanfile.py

* Update conanfile.py

* Update conanv2_transition.py

* improve file matching

python's fnmatch treats * as any character any number oftime, including /.
This is not coherent with bash, which excludes / from *.
The fix is to split the pattern and filenames by / and call fnmatch
on each part.

* add a test error

* fixup

* silence warning

* Update conanfile.py

Co-authored-by: Chris Mc <prince.chrismc@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants