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

Alternate more flexible code owners mechanism, soon to avoid mass pings #336261

Merged
merged 5 commits into from
Oct 8, 2024

Conversation

infinisil
Copy link
Member

@infinisil infinisil commented Aug 21, 2024

Description of changes

These damn mass pings are annoying, let's fix it!

This PR introduces an alternate mechanism of doing effectively the same as GitHub's native CODEOWNERS feature, but with some significant advantages:

  • No reviews will be requested for PRs that target the wrong base branch.
  • There is no need for user/team to have write access to be requested for reviews.
  • Invalidity of the code owners file fails CI

This PR still runs the native CODEOWNERS together with the alternative mechanism, so that we can run it for some time to confirm that it works correctly. Once confirmed, we'll be able to easily turn off the native CODEOWNERS and just rely on the alternate mechanism.

Note that this PR depended on NixOS/org#31

Tested


This work is sponsored by Antithesis

Add a 👍 reaction to pull requests you find important.

@infinisil infinisil added the significant Novel ideas, large API changes, notable refactorings, issues with RFC potential, etc. label Aug 21, 2024
@philiptaron
Copy link
Contributor

cc @tie for bash wizardry and excellent reviews as well.

@tie
Copy link
Member

tie commented Aug 21, 2024

Bash code is high quality, although I’d avoid cmd1 < <(cmd2) because it does not respect errexit (-e flag). E.g.

$ bash -e -u -o pipefail -O inherit_errexit -c 'true < <(false); echo oops'; echo exit code $?
oops
exit code 0
$ bash -e -u -o pipefail -O inherit_errexit -c 'cat <(bashgobrrr); echo oops'; echo exit code $?
bash: line 1: bashgobrrr: command not found
oops
exit code 0

I don’t think I’ll have time to pick this up, but I’d probably rewrite scripts in Python with GitHub client libraries to avoid Bash. It’s much nicer to work with if available, even if subprocess.run calls are a bit more bulky for scripting 😅

#!nix-shell -i python3 -p python3Packages.pygithub

@drupol
Copy link
Contributor

drupol commented Aug 21, 2024

I would definitely use something else than Bash too.

@infinisil
Copy link
Member Author

If I have time to work on this again, I'd prefer to keep using bash, since the script part is pretty much done already. But if somebody else picks this up before that, I fully support a Python rewrite!

@SuperSandro2000
Copy link
Member

