-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.groovy
More file actions
executable file
·82 lines (73 loc) · 2.42 KB
/
script.groovy
File metadata and controls
executable file
·82 lines (73 loc) · 2.42 KB
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
#!groovy
// println("hello world!")
def userInput = [
axes: [
[
name: 'PYTHON_VERSION',
values: ['3.11', '3.12','3.13']
],
[
name: 'OS',
values: ['linux','macos','windows']
],
[
name: 'ARCHITECTURE',
values: ['x86_64', 'arm64']
],
[
name: 'PACKAGE_TYPE',
values: ['wheel', 'sdist'],
]
],
excludes: [
[
[
name: 'OS',
values: 'windows'
],
[
name: 'ARCHITECTURE',
values: ['arm64'],
]
]
]
]
// Function to generate all permutations, with support for exclusion lists
def generatePermutations(List<Map> inputMaps, List<List<Map>> exclusions = []) {
// Generate all possible combinations from the input maps
def combinations = getCombinations(inputMaps)
// Filter combinations based on exclusions
def filteredCombinations = combinations.findAll { combination ->
// Check each exclusion list to see if any of the combinations should be excluded
!exclusions.any { exclusionList ->
exclusionList.every { exclusion ->
def mapInCombination = combination.find { it.name == exclusion.name }
// If exclusion value is a list, check if the value is in the exclusion list
if (exclusion.values instanceof List) {
return exclusion.values.contains(mapInCombination?.value)
}
// If exclusion value is a single string, check if the value matches the exclusion
else {
return mapInCombination?.value == exclusion.values
}
}
}
}
return filteredCombinations
}
// Helper function to generate all combinations of values
def getCombinations(List<Map> maps) {
// Start with a list containing an empty map
def result = [[]]
maps.each { map ->
def tempResult = []
map.values.each { value ->
result.each { combination ->
tempResult.add(combination + [name: map.name, value: value])
}
}
result = tempResult
}
return result
}
def permutations = generatePermutations(userInput.axes, userInput.excludes).collect(row -> row.collectEntries{ element -> [element.name, element.value]})