GiteaBot / gitea-backporter

:tea: A script that looks for PRs in Gitea that need to be backported and creates the backport PR for them
MIT License
16 stars 8 forks source link

Fails to backport clean cherry-picks #110

Open silverwind opened 9 months ago

silverwind commented 9 months ago

https://github.com/go-gitea/gitea/pull/27503 is a clean cherry-pick against both 1.21 and 1.20, but the bot failed for unknown reasons. Here's how I do it, maybe the bot tries it differently?

git checkout release/v1.21
git reset --hard origin/release/v1.21
git checkout -b backport-27503-21
git cherry-pick 08efeb5
git push silverwind backport-27503-21
yardenshoham commented 9 months ago

Logs:

2023-10-08T03:13:30.426 app[148ed433fe9d08] ams [info] Synced PR #27503
2023-10-08T03:13:35.518 app[148ed433fe9d08] ams [info] Set commit status in "Fix mermaid flowchart margin issue" (#27503)
2023-10-08T03:20:16.010 app[148ed433fe9d08] ams [info] Parsing #27503
2023-10-08T03:20:16.125 app[148ed433fe9d08] ams [info] Locked issue #25798
2023-10-08T03:20:16.389 app[148ed433fe9d08] ams [info] Set milestone 1.22 for PR #27503
2023-10-08T03:20:16.575 app[148ed433fe9d08] ams [info] Cherry-picking #27503
2023-10-08T03:20:17.338 app[148ed433fe9d08] ams [info] Added comment to #27503
2023-10-08T03:20:18.328 app[148ed433fe9d08] ams [info] Parsing #27503
2023-10-08T03:20:18.760 app[148ed433fe9d08] ams [info] Cherry-picking #27503
2023-10-08T03:20:19.645 app[148ed433fe9d08] ams [info] Added comment to #27503
2023-10-08T03:20:28.105 app[148ed433fe9d08] ams [info] Removed reviewed/wait-merge from "Fix mermaid flowchart margin issue" (#27503)
silverwind commented 9 months ago

Is it using ./contrib/backport? When I try that, it fails:

$ go run ./contrib/backport --version v1.21 --no-push 27503
* Backporting 27503 to origin/release/v1.21 as backport-27503-v1.21
* `git fetch origin main`

* `git fetch origin release/v1.21`

* Current branch is main
* Branch backport-27503-v1.21 already exists. Checking it out...
* Attempting git cherry-pick 08efeb5cdc22d21b5ef12cc540727594a22062d1
git cherry-pick 08efeb5cdc22d21b5ef12cc540727594a22062d1 failed:
On branch backport-27503-v1.21
Your branch and 'origin/release/v1.21' have diverged,
and have 137 and 73 different commits each, respectively.

You are currently cherry-picking commit 08efeb5cdc.
  (all conflicts fixed: run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

nothing to commit (use -u to show untracked files)

Unable to backport: git cherry-pick 08efeb5cdc22d21b5ef12cc540727594a22062d1 failed: exit status 1

I've now made a simple bash script that works, but it also does not amend either:

backport() {
  if [ $# -eq 0 ]; then; echo "backport PR VER"; return 1; fi
  PR="$1"
  VER="$2"

  git checkout "release/v$VER"
  git reset --hard "origin/release/v$VER"
  git branch -D "backport-$PR-$VER"
  git checkout -b "backport-$PR-$VER"
  HASH="$(curl -sH "X-GitHub-Api-Version: 2022-11-28" "https://api.github.com/repos/go-gitea/gitea/pulls/$PR" | jq -r .merge_commit_sha)"
  git cherry-pick "$HASH"
}
silverwind commented 9 months ago

https://github.com/go-gitea/gitea/pull/27501 was also clean cherry-pick which I backported with this bash script now.

silverwind commented 9 months ago

Contributed the script in https://github.com/go-gitea/gitea/pull/27519.

yardenshoham commented 9 months ago

How it backports https://github.com/GiteaBot/gitea-backporter/blob/aab91a4ce0781253c735e2cfa83472f8afe8ab2d/src/git.ts#L44-L92

silverwind commented 9 months ago

Why does the log not show any error?

silverwind commented 9 months ago

Maybe this if branch should log or throw the error?

https://github.com/GiteaBot/gitea-backporter/blob/aab91a4ce0781253c735e2cfa83472f8afe8ab2d/src/git.ts#L78-L84

I would make it throw an error on any command failure, much better than returning false and not knowing why it failed.

silverwind commented 9 months ago

Overall I think the bot should make use of https://github.com/go-gitea/gitea/tree/main/contrib/backport, so that the backporting mechanism can be tested locally in the repo as well. Likely that script needs a few adjustments as mention in the PR.

Edit: https://github.com/go-gitea/gitea/pull/27520 will make that script much less error-prone.

silverwind commented 9 months ago

After https://github.com/go-gitea/gitea/pull/27520, we could make the backporter use this script to cherry-pick. Imho, is is much better to having something that can be ran and debugged locally and we will only have one way to apply backports instead of two.

silverwind commented 8 months ago

https://github.com/go-gitea/gitea/pull/27752 likely another case of a 1-line change not being backported.

silverwind commented 5 months ago

Another case: https://github.com/go-gitea/gitea/pull/29106#issuecomment-1935299040

This is what I did locally and it worked fine:

git checkout release/v1.21
git reset --hard origin/release/v1.21
git checkout -b backport-29106-29111
git cherry-pick 9c39f85
git cherry-pick c7a21cb
git push silverwind backport-29106-29111

Maybe we could add some debug info in a <details> block in the bot comment to show what it did and where it failed to get to the root of this problem.

yardenshoham commented 5 months ago

Sure, send a PR, I will review it

silverwind commented 4 months ago

I think the bot currently can not successfully do any backport onto release/v1.21. I assume once we cut release/v1.22 it will be able to again for unknown reason. I think I've seen this pattern already in the last two releases. At some point in the target branch history, it just can't do it anymore.

silverwind commented 4 months ago

So I think I will write a new backport script in bash, commit it to repo and we let the bot use it. Much easier to debug than running the commands individually through deno and we show the exact output from the script as well in the bot message when it fails.

Likely also remove ./contrib/backport as no one is really using it and it has several shortcomings.

yardenshoham commented 4 months ago

Sure, send a PR, I will review it