1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
import { classify, split } from './supportedBranches.js'
type TargetBranchPolicyFacts = {
base: string
head: string
maxRebuildCount: number
rebuildsAllTests: boolean
onlyChangedFile: string | null
}
type TargetBranchReviewDecision =
| 'mass-rebuild'
| 'nixos-rebuild'
| 'possible-mass-rebuild'
| 'skip-development-merge'
| 'dismiss'
type TargetBranchPolicyResult = {
decision: TargetBranchReviewDecision
details: {
isExemptKernelUpdate: boolean
isExemptHomeAssistantUpdate: boolean
}
}
export 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 =
isDevelopmentHead && (!isStagingNixosBase || isPrimaryHead)
return {
isStagingNixosBase,
shouldSkipDevelopmentMerge,
shouldCheckMassRebuild:
!shouldSkipDevelopmentMerge && (isPrimaryBase || isStagingNixosBase),
shouldCheckNixosRebuild: !shouldSkipDevelopmentMerge && isPrimaryBase,
}
}
export function evaluateTargetBranchPolicy({
base,
head,
maxRebuildCount,
rebuildsAllTests,
onlyChangedFile,
}: TargetBranchPolicyFacts): TargetBranchPolicyResult {
const {
isStagingNixosBase,
shouldSkipDevelopmentMerge,
shouldCheckMassRebuild,
shouldCheckNixosRebuild,
} = getTargetBranchPolicy({ base, head })
// https://github.com/NixOS/nixpkgs/pull/553786#issuecomment-5510286851
// kernels-org should go to staging-nixos (or master) and staging-nixos-xx.xx (or release-xx.xx) when backported
// https://github.com/NixOS/nixpkgs/pull/521157
// xanmod should go to master and release-xx.xx when backported
const isExemptKernelUpdate =
onlyChangedFile === 'pkgs/os-specific/linux/kernel/kernels-org.json' ||
onlyChangedFile === 'pkgs/os-specific/linux/kernel/xanmod-kernels.nix'
// https://github.com/NixOS/nixpkgs/pull/483194#issuecomment-3793393218
const isExemptHomeAssistantUpdate =
maxRebuildCount <= 1500 && head === 'wip-home-assistant'
const details = {
isExemptKernelUpdate,
isExemptHomeAssistantUpdate,
}
const result = (decision: TargetBranchReviewDecision) => ({
decision,
details,
})
const isMassRebuild =
maxRebuildCount >= 1000 &&
!isExemptKernelUpdate &&
!isExemptHomeAssistantUpdate
if (shouldCheckMassRebuild && isMassRebuild) {
return result('mass-rebuild')
}
if (shouldCheckNixosRebuild && rebuildsAllTests && !isExemptKernelUpdate) {
return result('nixos-rebuild')
}
const isPossibleMassRebuild =
maxRebuildCount >= 500 &&
!isMassRebuild &&
!isExemptKernelUpdate &&
!isExemptHomeAssistantUpdate
if (
shouldCheckMassRebuild &&
isPossibleMassRebuild &&
!(rebuildsAllTests && isStagingNixosBase)
) {
return result('possible-mass-rebuild')
}
return result(
shouldSkipDevelopmentMerge ? 'skip-development-merge' : 'dismiss',
)
}
|