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

Fails to backport clean cherry-picks #110

Open
silverwind opened this issue Oct 8, 2023 · 15 comments
Open

Fails to backport clean cherry-picks #110

silverwind opened this issue Oct 8, 2023 · 15 comments

Comments

@silverwind
Copy link
Collaborator

go-gitea/gitea#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
Copy link
Collaborator

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
Copy link
Collaborator Author

silverwind commented Oct 8, 2023

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
Copy link
Collaborator Author

go-gitea/gitea#27501 was also clean cherry-pick which I backported with this bash script now.

@silverwind
Copy link
Collaborator Author

Contributed the script in go-gitea/gitea#27519.

@yardenshoham
Copy link
Collaborator

How it backports

export const cherryPickPr = async (
commitHash: string,
prNumber: number,
giteaMajorMinorVersion: string,
): Promise<boolean> => {
// fetch the upstream main branch
await cmd.run("git", {
cwd: "gitea",
args: ["fetch", "upstream", "main"],
});
// fetch the upstream release branch
await cmd.run("git", {
cwd: "gitea",
args: ["fetch", "upstream", `release/v${giteaMajorMinorVersion}`],
});
// create the backport branch from the upstream release branch
await cmd.run("git", {
cwd: "gitea",
args: [
"checkout",
`upstream/release/v${giteaMajorMinorVersion}`,
"-b",
getPrBranchName(prNumber, giteaMajorMinorVersion),
],
});
// cherry-pick the PR
const cherryPickStatus = await cmd.run("git", {
cwd: "gitea",
args: ["cherry-pick", commitHash],
});
if (!cherryPickStatus.success) {
await cmd.run("git", {
cwd: "gitea",
args: ["cherry-pick", "--abort"],
});
return false;
}
// push the branch to the fork
await cmd.run("git", {
cwd: "gitea",
args: ["push", "origin", getPrBranchName(prNumber, giteaMajorMinorVersion)],
});
return true;
};

@silverwind
Copy link
Collaborator Author

silverwind commented Oct 8, 2023

Why does the log not show any error?

@silverwind
Copy link
Collaborator Author

silverwind commented Oct 8, 2023

Maybe this if branch should log or throw the error?

if (!cherryPickStatus.success) {
await cmd.run("git", {
cwd: "gitea",
args: ["cherry-pick", "--abort"],
});
return false;
}

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

@silverwind
Copy link
Collaborator Author

silverwind commented Oct 8, 2023

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: go-gitea/gitea#27520 will make that script much less error-prone.

@silverwind
Copy link
Collaborator Author

After go-gitea/gitea#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
Copy link
Collaborator Author

go-gitea/gitea#27752 likely another case of a 1-line change not being backported.

@silverwind
Copy link
Collaborator Author

silverwind commented Feb 9, 2024

Another case: go-gitea/gitea#29106 (comment)

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
Copy link
Collaborator

Sure, send a PR, I will review it

@silverwind
Copy link
Collaborator Author

silverwind commented Feb 22, 2024

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
Copy link
Collaborator Author

silverwind commented Feb 22, 2024

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
Copy link
Collaborator

Sure, send a PR, I will review it

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

2 participants