-
Notifications
You must be signed in to change notification settings - Fork 93
/
versions.sh
executable file
·62 lines (51 loc) · 1.57 KB
/
versions.sh
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
#!/usr/bin/env bash
set -Eeuo pipefail
supportedNodeVersions=(
20
18
)
supportedAlpineVersions=(
3.19
3.18
)
defaultNodeVersion="${supportedNodeVersions[0]}"
defaultAlpineVersion="${supportedAlpineVersions[0]}"
versions=( "$@" )
if [ ${#versions[@]} -eq 0 ]; then
versions=( */ )
json='{}'
else
json="$(< versions.json)"
fi
versions=( "${versions[@]%/}" )
upstreamVersions=$(wget -qO- 'https://registry.npmjs.org/mongo-express' | jq -r '.versions | keys | .[]')
for version in "${versions[@]}"; do
export version
versionPattern="^${version/\./\\.}\.[0-9]*$"
filteredVersions=($(printf "%s\n" ${upstreamVersions[*]} | grep -E "${versionPattern}"))
fullVersion="${filteredVersions[${#filteredVersions[@]}-1]}"
echo "$version: $fullVersion"
export fullVersion="$fullVersion"
export nodeVersion="${supportedNodeVersions[${#supportedNodeVersions[@]}-1]}"
export alpineVersion="${supportedAlpineVersions[${#supportedAlpineVersions[@]}-1]}"
for node in "${supportedNodeVersions[@]}"; do
variants+=( "${supportedAlpineVersions[@]/#/$node-alpine}" )
done
doc='{}'
for variant in "${variants[@]}"; do
doc="$(jq <<<"$doc" -c --arg v "$variant" '
.variants += [ $v ]
')"
done
unset variants
# TODO: Add way to pin default Node and Alpine for specific versions
json="$(jq <<<"$json" -c --argjson doc "$doc" '
.[env.version] = ({
version: env.fullVersion,
node: env.nodeVersion,
alpine: env.alpineVersion,
variants: $doc.variants
})
')"
done
jq <<<"$json" -S . > versions.json