Commit graph

72 commits

Author SHA1 Message Date
Wolfgang Walther ffdc8205e5
workflows/bot: allow maintainer merges after committer approval
This allows committers to approve PRs with additional, optional nits
that the author-maintainer can either address or merge immediately
without these changes.

It also allows committers to approve a PR for merge, while still waiting
for other maintainers to give their feedback - they can then merge the
PR directly instead of passing it back to the committer.
2025-11-02 19:35:33 +01:00
Wolfgang Walther 9a637aa7a4
ci/github-script/merge: restructure head SHA check
While it was already the case that only merge comments *after* the
latest push were acted on, the logic wasn't easy to understand. This
change should make it more obvious, specially in combination with the
next commit, that all steps (comments, approvals, merge) must happen on
the same SHA - the current head SHA of the PR.
2025-11-02 19:35:32 +01:00
Wolfgang Walther 91c4d9236b
workflows/bot: allow maintainers to merge backports
All other conditions equal, there is no reason to prevent maintainers
from backporting changes to their packages. Maintainers are probably in
the *best* position to tell whether a certain change is backportable or
not - because they know the package well.
2025-11-02 17:26:01 +01:00
Wolfgang Walther 84d6678f3b
ci/github-script/merge: support OR conditions
This supports AND on the first and OR on the second level, which is
needed for some follow up work like backports, approval based merges or
trusted maintainers.
2025-11-02 16:36:14 +01:00
Wolfgang Walther 6848f93842
ci/github-script/merge: add TODO about second merge method
We have not observed this merge method being used in practice, yet. Not
in the new bot, not in the old bot. It seems like auto-merge works for
all cases.
2025-11-02 16:36:06 +01:00
Wolfgang Walther db8f50b4de
ci/github-script/merge: improve wording 2025-11-02 16:36:01 +01:00
Wolfgang Walther 2d0a8791fe
ci/github-script/merge: improve maintainer check 2025-11-02 16:35:56 +01:00
Wolfgang Walther 6a3c294f6f
ci/github-script/merge: move all conditions into runChecklist
No special casing anymore, all conditions are in the same place. This
also has the benefit of hiding the "has maintainers eligible for merge"
condition from comments, because it is only really relevant for
labeling.
2025-11-02 16:35:51 +01:00
Wolfgang Walther 7ea127c83a
ci/github-script/merge: move API requests out of runChecklist
This makes runChecklist mostly a pure function (except for logging) to
allow calling it repeatedly later.
2025-11-02 16:35:48 +01:00
Wolfgang Walther c7766c637f
ci/github-script/merge: improve caching of team members
This removes the need to `await` committers further down in the function
and allows re-using the cache for other teams later.
2025-11-02 16:35:16 +01:00
Wolfgang Walther 1aa72502fb
workflows/bot: fix permission in test workflow (#457575) 2025-11-01 17:57:59 +00:00
Wolfgang Walther 421974863f
workflows/bot: avoid access teams endpoints in Test workflow
We have no chance of getting a token that can request the team endpoints
in the pull_request context. This makes sense, because non-members of
the org are also not allowed to view the teams' memberships.

Thus, just fake an empty team - that's fine for the Test workflow.
2025-11-01 18:49:22 +01:00
Wolfgang Walther 00e7b934fb
workflows/bot: set "merge-bot eligible" label
This makes it more visible which PRs are merge-bot eligible, by setting
a label respectively.
2025-11-01 17:18:19 +01:00
Wolfgang Walther 89ace76ff1
workflows/bot: retry failed merges
By not keeping the node_id in the comments resulting from a failed
merge, these merges will be automatically retried.
2025-11-01 15:54:53 +01:00
Wolfgang Walther eea09eb9d3
workflows/bot: migrate nixpkgs-merge-bot to GHA
Running the nixpkgs-merge-bot in GitHub Actions instead of a separate
workflow has multiple advantages:
- A much better development workflow, with improved testability.
- The ability to label PRs with a "merge-bot eligible" label from the
same codebase.
- Using more data for merge strategy decisions, for example the number
of rebuilds.

This commits re-implements most of the features from the current
nxipkgs-merge-bot directly in the bot workflow. Instead of reacting to
webhook events, this now runs on the regular 10 minute schedule. Some
merges might be delayed a few minutes, but that should not be a problem
in practice.

To give the user early feedback, there are additional workflows running
when a comment or review is posted. These react with "eyes" to make the
user aware that the comment has been recognized.

The only feature not taken over was the size check for files in the PR.
This kind of check is not really relevant for maintainer merges only -
if we want to prevent bigger files from making it into the tree, then we
need a generic CI check, which is out of scope for the merge-bot.

Other than that, everything should be implemented - any omissions are by
accident.
2025-11-01 15:54:51 +01:00
Wolfgang Walther d78de15627
workflows/bot: rename from labels
This workflow / script is already doing more than must labeling: it's
already auto-closing package request issues.

Since we're going to migrate the nixpkgs-merge-bot into this workflow,
we'll rename things to a more generic name.
2025-11-01 15:24:09 +01:00
Wolfgang Walther f66a380ea3
workflows/pr: rename to pull-request-target
To be able to disable the pr.yml workflow on GitHub, we need to rename
it to a different name. Let's use the long name for consistency with
merge-group.yml. This only affects the GitHub-internal name, not the
visible name in the PR checklist, which is still "PR". This visible name
is also used by nixpkgs-review, so that won't break.
2025-11-01 12:59:21 +01:00
Wolfgang Walther 7b4a437e99
ci/github-script/labels: fix unmaintained packages
The labeler currently breaks for unmaintained packages after the recent
change to use maintainer maps.
2025-11-01 11:47:45 +01:00
Wolfgang Walther 6b5e6cbbee
ci/github-script/labels: set maintainer labels from latest maintainer map
Instead of setting the maintainer-related labels based entirely on Eval
results, this uses the new maintainer map from the target branch. This
allows labeling PRs correctly, that had been created *before* a
contributor became a maintainer of the respective package.
2025-11-01 10:36:23 +01:00
Wolfgang Walther 3df31aa255
ci/github-script/teams: use consistent style
These are style-only changes, that are not enforced via tooling - but
used mostly consistently in the other github-script files.
2025-10-28 11:56:25 +01:00
Silvan Mosberger c0c6684257 workflows/team-sync: init
Creates a team sync workflow that pushes the current state of teams to a
JSON file, which can then be ingested by `lib.teams` to expose member
lists.

Co-Authored-By: Alexander Bantyev <alexander.bantyev@tweag.io>
2025-10-27 19:36:57 +01:00
Wolfgang Walther a705a34a22
ci/github-script/labels: prevent closing purposely-empty PRs
Some PRs are empty on purpose, for example the yearly notification about
the election for voters. We should not close these because the merge
commit is empty - only if there was a change intended, but the merge
commit *becomes* empty, we should act.
2025-10-19 11:27:05 +02:00
Wolfgang Walther 402b41c125
ci/github-script/labels: close empty PRs
If the change of a PR has already been merged to the target branch
elsewhere, the PR will not be auto-closed by GitHub - and will still
show the same original diff. Still, the temporary merge commit is
actually empty. This causes all kinds of strange CI behavior, from not
showing rebuilds to not pinging maintainers.

We check the merge commit during labeling anyway, to see whether a merge
conflict is present. It's easy to just look a the number of affected
files in this merge commit - and if there are none, we can just
automatically close the PR as no longer relevant.
2025-10-18 11:29:36 +02:00
Wolfgang Walther b98ea083be
workflows/labels: use Node 24 2025-10-11 13:37:21 +02:00
Wolfgang Walther f0c1e4b672
ci/github-script/labels: solve TODOs
These can now be removed after enough time has passed.

Advanced search is only the default from November 4, according to the
GitHub docs at:
https://docs.github.com/en/rest/search/search?apiVersion=2022-11-28#search-issues-and-pull-requests
2025-10-11 13:35:53 +02:00
Wolfgang Walther f7d6d11e8e
workflows/check: don't check github api for owners file
This removes the "owners" check from codeowners-validator. With it, all
tokens and permissions can be removed, because these were only needed to
make these requests.

This solves the problem of codeowners-validator not supporting our new
nested team structure for nixpkgs-maintainers. To make the onboarding of
new teams easier, we moved all teams "under" the nixpkgs-maintainers
team. This makes them inherit the right privileges (triage) for Nixpkgs.

However, this inheritance is not recognized by codeowners-validator,
thus it assumes that these teams don't have access to Nixpkgs. This then
fails the owners check immediately.

Removing the owners check also has a few other advantages:
- This check depends on external state: If a user is renamed or a team
removed, the check will fail. This makes it a bad check for required
status checks or merge queues - the check might fail randomly,
independent of the current PR.
- Running this check in a fork will never work, because the respective
users and teams don't have access to the fork's repo.

Both of this required us to set `continue-on-error: true` most of the
time.
2025-09-28 18:22:01 +02:00
Ryan Omasta 4c6b9993e6
ci/github-script/labels: don't add stale if issue was mentioned
Co-authored-by: Wolfgang Walther <walther@technowledgy.de>
2025-09-15 02:07:27 -06:00
Ryan Omasta 32373aff1c
ci/github-script/labels: keep "needs reviewer" if only automated reviews 2025-09-08 21:55:43 -06:00
Wolfgang Walther b5dee53399
ci/github-script/labels: auto close package request issues
This allows the labels workflow to support issue management in two ways:
- New package request can potentially created with a `4.workflow:
auto-close` label immediately and be closed automatically this way.
- Existing package requests can be bulk-closed by adding this label.
This has the advantage of posting the explanatory comment at the same
time, which is not possible with regular bulk operations.
2025-08-29 21:09:55 +02:00
Wolfgang Walther eb766e2d51
ci/github-script: fix run script
Not a problem for prepare/commits, but the labels comand will remove the
temp directory again, before it actually runs the command. Nothing good
will come out of that!
2025-08-26 13:52:25 +02:00
Wolfgang Walther 41ae23c0e7
ci,workflows: deal with ghost reviews
When a user deletes their account, they appear as a "ghost user". This
user is represented as `null` on API requests. If such a user had posted
a review before, this breaks a few places, which assume to be able to
access `user.login`.
2025-08-25 15:17:01 +02:00
Wolfgang Walther 40d8532c08
ci/github-script/prepare: identify real base branch (#435596) 2025-08-25 12:05:12 +00:00
Wolfgang Walther 956d0a744d
workflows/check: allow owners to fail when ci/OWNERS is untouched
The owners check is not reproducible, because it depends on the state of
the NixOS org on GitHub. Owners can rename their accounts or they can
leave the organisation and access to Nixpkgs can be removed from teams.
All of this breaks the owners check for reasons unrelated to the PR at
hand.

This PR makes the check for the owners file conditionally required: Only
when the ci/OWNERS file is actually modified a failed check will block
merging the PR. When that's not the case, the check will still fail
visibily in the checklist, but the failure can be ignored.

This is especially relevant for the Merge Queue, which should not be
entirely blocked whenever any of these events happen.

Also, it allows passing the checks in a fork when testing, where the
owners check will *always* fail, because the respective teams and
members are never part of the "user org" that a fork is.
2025-08-24 20:11:29 +02:00
Wolfgang Walther 87d9b08ffb
ci/github-script/prepare: identify real base branch
When a contributor mistakenly sets the wrong target branch for a Pull
Request, this can lead to bad consequences for CI. Most prominent is the
mass ping of codeowners, that is already handled in
`ci/request-reviews/verify-base-branch.sh`. But there are other things
that go wrong:
- After eval, a mass ping of maintainers would still be possible, in
theory. Practically, this doesn't happen, because we have a limit of 10
reviewer requests at the same time.
- This will most often contain a change to `ci/pinned.json`, thus the
full Eval matrix of all Lix/Nix versions will be run, burning a lot of
resources.
- The PR will be labelled with almost all labels that are available.

We can improve on the current situation with some API calls to determine
the "best" merge-base for the current PR. We then consider this as the
"real base". If the current target is not the real base, we fail the
prepare step, which is early enough to prevent all other CI from
running.
2025-08-24 18:09:08 +02:00
Wolfgang Walther 0601cf6fd0
ci/github-script/prepare: avoid running CI when targeting channel branches
This moves the no-channel-base check into the prepare script to exit
early and prevent all of CI to run against those branches. We also
provide better output by posting a "Changes Requested" review, using the
existing infrastructure from the old cherry-picks check.

The review will be dismissed automatically once the branch has been
corrected, because the commits check will run and do it.
2025-08-24 17:58:51 +02:00
Wolfgang Walther c96b0e6d3d
ci/github-script/commits: split review function into separate file
This allows re-using postReview in the next commit.
2025-08-24 12:14:54 +02:00
Wolfgang Walther b6bbf7b250
workflows/check: always run commits job
This is the very first step to extending the commits job to do more than
just cherry-picks in the future: It could check reverts or merge
commits, but also the commit message format and more.

Of course, cherry-picks are still just checked on the stable branches as
before. For now, this allows us to run the part that dismisses automated
reviews automatically. This helps us when we do branch related checks in
the prepare step, which would also create such a review. To avoid
cluttering multiple reviews across a PR, we'll want all of these reviews
to be handled by the same code, thus this change.
2025-08-24 12:14:50 +02:00
Wolfgang Walther 443f30f811
workflows/test: init
This workflow runs the PR and Push workflow files on a `pull_request`
trigger. The intent is to test changes to the workflow files
immediately. Previously, these were run directly from the respective
workflow files.

The new approach allows us to move the logic to run this only when
workflow files changed from the pull_request trigger into a job. This
has the advantage that older jobs are cleaned up, when the PR changes
from a state of "workflow files changed" to "no workflow files changed".
This can happen when changing a PR's base from staging to master, in
which case changes from master would temporarily appear in the PR as
changes. When these include changes to workflow files, this would
trigger the PR workflow via `pull_request`. Once the base is changed,
the PR is closed and re-opened, so CI runs again - but since it's on the
same commit and the new run doesn't trigger `pull_request`, the results
of the previous run are still kept and displayed. These results may
include cancelled or failed jobs, which are impossible to recover from
without another force-push.

Checking this condition at run-time is only possible, because we move it
into a separate workflow, turning the `pr.yml` workflow into a re-usable
workflow. This will make sure to skip the whole workflow at once, when
no change was detected, which will prevent the "no PR failures" job from
appearing as skipped - which would imply "success" and make the PR
mergeable immediately. Instead the "no PR failures" job is not shown at
all for this trigger, which is generally what we want.

Do the same for `push.yml` for consistency.
2025-08-24 12:07:39 +02:00
Wolfgang Walther 2257beb1d0
ci/github-script/commits: fix logging no-cherry-pick message
This has severity "important", which is not a `core` function. Falling
back to `core.info` for all unknown values now.
2025-08-22 09:24:41 +02:00
Wolfgang Walther 8ec348d644
ci/github-script/commits: fix not-cherry-picked-because regex
This needs the multiline flags, which enables `^` and `$` to match line
start and line end, not start and end of the whole string.

Not sure how this got past testing when initially merged.
2025-08-22 09:18:32 +02:00
Wolfgang Walther f94fd64d53
ci/github-script/prepare: fix logging of branch classification
Logging objects to stdout is not possible with `core.info`, so we
fallback to `console.log` instead. There's no functional difference for
these anyway.
2025-08-20 17:59:27 +02:00
Wolfgang Walther 46a1b0a7bc
ci/github-script/prepare: determine changed files 2025-08-20 17:18:36 +02:00
Wolfgang Walther 4220a03df8
ci/github-script/prepare: classify branches 2025-08-20 17:18:25 +02:00
Wolfgang Walther 9caf455441
ci/github-script/prepare: load systems 2025-08-20 17:17:12 +02:00
Wolfgang Walther 23b82b3228
ci: apply unsafe fixes with biome 2025-08-20 15:41:28 +02:00
Wolfgang Walther 1fa55d3900
ci: apply safe formatting with biome 2025-08-20 15:41:24 +02:00
Wolfgang Walther a8cb53611b
ci/github-script/prepare: refactor
Using core.info instead of console.log and simplifying the arguments for
API calls a bit.
2025-08-20 15:16:20 +02:00
Wolfgang Walther f5d3e43368
ci/github-script/prepare: run biome
This will be added to treefmt in a different commit / PR.
2025-08-20 15:16:20 +02:00
Wolfgang Walther c787c66de6
ci/github-script/prepare: init from actions/get-merge-commit
This just moves the code over to ci/github-script to make it easy to
test and iterate on locally.

The name `prepare` is chosen, because the script will be extended with
the other steps from "PR / prepare" next.
2025-08-20 15:16:15 +02:00
Wolfgang Walther 91fd9b10ac
ci/github-script/commits: conditionally show comments
This only shows *some* of the additional hints, depending on what the
checks resulted in. Should hopefully reduce confusion a bit.
2025-08-14 18:29:50 +02:00