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

Fix Backmerge PR action #587

Merged
merged 6 commits into from
Sep 3, 2024
Merged

Fix Backmerge PR action #587

merged 6 commits into from
Sep 3, 2024

Conversation

iangmaia
Copy link
Contributor

@iangmaia iangmaia commented Sep 2, 2024

What does it do?

We have noticed the error below while creating a backmerge to a hotfix branch:

Error creating backmerge pull request: git '--git-dir=<...>/.git' '--work-tree=/<...>' '-c' 'core.quotePath=true' '-c' 'color.ui=false' 'rev-parse' 'release/<HOTFIX VERSION>'  2>&1
status: pid 11499 exit 128
output: "fatal: ambiguous argument 'release/<HOTFIX VERSION>': unknown revision or path not in the working tree.\nUse '--' to separate paths from revisions, like this:\n'git <command> [<revision>...] -- [<file>...]'\nrelease/<HOTFIX VERSION>

Meaning that the given branch release/<HOTFIX VERSION> isn't present locally and only in origin. From inspecting the code and logs, this error most likely happened in the method GitHelper.point_to_same_commit?, called in the line 106 of the action create_release_backmerge_pull_request_action.

This PRs uses origin/ to compare the refs and some safety net to point_to_same_commit?.

Checklist before requesting a review

  • Run bundle exec rubocop to test for code style violations and recommendations
  • Add Unit Tests (aka specs/*_spec.rb) if applicable
  • Run bundle exec rspec to run the whole test suite and ensure all your tests pass
  • Make sure you added an entry in the CHANGELOG.md file to describe your changes under the appropriate existing ### subsection of the existing ## Trunk section.
  • If applicable, add an entry in the MIGRATION.md file to describe how the changes will affect the migration from the previous major version and what the clients will need to change and consider.

@iangmaia iangmaia added the bug Something isn't working label Sep 2, 2024
@iangmaia iangmaia self-assigned this Sep 2, 2024
@dangermattic
Copy link
Collaborator

dangermattic commented Sep 2, 2024

1 Warning
⚠️ PR is not assigned to a milestone.

Generated by 🚫 Danger

@iangmaia iangmaia marked this pull request as ready for review September 2, 2024 12:52
@iangmaia iangmaia requested review from AliSoftware and a team September 2, 2024 12:52
Copy link
Contributor

@AliSoftware AliSoftware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be worth testing this in real world in a dummy repo (maybe release-toolkit-demo, which was created a while ago mostly for such testing purposes…?), e.g. creating a release/12.4 branch and a release/12.3 branch then running that action with source_branch:'release/12.3' and no target_branches)

@iangmaia
Copy link
Contributor Author

iangmaia commented Sep 2, 2024

@AliSoftware

Would be worth testing this in real world in a dummy repo (maybe release-toolkit-demo, which was created a while ago mostly for such testing purposes…?), e.g. creating a release/12.4 branch and a release/12.3 branch then running that action with source_branch:'release/12.3' and no target_branches)

I've ran some tests, and unfortunately, fetching origin didn't really fix the issue, so we had to use origin/ when comparing refs. I've updated the code on 332e9f8, and this worked fine. I've also removed the origin fetch (17eb938) as it seems redundant in the end.

ref1_commit = git_repo.gcommit(ref1)
ref2_commit = git_repo.gcommit(ref2)
rescue StandardError => e
puts "Error: #{e.message}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of:

Suggested change
puts "Error: #{e.message}"
UI.error "Error fetching commits for #{ref1} and #{ref2}: #{e.message}"

Actually, those are two different suggestions:

  • Use UI.error instead of puts
  • Include the attempted operation in the error message

@@ -39,7 +39,7 @@ def stub_expected_pull_requests(expected_backmerge_branches:, source_branch:, la

next if branch_exists_on_remote

allow(Fastlane::Helper::GitHelper).to receive(:point_to_same_commit?).with(target_branch, source_branch).and_return(point_to_same_commit)
allow(Fastlane::Helper::GitHelper).to receive(:point_to_same_commit?).with("origin/#{target_branch}", "origin/#{source_branch}").and_return(point_to_same_commit)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to this particular line, but I wonder if it would be worth adding a test to ensure that if we pass branches that already have "origin/" in the name, our logic doesn't append an additional "origin/" to them.

@mokagio
Copy link
Contributor

mokagio commented Sep 3, 2024

@iangmaia I'll take over merging this already approved PR so that I can update the changelog etc. of my removal PR #580 on top of this. Thanks!

@mokagio mokagio merged commit b6eb427 into trunk Sep 3, 2024
3 of 5 checks passed
@mokagio mokagio deleted the iangmaia/fix-backmerge-pr branch September 3, 2024 01:38
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 this pull request may close these issues.

4 participants