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

workflows/auto-merge{,-enable,-abort}: init #261800

Closed
wants to merge 1 commit into from

Conversation

felschr
Copy link
Member

@felschr felschr commented Oct 18, 2023

Description of changes

Add GitHub workflow for auto-merging PRs once checks all succeed based on a label that only committers can set.

This is very much WIP, not tested at all and I'm not that familiar with GitHub actions, but it seems feasible.

@delroth shared this idea on Matrix.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandbox = true set in nix.conf? (See Nix manual)
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 23.11 Release Notes (or backporting 23.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

@delroth
Copy link
Contributor

delroth commented Oct 18, 2023

@delroth shared this idea on Matrix: https://matrix.to/#/!kjdutkOsheZdjqYmqp:nixos.org/$CdzV5mNDPxohBv_NMz6zrwmIgTR5EQ3pYoiPn364LpU?via=nixos.org&via=matrix.org&via=nixos.dev

To expand on the rationale: I've noticed that I very commonly have to tell people "this PR seems fine, I'll merge it once ofborg is green". Then I either forget, or I have to context switch at some later point in the future when I hope that ofborg will have completed :-) I'd much rather this be automated to save on that context switch and decrease merge latency.

@@ -0,0 +1,27 @@
# This action aborts auto-merging by removing the label
# when changes are pushed.
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm worried about TOCTOU problems here - it seems hard to "prove" for sure that they don't exist with how this is currently architectured. If you're confident that this implementation doesn't have TOCTOU problems, I'd thoroughly document it somewhere.

Copy link
Member

Choose a reason for hiding this comment

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

In the github API, you can specify the sha hash to merge: https://docs.github.com/en/free-pro-team@latest/rest/pulls/pulls?apiVersion=2022-11-28#merge-a-pull-request
This means you can make sure that the PR was not updated with newer content than what your current state was.

contents: write # for devmasx/merge-branch to merge branches
pull-requests: write # for peter-evans/create-or-update-comment to create or update comment
name: auto merge
if: github.repository_owner == 'NixOS' && github.event.pull_request.merged == false && contains(github.event.pull_request.labels.*.name, 'auto-merge') && github.event.check_suite.conclusion == 'success'
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that check_suite events contain the SHA of the commit for which they were ran. Maybe this is something we could use for merge-branch to additionally make sure that we're merging the right thing?

@@ -0,0 +1,37 @@
# This action ensures the "auto-merge" label can only by used
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's use this thread to bikeshed label name :P

My suggestion: "merge-on-green" or something along those lines, which attempts to state the condition for the merge to happen automatically.

@delroth
Copy link
Contributor

delroth commented Oct 18, 2023

Alternative implementations:

@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux labels Oct 18, 2023
@felschr
Copy link
Member Author

felschr commented Oct 18, 2023

auto-merge-enable & auto-merge-abort work now, but auto-merge isn't being triggered for some reason.

I've been testing this over here: https://github.com/felschr-org/nixpkgs/pull/6

@felschr
Copy link
Member Author

felschr commented Oct 18, 2023

check_run never seems to get invoked for workflows (and workflow_run requires specifying workflows).
Seems that OfBorg will invoke check_run, though. OfBorg doesn't run for my fork, so haven't tested this.

Usually OfBorg will be the last check to finish, so it might be alright to ignore workflows. We can also include the workflows, but we need to specify all of them which is a bit error-prone.

I'll still try using workflow_run later, just to be able to test this in my fork.

@infinisil infinisil added the significant Novel ideas, large API changes, notable refactorings, issues with RFC potential, etc. label Nov 16, 2023
@felschr
Copy link
Member Author

felschr commented Jun 24, 2024

I think this might be a better fit for nixpkgs-merge-bot now.
There is a related issue: NixOS/nixpkgs-merge-bot#95

Either way, since I unfortunately don't have time to look into this further at the moment, I'm closing this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: policy discussion 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux significant Novel ideas, large API changes, notable refactorings, issues with RFC potential, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants