hrvey / combine-prs-workflow

Combine/group together PRs (for example from Dependabot and similar services)
https://www.hrvey.com/blog/combine-dependabot-prs
MIT License
296 stars 51 forks source link

Should not be doing an octopus. #2

Closed joshuafredrickson closed 2 years ago

joshuafredrickson commented 3 years ago

I love the idea of this, however I receive the following error:

ERROR: content conflict in site/composer.lock
fatal: merge program failed
Automated merge did not work.
Should not be doing an octopus.
Merge with strategy octopus failed.
Error: Process completed with exit code 2.

I'm using it with dependabot PRs, status set to false on the combine-prs-branch branch.

Frequently when I merge multiple dependabot PRs in a row, I have to wait for subsequent PRs to rebase before I can proceed with the next. I'm thinking that's somehow related.

Here's the full output:

Run echo ""dependabot/composer/site/wpackagist-plugin/jetpack-9.0.1 dependabot/composer/site/satispress/woocommerce-subscriptions-3.0.9 dependabot/composer/site/wpackagist-plugin/woo-discount-rules-2.2.2 dependabot/composer/site/wpackagist-plugin/woocommerce-delivery-notes-4.6.0 dependabot/composer/site/wpackagist-plugin/event-tickets-5.0.1 dependabot/composer/site/wpackagist-plugin/user-switching-1.5.6 dependabot/composer/site/wpackagist-plugin/duplicate-post-3.2.6 dependabot/composer/site/wpackagist-plugin/wp-mail-smtp-2.4.0 dependabot/composer/site/wpackagist-plugin/woocommerce-services-1.24.3 dependabot/composer/site/wpackagist-plugin/woocommerce-4.5.2""
  echo ""dependabot/composer/site/wpackagist-plugin/jetpack-9.0.1 dependabot/composer/site/satispress/woocommerce-subscriptions-3.0.9 dependabot/composer/site/wpackagist-plugin/woo-discount-rules-2.2.2 dependabot/composer/site/wpackagist-plugin/woocommerce-delivery-notes-4.6.0 dependabot/composer/site/wpackagist-plugin/event-tickets-5.0.1 dependabot/composer/site/wpackagist-plugin/user-switching-1.5.6 dependabot/composer/site/wpackagist-plugin/duplicate-post-3.2.6 dependabot/composer/site/wpackagist-plugin/wp-mail-smtp-2.4.0 dependabot/composer/site/wpackagist-plugin/woocommerce-services-1.24.3 dependabot/composer/site/wpackagist-plugin/woocommerce-4.5.2""
  sourcebranches="${BRANCHES_TO_COMBINE%\"}"
  sourcebranches="${sourcebranches#\"}"

  basebranch="${BASE_BRANCH%\"}"
  basebranch="${basebranch#\"}"

  git config pull.rebase false
  git config user.name github-actions
  git config user.email github-actions@github.com

  git branch $COMBINE_BRANCH_NAME $basebranch
  git checkout $COMBINE_BRANCH_NAME
  git pull origin $sourcebranches --no-edit
  git push origin $COMBINE_BRANCH_NAME
  shell: /bin/bash -e {0}
  env:
    BASE_BRANCH: master
    BRANCHES_TO_COMBINE: "dependabot/composer/site/wpackagist-plugin/jetpack-9.0.1 dependabot/composer/site/satispress/woocommerce-subscriptions-3.0.9 dependabot/composer/site/wpackagist-plugin/woo-discount-rules-2.2.2 dependabot/composer/site/wpackagist-plugin/woocommerce-delivery-notes-4.6.0 dependabot/composer/site/wpackagist-plugin/event-tickets-5.0.1 dependabot/composer/site/wpackagist-plugin/user-switching-1.5.6 dependabot/composer/site/wpackagist-plugin/duplicate-post-3.2.6 dependabot/composer/site/wpackagist-plugin/wp-mail-smtp-2.4.0 dependabot/composer/site/wpackagist-plugin/woocommerce-services-1.24.3 dependabot/composer/site/wpackagist-plugin/woocommerce-4.5.2"
    COMBINE_BRANCH_NAME: combine-prs-branch
dependabot/composer/site/wpackagist-plugin/jetpack-9.0.1 dependabot/composer/site/satispress/woocommerce-subscriptions-3.0.9 dependabot/composer/site/wpackagist-plugin/woo-discount-rules-2.2.2 dependabot/composer/site/wpackagist-plugin/woocommerce-delivery-notes-4.6.0 dependabot/composer/site/wpackagist-plugin/event-tickets-5.0.1 dependabot/composer/site/wpackagist-plugin/user-switching-1.5.6 dependabot/composer/site/wpackagist-plugin/duplicate-post-3.2.6 dependabot/composer/site/wpackagist-plugin/wp-mail-smtp-2.4.0 dependabot/composer/site/wpackagist-plugin/woocommerce-services-1.24.3 dependabot/composer/site/wpackagist-plugin/woocommerce-4.5.2
Switched to branch 'combine-prs-branch'
From https://github.com/Scout-Branding/skin-wellness
 * branch              dependabot/composer/site/wpackagist-plugin/jetpack-9.0.1 -> FETCH_HEAD
 * branch              dependabot/composer/site/satispress/woocommerce-subscriptions-3.0.9 -> FETCH_HEAD
 * branch              dependabot/composer/site/wpackagist-plugin/woo-discount-rules-2.2.2 -> FETCH_HEAD
 * branch              dependabot/composer/site/wpackagist-plugin/woocommerce-delivery-notes-4.6.0 -> FETCH_HEAD
 * branch              dependabot/composer/site/wpackagist-plugin/event-tickets-5.0.1 -> FETCH_HEAD
 * branch              dependabot/composer/site/wpackagist-plugin/user-switching-1.5.6 -> FETCH_HEAD
 * branch              dependabot/composer/site/wpackagist-plugin/duplicate-post-3.2.6 -> FETCH_HEAD
 * branch              dependabot/composer/site/wpackagist-plugin/wp-mail-smtp-2.4.0 -> FETCH_HEAD
 * branch              dependabot/composer/site/wpackagist-plugin/woocommerce-services-1.24.3 -> FETCH_HEAD
 * branch              dependabot/composer/site/wpackagist-plugin/woocommerce-4.5.2 -> FETCH_HEAD
Trying simple merge with d228188c452f1d22f90e1dd0c088bdafa94d849c
Trying simple merge with 3f21d20663f628ccdf1bc2bcc15ed5319ddd430f
Simple merge did not work, trying automatic merge.
Auto-merging site/composer.lock
ERROR: content conflict in site/composer.lock
fatal: merge program failed
Automated merge did not work.
Should not be doing an octopus.
Merge with strategy octopus failed.
Error: Process completed with exit code 2.
martingjaldbaek commented 3 years ago

Hey Joshua, thanks for the heads up! The "Should not be doing an octopus" error means there was a merge conflict, which your error output confirms. As far as I know that conflict would still be there if the branches were merged one at a time, so I'm not sure if adding an option to not do an octopus merge (i.e. merge the branches one at a time instead) would actually help anything here.

When looking at your error, I can see that the merge conflict is in site/composer.lock. That makes sense, since the most likely way for two different Dependabot PRs to have a conflict is if the resolved 2nd hand dependencies from two different PRs end up resolving to the same lines in the .lock file - which I think might not be too uncommon in frameworks with modular components that share a lot of dependencies. Unfortunately I'm not sure there's really a good way to solve this from git - the "correct" solution would be to add the dependencies together, and then let the package manager sort out the right way for the .lock file to look. That's probably also what Dependabot does if a rebase fails. But unfortunately I think that means that this is just a limitation to this approach, where it merges unrelated PRs together just fine, but closely related PRs will tend to cause conflicts. For a scenario like that, I think the only real solution is to use a dependency update service that will group the PRs for you (I've heard that https://depfu.com/ has that as an option).

Finally, an idea I'm thinking of is to define a kind of label you could put on PRs that you wanted to exclude from the merge. Unfortunately, I don't think that would help in your case, since I can see from the names of your branches that probably almost all your branches would have merge conflicts.

HonkingGoose commented 3 years ago

For a scenario like that, I think the only real solution is to use a dependency update service that will group the PRs for you

Can confirm Depfu will group updates, Renovate can group updates as well. You can find those bots on the GitHub marketplace here: https://github.com/marketplace?category=dependency-management&verification=verified

Depfu only supports JavaScript and Ruby. Renovate covers most popular languages.

Check what languages each bot supports before choosing one to install. :wink:

martingjaldbaek commented 2 years ago

Hey, the latest release, 1.3.0 comes with the ability to gracefully recover from merge conflicts - it just merges as many branches as possible, and in the combined PR it lists which branches, if any, were not included due to merge conflicts. As such, the error "should not be doing an octopus" will never show up any more (in fact the new version does a sequence of normal merges instead of a single octopus merge, so that if any of the individual merges fail, it can be skipped). So I'm closing this issue - the limitation that come with using git merges as a part of the workflow is listed in the readme, but the "sharp edges" that this came with have now been "sanded down", and this specific issue isn't possible any more :)