This would only cover the use case to request reviews for changed files. We would loose the UI indicator that files are owned by a codeowners, the feature to block merges unless a codeowber approved (we're are not using that to much) and the validation in the UI.

We could split the codeowners file to those features for some entries back though.

@Mic92
Copy link
Member

Mic92 commented Aug 25, 2024

This would only cover the use case to request reviews for changed files. We would loose the UI indicator that files are owned by a codeowners, the feature to block merges unless a codeowber approved (we're are not using that to much) and the validation in the UI.

We could split the codeowners file to those features for some entries back though.

For me that sounds like a good tradeoff if it reduces the noise I am currently getting as a code owner.

@infinisil
Copy link
Member Author

Good point @SuperSandro2000. I agree with @Mic92 that it's probably a good tradeoff still, but in the future we can also fully or partially implement those features:

Ideally all of this would be implemented by some GitHub action out there already, but I couldn't find anything that would work for our specific case.

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/prs-reaching-the-right-reviewers/51312/4

@infinisil
Copy link
Member Author

Worked on this a bunch, and a bit more is needed, but it's looking pretty good! I tested:

@Eveeifyeve
Copy link
Contributor

So is there still going to be still lib.maintainers or is nixpkgs switching to owners?

@infinisil
Copy link
Member Author

infinisil commented Oct 1, 2024

@Eveeifyeve Good question. meta.maintainers does have advantages (such as being able to process it more easily, e.g. for detecting unmaintained packages at eval-time), but also disadvantages (it doesn't map cleanly to files). I can imagine a future in which we combine the best of both worlds, but for now we should definitely maintain the status quo.

@Eveeifyeve
Copy link
Contributor

@Eveeifyeve Good question. meta.maintainers does have advantages (such as being able to process it more easily, e.g. for detecting unmaintained packages at eval-time), but also disadvantages (it doesn't map cleanly to files). I can imagine a future in which we combine the best of both worlds, but for now we should definitely maintain the status quo.

Yeah but I guess it makes sense.

@infinisil infinisil force-pushed the no-more-mass-pings branch 2 times, most recently from aaf1d6b to 3964fb5 Compare October 3, 2024 23:52
@infinisil
Copy link
Member Author

infinisil commented Oct 8, 2024

I briefly disabled it manually because apparently the current codeowners file references some non-existent files: https://github.com/NixOS/nixpkgs/actions/runs/11243668280/job/31260095472#step:7:34

Making a PR to fix this

@infinisil
Copy link
Member Author

Kind of dangerous though, that we can disable the workflow to prevent pings (well not yet), we'll have to trust the committers with that..

@infinisil infinisil deleted the no-more-mass-pings branch October 8, 2024 21:08
@infinisil
Copy link
Member Author

#347348

infinisil added a commit to tweag/nixpkgs that referenced this pull request Oct 8, 2024
Since NixOS#336261 we have CI that
checks that the codeowners file is valid:

https://github.com/NixOS/nixpkgs/actions/runs/11243668280/job/31260095472#step:7:34

Which files are correct (or whether they were removed) was determined
using the Git history and some grepping
@infinisil
Copy link
Member Author

Alright merged and enabled again. Here's the place to watch how it's doing: https://github.com/NixOS/nixpkgs/actions/workflows/codeowners.yml

wrbbz pushed a commit to wrbbz/nixpkgs that referenced this pull request Oct 9, 2024
Since NixOS#336261 we have CI that
checks that the codeowners file is valid:

https://github.com/NixOS/nixpkgs/actions/runs/11243668280/job/31260095472#step:7:34

Which files are correct (or whether they were removed) was determined
using the Git history and some grepping
mkg20001 pushed a commit to mkg20001/nixpkgs that referenced this pull request Oct 9, 2024
Since NixOS#336261 we have CI that
checks that the codeowners file is valid:

https://github.com/NixOS/nixpkgs/actions/runs/11243668280/job/31260095472#step:7:34

Which files are correct (or whether they were removed) was determined
using the Git history and some grepping
@infinisil
Copy link
Member Author

Another follow-up improvement: #347592

@infinisil
Copy link
Member Author

infinisil commented Oct 9, 2024

We also did have a mass ping earlier with #346556, but because the base branch got adjusted within 10 seconds, CI didn't get to the nice error message: https://github.com/NixOS/nixpkgs/actions/runs/11261663743/job/31315595008. (Edit: I wrote a change to fix this, but I don't think we actually want that in practice)

The codeowner check job also failed because the /merge ref didn't exist anymore: https://github.com/NixOS/nixpkgs/actions/runs/11261666327/job/31315601456#step:6:59. I'm looking into whether it's possible to not fail like that. Edit: I don't think it's easily doable but also not really necessary.

infinisil added a commit to tweag/nixpkgs that referenced this pull request Oct 9, 2024
This effectively disables the native GitHub codeowners feature
and enables the new alternate codeowners mechanism introduced in
NixOS#336261

This means that:
- We can now declare users without write access as code owners!
- Targeting the wrong branch won't trigger mass pings anymore!
@infinisil
Copy link
Member Author

#347610 🚀

We could also wait longer, but honestly I don't think we need to. We can always revert if it causes problems, but I'm fairly convinced there won't be any, and I'll be available in case there are

infinisil added a commit to tweag/nixpkgs that referenced this pull request Oct 9, 2024
This effectively disables the native GitHub codeowners feature
and enables the new alternate codeowners mechanism introduced in
NixOS#336261

This means that:
- We can now declare users without write access as code owners!
- Targeting the wrong branch won't trigger mass pings anymore!
mkg20001 pushed a commit to mkg20001/nixpkgs that referenced this pull request Oct 10, 2024
Since NixOS#336261 we have CI that
checks that the codeowners file is valid:

https://github.com/NixOS/nixpkgs/actions/runs/11243668280/job/31260095472#step:7:34

Which files are correct (or whether they were removed) was determined
using the Git history and some grepping
# https://github.com/mszostok/codeowners-validator/pull/222
(fetchpatch {
name = "user-write-access-check";
url = "https://github.com/mszostok/codeowners-validator/compare/f3651e3810802a37bd965e6a9a7210728179d076...840eeb88b4da92bda3e13c838f67f6540b9e8529.patch";
Copy link
Member

Choose a reason for hiding this comment

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

Isn't it kinda a bit up to luck if the commits get garbage collected in unmerged PRs? When you receive review feedback and force push things, the URL might break over time.

@SuperSandro2000
Copy link
Member

We don't have any tests for this other than running it in dry-run mode?
That is kinda concerning for security related tool that talks to outside APIs and does many things in shellscript.

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 10.rebuild-linux: 0 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.