-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathgenerate-stackbrew-library.jq
More file actions
141 lines (123 loc) · 3.19 KB
/
generate-stackbrew-library.jq
File metadata and controls
141 lines (123 loc) · 3.19 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
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
include "shared";
to_entries
| map_values(select(.)) # ignore nulls ("rc" post-GA)
| (
# our entries are in precedence order, so loop over them in order and assign "generic" tags like "1" to the first entry that might use them
reduce .[] as $v ({};
.[
$v.value.version
| if $v.key == "rc" then
# pre-releases get an intentionally limited set of tags
[
., # "1.13.0-alpha2"
(split(".")[0:2] | join(".") + "-rc"), # "1.13-rc"
"rc",
empty
]
else
# TODO should we add an explicit "stable" alias? for us, that's currently spelled "latest" and that's probably good enough?
# (see similar TODO in "versions.sh" about "lts")
split(".")
| [
foreach .[] as $c ([]; . += [ $c ])
| join(".")
]
| reverse + [ "" ]
end
| .[]
] //= $v.key
)
# now that object is backwards ({ "1": "stable", "1.X": "stable" }), so let's reduce it back the other way ({ "stable": [ "1", "1.X" ] }) so lookups are trivial below
| reduce to_entries[] as $e ({}; .[$e.value] += [ $e.key ])
) as $versionsTags
| (first(.[].value.variants[] | select(startswith("alpine") or startswith("windows/") | not)) // "") as $latestDebian
| (first(.[].value.variants[] | select(startswith("alpine"))) // "") as $latestAlpine
| .[]
| .key as $key
| .value
# only the major versions asked for "./generate-stackbrew-library.sh X Y ..."
| if $ARGS.positional != [] then
select(IN($key; $ARGS.positional[]))
else . end
| $versionsTags[$key] as $versionTags
| .variants[] as $variant # "trixie", "alpine3.22", "windows/servercore-ltsc2025", etc
# Tags:
| [
(
$variant
| if startswith("windows/servercore-") then
sub("/"; "")
elif startswith("windows/nanoserver-") then
ltrimstr("windows/")
else
.
end
),
if $variant == $latestAlpine then
"alpine"
else empty end,
empty
| $versionTags[] as $versionTag
| [ $versionTag, . | select(. != "") ]
| join("-")
| if . == "" then "latest" else . end
] as $tags
# SharedTags:
| [
(
$variant
| if startswith("windows/servercore-") then
"windowsservercore",
""
elif startswith("windows/nanoserver-") then
"nanoserver"
elif . == $latestDebian then
""
else empty end
),
empty
| $versionTags[] as $versionTag
| [ $versionTag, . | select(. != "") ]
| join("-")
| if . == "" then "latest" else . end
] as $sharedTags
# Architectures:
| (
.arches
| keys_unsorted
| if $variant | startswith("alpine") then
map(
select(startswith("alpine-"))
| ltrimstr("alpine-")
)
else . end
| (
$parentsArches[from($variant)]
// if $variant | startswith("windows/") then
[ "windows-amd64" ] # TODO windows-arm64v8 someday?
else [] end
) as $parentArches
| . - (. - $parentArches) # intersection
) as $arches
| (
"",
"Tags: \($tags | join(", "))",
if $sharedTags != [] then "SharedTags: \($sharedTags | join(", "))" else empty end,
"Directory: \($key)/\($variant)",
"Architectures: \($arches | join(", "))",
(
$variant
| if startswith("windows/") then
split("-")[-1] as $winver
| [
if startswith("windows/nanoserver-") then
"nanoserver-" + $winver
else empty end,
"windowsservercore-" + $winver,
empty
]
| "Constraints: " + join(", ")
else empty end
),
empty
)