Skip to content

Commit e97b328

Browse files
smolatianon
andcommitted
update.sh: use version id for version comparison
Use version id (single integer) for version comparisons. This is clearer and less error prone than combining conditions on major and minor. The convention used is the same as PHP_VERSION_ID, which is standard since PHP 5.2.7 and commonly used for simple version comparisons. See: https://www.php.net/manual/en/function.phpversion.php Co-authored-by: Tianon Gravi <[email protected]>
1 parent 098e442 commit e97b328

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

update.sh

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,21 @@ generated_warning() {
4545
EOH
4646
}
4747

48+
# Equivalent to PHP's PHP_VERSION_ID:
49+
# 5.6.10 => 50610, 7.1.0 => 70100
50+
as_version_id() {
51+
local fullVersion="$1"
52+
# strip prelease suffix
53+
fullVersion="${fullVersion%%[a-z]*}"
54+
local IFS='.'
55+
local components=( $fullVersion )
56+
printf '%d%02d%02d' "${components[0]}" "${components[1]:-0}" "${components[2]:-0}"
57+
}
58+
4859
travisEnv=
4960
for version in "${versions[@]}"; do
5061
rcVersion="${version%-rc}"
5162

52-
# "7", "5", etc
53-
majorVersion="${rcVersion%%.*}"
54-
# "2", "1", "6", etc
55-
minorVersion="${rcVersion#$majorVersion.}"
56-
minorVersion="${minorVersion%%.*}"
57-
5863
# scrape the relevant API based on whether we're looking for pre-releases
5964
apiUrl="https://www.php.net/releases/index.php?json&max=100&version=${rcVersion%%.*}"
6065
apiJqExpr='
@@ -107,6 +112,8 @@ for version in "${versions[@]}"; do
107112
sha256="${possi[3]}"
108113
md5="${possi[4]}"
109114

115+
versionId="$(as_version_id "$fullVersion")"
116+
110117
gpgKey="${gpgKeys[$rcVersion]}"
111118
if [ -z "$gpgKey" ]; then
112119
echo >&2 "ERROR: missing GPG key fingerprint for $version"
@@ -151,7 +158,7 @@ for version in "${versions[@]}"; do
151158
if [ "$variant" = 'apache' ]; then
152159
cp -a apache2-foreground "$version/$suite/$variant/"
153160
fi
154-
if [ "$majorVersion" = '7' -a "$minorVersion" -lt '2' ]; then
161+
if [ "$versionId" -lt "$(as_version_id 7.2)" ]; then
155162
# argon2 password hashing is only supported in 7.2+
156163
sed -ri \
157164
-e '/##<argon2-stretch>##/,/##<\/argon2-stretch>##/d' \
@@ -163,36 +170,36 @@ for version in "${versions[@]}"; do
163170
-e '/##<argon2-stretch>##/,/##<\/argon2-stretch>##/d' \
164171
"$version/$suite/$variant/Dockerfile"
165172
fi
166-
if [ "$majorVersion" = '7' -a "$minorVersion" -lt '4' ]; then
173+
if [ "$versionId" -lt "$(as_version_id 7.4)" ]; then
167174
# oniguruma is part of mbstring in php 7.4+
168175
sed -ri \
169176
-e '/oniguruma-dev|libonig-dev/d' \
170177
"$version/$suite/$variant/Dockerfile"
171178
fi
172-
if [ "$majorVersion" -ge '8' ]; then
179+
if [ "$versionId" -ge "$(as_version_id 8.0)" ]; then
173180
# 8 and above no longer include pecl/pear (see https://github.com/docker-library/php/issues/846#issuecomment-505638494)
174181
sed -ri \
175182
-e '/pear |pearrc|pecl.*channel/d' \
176183
"$version/$suite/$variant/Dockerfile"
177184
fi
178-
if [ "$majorVersion" != '7' ] || [ "$minorVersion" -lt '4' ]; then
179-
# --with-pear is only relevant on PHP 7, and specifically only 7.4+ (see https://github.com/docker-library/php/issues/846#issuecomment-505638494)
185+
if [ "$versionId" -lt "$(as_version_id 7.4)" ]; then
186+
# --with-pear is only relevant on PHP 7.4+ (see https://github.com/docker-library/php/issues/846#issuecomment-505638494)
180187
sed -ri \
181188
-e '/--with-pear/d' \
182189
"$version/$suite/$variant/Dockerfile"
183190
fi
184-
if [ "$majorVersion" = '7' -a "$minorVersion" -lt '2' ]; then
191+
if [ "$versionId" -lt "$(as_version_id 7.2)" ]; then
185192
# sodium is part of php core 7.2+ https://wiki.php.net/rfc/libsodium
186193
sed -ri '/sodium/d' "$version/$suite/$variant/Dockerfile"
187194
fi
188-
if [ "$variant" = 'fpm' -a "$majorVersion" = '7' -a "$minorVersion" -lt '3' ]; then
195+
if [ "$variant" = 'fpm' -a "$versionId" -lt "$(as_version_id 7.3)" ]; then
189196
# php-fpm "decorate_workers_output" is only available in 7.3+
190197
sed -ri \
191198
-e '/decorate_workers_output/d' \
192199
-e '/log_limit/d' \
193200
"$version/$suite/$variant/Dockerfile"
194201
fi
195-
if [ "$suite" = 'stretch' ] || [ "$majorVersion" -gt '7' ] || { [ "$majorVersion" = '7' ] && [ "$minorVersion" -ge '4' ]; }; then
202+
if [ "$suite" = 'stretch' ] || [ "$versionId" -ge "$(as_version_id 7.4)" ]; then
196203
# https://github.com/docker-library/php/issues/865
197204
# https://bugs.php.net/bug.php?id=76324
198205
# https://github.com/php/php-src/pull/3632
@@ -201,13 +208,13 @@ for version in "${versions[@]}"; do
201208
-e '/freetype-config/d' \
202209
"$version/$suite/$variant/Dockerfile"
203210
fi
204-
if [[ "$suite" == alpine* ]] && [ "$majorVersion" = '7' ] && [ "$minorVersion" -lt '4' ]; then
211+
if [[ "$suite" == alpine* ]] && [ "$versionId" -lt "$(as_version_id 7.4)" ]; then
205212
# https://github.com/docker-library/php/issues/888
206213
sed -ri \
207214
-e '/linux-headers/d' \
208215
"$version/$suite/$variant/Dockerfile"
209216
fi
210-
if [ "$majorVersion" -lt '8' ]; then
217+
if [ "$versionId" -lt "$(as_version_id 8.0)" ]; then
211218
# https://github.com/php/php-src/commit/161adfff3f437bf9370e037a9e2bf593c784ccff
212219
sed -ri \
213220
-e 's/--enable-zts/--enable-maintainer-zts/g' \

0 commit comments

Comments
 (0)