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

Add GitHub Action to automatically create cherrypick PRs #10361

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

tetrapod00
Copy link
Contributor

@tetrapod00 tetrapod00 commented Dec 2, 2024

Uses peter-evans/create-pull-request and actions/checkout, both of which are already dependencies.

When merging a PR with a cherrypick label, attempt to cherrypick a single commit into a new branch, then create a PR.

Handles squash and merge, by checking the number of commits in the PR, and choosing the commit to cherrypick accordingly.

Fails if the cherrypick does not apply cleanly.

Does not attempt to merge the new PR.
Does not attempt to update stable.


This will likely need to wait until we stop using stable, since each auto-cherrypicked PR would need a separate PR to update stable. We can definitely automate that with another action, and I think we can even make the second action trigger on merge of any of these automatic cherrypick PRs... but that seems very messy. If we wait until stable is no longer used, then these automatic cherrypick PRs can simply be merged after giving them a human review, and then will trigger a rebuild of the docs.

To test this I recommend making a new fake-master or similar branch in your fork, create a 5.3 branch and a cherrypick:5.3 label, and then change the relevant strings in the workflow file to refer to those branches instead. At least, that's how I tested.

Potential future improvements:

  • Handle squash and merge PRs. The API doesn't explicitly expose a way to test how a PR was merged. But we can check the number of commits in the PR, and handle the two cases differently. This is prone to error if for example we squash and merge a PR with a single commit, or merge commit a PR with several commits. But I think that in those cases the cherrypick will not apply cleanly, and still fail. And there should be a human review for these auto-cherrypicks anyway.

Optional:

  • Handle cherrypicking to multiple past branches. I ran into some limitations of the GHA syntax and couldn't figure out how to use an env variable within a contains(). So I couldn't figure this out in the initial implementation. There should be some way, though.
  • Remove the cherrypick label automatically when the cherrypick is merged?
  • Comment automatically when the cherrypick is merged?
  • Comment in the PR if the cherrypick does not apply cleanly?

Uses peter-evans/create-pull-request and actions/checkout,
both of which are already dependencies.

When merging a PR with a cherrypick label, which only contains
a single commit, attempt to cherrypick the single commit into
a new branch, then create a PR.

Fails if there are multiple commits (to catch squash and merge).
Fails if the cherrypick does not apply cleanly.

Does not attempt to merge the new PR.
Does not attempt to update stable.
@tetrapod00 tetrapod00 added enhancement github_actions Pull requests that update GitHub Actions code labels Dec 2, 2024
@mhilbrunner
Copy link
Member

mhilbrunner commented Dec 3, 2024

Yaaay! Exactly the direction I had in mind and never found time for.

This will likely need to wait until we stop using stable, since each auto-cherrypicked PR would need a separate PR to update stable.

Yes; but IMO it is fine to still sync stable automatically after merging a bunch of these PRs. Shouldn't block this.

Remove the cherrypick label automatically when the cherrypick is merged?

That'd be super nice, but not blocking IMO.

Comment automatically when the cherrypick is merged?

Nice to have but not critical to me.

Comment in the PR if the cherrypick does not apply cleanly?

Likewise not critical, as the absence of a cherrypick PR referencing it kinda already implies something went wrong.

Handle cherrypicking to multiple past branches.

Nice to have, but also harder to handle logically -- e.g., we still have many PRs labelled for cherrypicking to older branches that shouldn't be cherrypicked anymore now that current stable has moved on (a lot of enhancement PRs usually).

So personally I'd rather keep this manual, actually. Also, now that the team is growing we can hopefully move more towards anticipatory work (e.g. document the upcoming Godot versions before/as they come out), instead of having to catch up a lot. As we now get smaller, but more frequent releases it is also not as critical if some stuff is not, say, in 4.1 docs but in 4.2/4.3. This was a large issue in the past with the larger, slower releases.

So overall, we will probably be increasingly more conservative in what we cherrypick to old branches, and how far back, keeping that increasingly to important bug fixes (docs that are outright wrong or misleading, for example).


The only blocking things here to me are:

  • This needs a bit of testing. Help welcome!
  • We need to handle squash+merge cleanly, especially as we are increasingly using that now.
  • Once we are happy with it, we need signoff by Akien, to make sure he's happy with how the Git history looks with this.

Thank you for working on this, this will make both the docs team and users super happy :)

@tetrapod00
Copy link
Contributor Author

Squash and merge is now handled.

For the sake of code review, you may be interested in the GH docs for the ternary hack and for the pull request event:

Note that GITHUB_SHA for this event is the last merge commit of the pull request merge branch. If you want to get the commit ID for the last commit to the head branch of the pull request, use github.event.pull_request.head.sha instead.

@tetrapod00
Copy link
Contributor Author

I think all the nice-to-haves will require one or more separate actions/workflows, which trigger on the merging of the automatically generated PR. I believe there is also a complication where PRs generated by actions usually don't trigger new actions to avoid recursion, unless you manually set it up.

So if this workflow of automatically generating but manually merging PRs is acceptable, let's defer the nice-to-haves for later.

@tetrapod00 tetrapod00 marked this pull request as ready for review December 4, 2024 06:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion enhancement github_actions Pull requests that update GitHub Actions code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants