Skip to content

Add merge workflow#22120

Draft
iluuu1994 wants to merge 1 commit into
php:masterfrom
iluuu1994:merge-workflow
Draft

Add merge workflow#22120
iluuu1994 wants to merge 1 commit into
php:masterfrom
iluuu1994:merge-workflow

Conversation

@iluuu1994
Copy link
Copy Markdown
Member

@iluuu1994 iluuu1994 commented May 22, 2026

TODOs:

  • NEWS entry. Maybe the entry can be added to the PR description and then added to the commit by the workflow.
  • Sign commits. I think the bot will need its own account.
  • Add Signed-off-by from the person adding the label, and potentially from approved PR reviews.
  • Add Co-Authored-By for any other commiter.
  • Potentially add some guardrails, e.g. adding a limit on merged commits if the target is wrong.

Feedback is appreciated. I know some people were skeptical of this approach (@TimWolla, @shivammathur), but I think it's worth trying out. @asgrim expressed interest in this, after seeing how many steps the merge process involves.

Simple test on my fork:

image

Copy link
Copy Markdown
Member

@shivammathur shivammathur left a comment

Choose a reason for hiding this comment

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

Some initial thoughts


permissions:
contents: read

Copy link
Copy Markdown
Member

@shivammathur shivammathur May 22, 2026

Choose a reason for hiding this comment

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

fetch-depth: 0
filter: blob:none
ref: ${{ github.event.pull_request.base.ref }}
token: ${{ secrets.GITHUB_TOKEN }}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please check that merging with GITHUB_TOKEN triggers CI for merged branches, This might need an app token.

Comment on lines +4 to +5
pull_request_target:
types: [labeled]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Using pull_request_target should be avoided. I would suggest using workflow_dispatch that gets triggered by a separate small workflow that runs on issues: labeled, validates the label/actor/PR, then calls the dispatch workflow.

return try_run(['git', 'show-ref', '--verify', '--quiet', "refs/remotes/origin/$branch"]);
}

function find_next_release_branch(string $current): ?string {
Copy link
Copy Markdown
Member

@shivammathur shivammathur May 22, 2026

Choose a reason for hiding this comment

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

This is great, but what if someone labels an old open PR targeting an unsupported branch by mistake and the automation goes off merging it. I would suggest we keep a manifest of branches that this goes through and that is maintained when we branch off to avoid any unexpected merges.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I believe that should be rejected due to our push rules. But I'm happy to test.

Comment on lines +128 to +129
push_pr_branch($pr_repo_url, $pr_ref, $squashed_sha, $pr_sha);
push_release_branches($release_branches);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is not atomic as what if pr_branch gets pushed and push_release_branches fails, this can happen when github is having issues which is a lot lately.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Indeed, but sadly I didn't find a way to push both the PR and release branches atomically, given that the PR branch comes from a different origin. I thought this was acceptable, given that we sometimes do this manually as well.

The only solution I can think of is to revert the PR by pushing the previous commit, but given this might also fail, that would also be an incomplete solution.

Do you have another suggestion?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think adding error handling and a PR comment in case this goes wrong might be a good compromise.

}

function push_pr_branch(string $url, string $branch, string $squashed_sha, string $original_sha) {
run(['git', 'push', "--force-with-lease=$branch:$original_sha", $url, "$squashed_sha:refs/heads/$branch"],
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This might fail if the PR author forgets to tick the box to allow maintainer commits.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Indeed. This step is technically optional, but I'm doing it so that the PR is marked as "merged". I suppose we can close it manually if this step fails, but I also don't think many people tick off this box. But I'm happy to add this fallback if you like.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, handling the fallback would be better.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We'll need to differentiate between a force-with-lease failure and the missing checkbox. In the former case, we don't want the fallback. I'll see what I can do.

Comment on lines +45 to +47
PR_FIRST_SHA: $(git log --reverse --format=%H ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }} | head -n1)
PR_SHA: ${{ github.event.pull_request.head.sha }}
PR_REF: ${{ github.event.pull_request.head.ref }}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There should be a check to stop this workflow before pushing changes if the PR_SHA does not match the PR head as it changed between the label event and the workflow merging and pushing. This can happen when the nightly workflow is running and other workflows runs are delayed.

id: merge
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
PR_FIRST_SHA: $(git log --reverse --format=%H ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }} | head -n1)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This doesn't actually work ofc and will need to run and declared as an env there, or just moved to the script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants