mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-11-24 17:43:19 +01:00
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.
81 lines
2 KiB
JavaScript
Executable file
81 lines
2 KiB
JavaScript
Executable file
#!/usr/bin/env nix-shell
|
|
/*
|
|
#!nix-shell -i node -p nodejs
|
|
*/
|
|
|
|
const typeConfig = {
|
|
master: ['development', 'primary'],
|
|
release: ['development', 'primary'],
|
|
staging: ['development', 'secondary'],
|
|
'staging-next': ['development', 'secondary'],
|
|
'haskell-updates': ['development', 'secondary'],
|
|
nixos: ['channel'],
|
|
nixpkgs: ['channel'],
|
|
}
|
|
|
|
// "order" ranks the development branches by how likely they are the intended base branch
|
|
// when they are an otherwise equally good fit according to ci/github-script/prepare.js.
|
|
const orderConfig = {
|
|
master: 0,
|
|
release: 1,
|
|
staging: 2,
|
|
'haskell-updates': 3,
|
|
'staging-next': 4,
|
|
}
|
|
|
|
function split(branch) {
|
|
return {
|
|
...branch.match(
|
|
/(?<prefix>.+?)(-(?<version>\d{2}\.\d{2}|unstable)(?:-(?<suffix>.*))?)?$/,
|
|
).groups,
|
|
}
|
|
}
|
|
|
|
function classify(branch) {
|
|
const { prefix, version } = split(branch)
|
|
return {
|
|
branch,
|
|
order: orderConfig[prefix] ?? Infinity,
|
|
stable: (version ?? 'unstable') !== 'unstable',
|
|
type: typeConfig[prefix] ?? ['wip'],
|
|
version: version ?? 'unstable',
|
|
}
|
|
}
|
|
|
|
module.exports = { classify }
|
|
|
|
// If called directly via CLI, runs the following tests:
|
|
if (!module.parent) {
|
|
console.log('split(branch)')
|
|
function testSplit(branch) {
|
|
console.log(branch, split(branch))
|
|
}
|
|
testSplit('master')
|
|
testSplit('release-25.05')
|
|
testSplit('staging')
|
|
testSplit('staging-next')
|
|
testSplit('staging-25.05')
|
|
testSplit('staging-next-25.05')
|
|
testSplit('nixpkgs-25.05-darwin')
|
|
testSplit('nixpkgs-unstable')
|
|
testSplit('haskell-updates')
|
|
testSplit('backport-123-to-release-25.05')
|
|
|
|
console.log('')
|
|
|
|
console.log('classify(branch)')
|
|
function testClassify(branch) {
|
|
console.log(branch, classify(branch))
|
|
}
|
|
testClassify('master')
|
|
testClassify('release-25.05')
|
|
testClassify('staging')
|
|
testClassify('staging-next')
|
|
testClassify('staging-25.05')
|
|
testClassify('staging-next-25.05')
|
|
testClassify('nixpkgs-25.05-darwin')
|
|
testClassify('nixpkgs-unstable')
|
|
testClassify('haskell-updates')
|
|
testClassify('backport-123-to-release-25.05')
|
|
}
|