ci/github-script/check-target-branch: check staging-nixos mass rebuilds

Assisted-by: Codex gpt-5.6-sol medium
This commit is contained in:
Ihar Hrachyshka
2026-08-17 21:08:16 -04:00
parent 403d5922cf
commit 221930c60c
3 changed files with 31 additions and 18 deletions

View File

@@ -53,14 +53,14 @@ const cases: Array<{
expected: 'mass-rebuild',
},
{
name: 'does not check mass rebuilds on staging-nixos',
name: 'flags a mass rebuild on staging-nixos',
facts: { base: 'staging-nixos', maxRebuildCount: 24_000 },
expected: 'dismiss',
expected: 'mass-rebuild',
},
{
name: 'does not check mass rebuilds on a release staging-nixos branch',
name: 'flags a mass rebuild on a release staging-nixos branch',
facts: { base: 'staging-nixos-26.05', maxRebuildCount: 1000 },
expected: 'dismiss',
expected: 'mass-rebuild',
},
{
name: 'allows mass rebuilds on staging',
@@ -97,9 +97,9 @@ const cases: Array<{
expected: 'dismiss',
},
{
name: 'does not check possible mass rebuilds on staging-nixos',
name: 'flags other possible mass rebuilds on staging-nixos',
facts: { base: 'staging-nixos', maxRebuildCount: 500 },
expected: 'dismiss',
expected: 'possible-mass-rebuild',
},
{
name: 'skips staging into master',
@@ -127,13 +127,13 @@ const cases: Array<{
expected: 'skip-development-merge',
},
{
name: 'skips staging into staging-nixos',
name: 'checks staging into staging-nixos',
facts: {
base: 'staging-nixos',
head: 'staging',
maxRebuildCount: 24_000,
},
expected: 'skip-development-merge',
expected: 'mass-rebuild',
},
{
name: 'skips release staging-nixos into its release branch',
@@ -154,13 +154,13 @@ const cases: Array<{
expected: 'skip-development-merge',
},
{
name: 'skips release staging into its staging-nixos branch',
name: 'checks release staging into its staging-nixos branch',
facts: {
base: 'staging-nixos-26.05',
head: 'staging-26.05',
maxRebuildCount: 24_000,
},
expected: 'skip-development-merge',
expected: 'mass-rebuild',
},
{
name: 'kernel exemption suppresses a possible mass rebuild',

View File

@@ -1,4 +1,4 @@
const { classify } = require('../supportedBranches.js')
const { classify, split } = require('../supportedBranches.js')
type TargetBranchPolicyFacts = {
base: string
@@ -20,12 +20,17 @@ function getTargetBranchPolicy({ base, head }: { base: string; head: string }) {
const baseClassification = classify(base)
const headClassification = classify(head)
const isPrimaryBase = baseClassification.type.includes('primary')
const isPrimaryHead = headClassification.type.includes('primary')
const isStagingNixosBase = split(base).prefix === 'staging-nixos'
const isDevelopmentHead = headClassification.type.includes('development')
const shouldSkipDevelopmentMerge =
headClassification.type.includes('development')
isDevelopmentHead && (!isStagingNixosBase || isPrimaryHead)
return {
isStagingNixosBase,
shouldSkipDevelopmentMerge,
shouldCheckMassRebuild: !shouldSkipDevelopmentMerge && isPrimaryBase,
shouldCheckMassRebuild:
!shouldSkipDevelopmentMerge && (isPrimaryBase || isStagingNixosBase),
shouldCheckNixosRebuild: !shouldSkipDevelopmentMerge && isPrimaryBase,
}
}
@@ -39,6 +44,7 @@ function decideTargetBranchReview({
isExemptHomeAssistantUpdate,
}: TargetBranchPolicyFacts): TargetBranchReviewDecision {
const {
isStagingNixosBase,
shouldSkipDevelopmentMerge,
shouldCheckMassRebuild,
shouldCheckNixosRebuild,
@@ -61,7 +67,11 @@ function decideTargetBranchReview({
!isMassRebuild &&
!isExemptKernelUpdate &&
!isExemptHomeAssistantUpdate
if (shouldCheckMassRebuild && isPossibleMassRebuild) {
if (
shouldCheckMassRebuild &&
isPossibleMassRebuild &&
!(rebuildsAllTests && isStagingNixosBase)
) {
return 'possible-mass-rebuild'
}

View File

@@ -53,10 +53,14 @@ type TargetBranchReviewFacts = {
maxRebuildCount: number
}
function getStagingBranch(base: string) {
const version = split(base).version
return version ? `staging-${version}` : 'staging'
}
async function postMassRebuildReview(facts: TargetBranchReviewFacts) {
const { github, context, core, dry, base, maxRebuildCount } = facts
const desiredBranch =
base === 'master' ? 'staging' : `staging-${split(base).version}`
const desiredBranch = getStagingBranch(base)
const body = [
`The PR's base branch is set to \`${base}\`, but this PR causes ${maxRebuildCount} rebuilds.`,
'It is therefore considered a mass rebuild.',
@@ -107,8 +111,7 @@ async function postNixosRebuildReview(facts: TargetBranchReviewFacts) {
async function postPossibleMassRebuildReview(facts: TargetBranchReviewFacts) {
const { github, context, core, dry, base, maxRebuildCount } = facts
const stagingBranch =
base === 'master' ? 'staging' : `staging-${split(base).version}`
const stagingBranch = getStagingBranch(base)
const body = [
`The PR's base branch is set to \`${base}\`, and this PR causes ${maxRebuildCount} rebuilds.`,
`Please consider whether this PR causes a mass rebuild according to [our conventions](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md#branch-conventions).`,