Skip to content

update.sh: use version id for version comparison #1040

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

smola
Copy link

@smola smola commented Jul 25, 2020

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

@smola
Copy link
Author

smola commented Jul 25, 2020

This doesn't make a difference for the current set of supported versions, but I hope it prevents problems once we have multiple versions for both 7.x and 8.x. It made my work a bit simpler when supporting 5.x too.

@yosifkit
Copy link
Member

Thanks for the contribution! This definitely seems like a good idea. 👍

I'd rather have a version ID function so that the if statements can be easier to read by still using a regular version number like 7.2.1, 7.2, 8. If you like, I can take it from here, but you are welcome to do so.

My rough idea would be something like if [ "$versionId" -lt "$(asVersionId '7.2')" ]

@smola
Copy link
Author

smola commented Aug 13, 2020

@yosifkit Sounds good. I added a function as_version_id (to keep same naming convention) which accepts versions with 1, 2 or 3 components.

Copy link
Member

@yosifkit yosifkit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything else looks great to me. 👍

update.sh Outdated
as_version_id() {
local fullVersion="$1"
# strip prelease suffix
fullVersion="${fullVersion/[a-z]*/}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MIght be safer to use "${fullVersion%[a-z]*}" so that it only matches the end?

update.sh Outdated
# sodium is part of php core 7.2+ https://wiki.php.net/rfc/libsodium
sed -ri '/sodium/d' "$version/$suite/$variant/Dockerfile"
fi
if [ "$variant" = 'fpm' -a "$majorVersion" = '7' -a "$minorVersion" -lt '3' ]; then
if [ "$variant" = 'fpm' -a "$versionId" -lt '70300' ]; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed one 😉.

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 <admwiggin@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants