-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfilter.js
More file actions
55 lines (46 loc) · 1.69 KB
/
Copy pathfilter.js
File metadata and controls
55 lines (46 loc) · 1.69 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
import process from 'node:process'
import fs from 'node:fs/promises'
import path from 'path'
function printUsage () {
console.error("Usage: node filter.js [path to repo] [JSON list of versions]")
process.exit(1)
}
const repoArg = process.argv[2]
const versionsArg = process.argv[3]
if (!repoArg || !versionsArg) {
printUsage()
}
const distros = new Set(["fedora", "rhel8", "rhel9", "rhel10", "rhel11", "c9s", "c10s", "c11s"])
let matrix = []
let versions
try {
versions = JSON.parse(versionsArg)
} catch (err) {
printUsage()
}
if (!Array.isArray(versions)) {
printUsage()
}
// wait for all iterations of loop to finish
await Promise.all(versions.map(async version => {
let files = []
try {
files = await fs.readdir(path.join(repoArg, version))
} catch (err) {
// if a directory for a version doesn't exist, we don't need to test anything there
// aka every distro here is added to the exclude matrix
}
const presentDistros = new Set(files.filter(name => name.startsWith("Dockerfile."))
.map(name => name.split(".")[1]))
const excludedDistros = new Set(files.filter(name => name.startsWith(".exclude-"))
.map(name => name.split("-")[1]))
// union of excluded distros and the ones not present; filtered to only contain real distros (e.g. no c8s)
const missingDistros = distros.intersection(excludedDistros.union(distros.difference(presentDistros)))
missingDistros.forEach(distro => {
matrix.push({"version": version, "os_test": distro})
if (distro.startsWith("rhel")) {
matrix.push({"version": version, "os_test": `${distro}-unsubscribed`})
}
})
}))
console.log(JSON.stringify(matrix))