-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathversions.sh
More file actions
executable file
·125 lines (112 loc) · 3.03 KB
/
versions.sh
File metadata and controls
executable file
·125 lines (112 loc) · 3.03 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
#!/usr/bin/env bash
set -Eeuo pipefail
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
# TODO consume https://www.php.net/releases/branches.php and https://www.php.net/release-candidates.php?format=json here like in Go, Julia, etc (so we can have a canonical "here's all the versions possible" mode, and more automated metadata like EOL 👀)
versions=( "$@" )
if [ ${#versions[@]} -eq 0 ]; then
versions=( */ )
json='{}'
else
json="$(< versions.json)"
fi
versions=( "${versions[@]%/}" )
for version in "${versions[@]}"; do
rcVersion="${version%-rc}"
export version rcVersion
# scrape the relevant API based on whether we're looking for pre-releases
if [ "$rcVersion" = "$version" ]; then
apiUrl="https://www.php.net/releases/index.php?json&max=100&version=${rcVersion%%.*}"
apiJqExpr='
(keys[] | select(startswith(env.rcVersion))) as $version
| [ $version, (
.[$version].source[]
| select(.filename | endswith(".xz"))
|
"https://www.php.net/distributions/" + .filename,
"https://www.php.net/distributions/" + .filename + ".asc",
.sha256 // ""
) ]
'
else
apiUrl='https://www.php.net/release-candidates.php?format=json'
apiJqExpr='
(.releases // [])[]
| select(.version | startswith(env.rcVersion))
| [
.version,
.files.xz.path // "",
"",
.files.xz.sha256 // ""
]
'
fi
IFS=$'\n'
possibles=( $(
curl -fsSL "$apiUrl" \
| jq --raw-output "$apiJqExpr | @sh" \
| sort -rV
) )
unset IFS
if [ "${#possibles[@]}" -eq 0 ]; then
echo >&2 "warning: skipping/removing '$version' (does not appear to exist upstream)"
json="$(jq <<<"$json" -c '.[env.version] = null')"
continue
fi
# format of "possibles" array entries is "VERSION URL.TAR.XZ URL.TAR.XZ.ASC SHA256" (each value shell quoted)
# see the "apiJqExpr" values above for more details
eval "possi=( ${possibles[0]} )"
fullVersion="${possi[0]}"
url="${possi[1]}"
ascUrl="${possi[2]}"
sha256="${possi[3]}"
if ! curl --head -fsSL "$url" -o /dev/null; then
echo >&2 "error: '$url' appears to be missing"
exit 1
fi
# if we don't have a .asc URL, let's just assume one :)
if [ -z "$ascUrl" ]; then
ascUrl="$url.asc"
fi
echo "$version: $fullVersion"
export fullVersion url ascUrl sha256
json="$(
jq <<<"$json" -c '
.[env.version] = {
version: env.fullVersion,
url: env.url,
ascUrl: env.ascUrl,
sha256: env.sha256,
variants: [
# order here controls the order of the library/ file
(
"trixie",
"bookworm",
"alpine3.23",
"alpine3.22",
empty
) as $suite
| (
"cli",
"apache",
"fpm",
"zts",
empty
) as $variant
| if $suite | startswith("alpine") and $variant == "apache" then empty else
"\($suite)/\($variant)"
end
],
}
'
)"
# make sure RCs and releases have corresponding pairs
json="$(jq <<<"$json" -c '
.[
env.version
+ if env.version == env.rcVersion then
"-rc"
else "" end
] //= null
')"
done
jq <<<"$json" 'to_entries | sort_by(.key) | from_entries' > versions.json