Skip to content
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

GH Action: Add steps to test against libxml >= 2.12 #798

Closed

Conversation

asispts
Copy link
Contributor

@asispts asispts commented Jan 25, 2025

Description

Follow up of #797.

I've update GH action to run tests against libxml >= 2.12. Also, I added fail-fast: false to ensure that other matrix jobs continue running until completion.

Note

Since libxml >= 2.12 is not available in ubuntu-latest, the library is compiled from source.

Suggested changelog entry

Related issues/external references

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
    • This change is only breaking for integrators, not for external standards or end-users.
  • Documentation improvement

PR checklist

  • I have checked there is no other PR open for the same change.
  • I have read the Contribution Guidelines.
  • I grant the project the right to include and distribute the code under the BSD-3-Clause license (and I have the right to grant these rights).
  • I have added tests to cover my changes.
  • I have verified that the code complies with the projects coding standards.
  • [Required for new sniffs] I have added XML documentation for the sniff.

@jrfnl
Copy link
Member

jrfnl commented Jan 25, 2025

@asispts Would you mind rebasing this PR ? as it needs the changes from #797 (now merged) to allow the build to pass.

@asispts asispts force-pushed the bugfix/issue-767-action branch from ee93a6a to bcc81fc Compare January 26, 2025 03:31
@asispts
Copy link
Contributor Author

asispts commented Jan 26, 2025

@jrfnl done

Copy link
Member

@jrfnl jrfnl left a comment

Choose a reason for hiding this comment

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

Thank you for working on this @asispts ! I really appreciate your help in stabilizing this part of the test suite and safeguarding the functionality in different circumstances.

I do have some questions and remarks, which I've left in line. Questions do not necessarily imply something needs to change. In most cases, I'd just like to understand the reasoning why.

@@ -93,6 +96,20 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4

# A temporary solution
- name: Install libxml2 >= 2.12 (PHP 8.1+ on linux only)
if: ${{ matrix.os == 'ubuntu-latest' && contains(fromJSON('["8.1", "8.2", "8.3"]'), matrix.php) }}
Copy link
Member

Choose a reason for hiding this comment

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

I have a number of question about this:

  1. Does this have to be tested on multiple PHP versions or would testing on a single PHP 8.1+ version be sufficient ? (the compile from scratch slows the build down with ~45-60 second extra build time)
  2. How was it decided to test against PHP 8.1, 8.2 and 8.3, but not against PHP 8.4 or 8.5 ?

Copy link
Member

Choose a reason for hiding this comment

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

As for the usability/comprehension of failures if/when they would occur:
As things are, if a build using libxml 2.12 would fail, it is not transparent for a non-regular contributor that libxml 2.12 is being used and may be the cause of the failure. They would have to study the workflow to figure that out.

Did you consider making the use of libxml 2.12 a matrix flag ? And if you considered this, what was the reason to decide against that ?
Note: if it would be a matrix flag, that would also allow for annotating that libxml 2.12 is being used for a certain job in the job name.

Copy link
Member

Choose a reason for hiding this comment

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

Last question: not sure if that would work, but did you consider/have you tried installing libxml 2.12 via the extensions key in the setup-php action runner ?
Ref: https://github.com/shivammathur/setup-php?tab=readme-ov-file#heavy_plus_sign-php-extension-support

Copy link
Contributor Author

@asispts asispts Jan 27, 2025

Choose a reason for hiding this comment

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

@jrfnl The issue is related to libxml2 library, not the PHP libxml extension.

I've added a comment to explain why is this a temporary solution. Also, I used homebrew, as suggested by @derrabus, to install latest libxml2 version and remove the hardcoded version.

Copy link
Member

@jrfnl jrfnl Jan 28, 2025

Choose a reason for hiding this comment

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

@asispts Thanks for your continued work on this.

While my last question (third comment here) has been answered, the questions posed in my first two comments have not yet been answered and I'd still be interested to understand the reasoning for the current choices.

@jrfnl jrfnl added this to the 3.12.0 milestone Jan 26, 2025
@derrabus
Copy link

Compiling libxml2 on each build sounds expensive. Would it be faster to use Homebrew for the installation? Also, do we need to test with every PHP version? Wouldn't it be enough if we installed the custom libxml2 only on let's say PHP 8.4 and use Ubuntu's bundled libxml2 for the other builds?

@asispts asispts force-pushed the bugfix/issue-767-action branch from 7249a25 to ad85bfa Compare January 28, 2025 14:03
@jrfnl
Copy link
Member

jrfnl commented Jan 28, 2025

Observation: by the looks of it, installing Homebrew and then installing libxml via Homebrew is only marginally faster and at times significantly slower than building from scratch.

Some Homebrew based builds:

versus some install from scratch based builds:

@derrabus
Copy link

Observation: by the looks of it, installing Homebrew and then installing libxml via Homebrew is only marginally faster and at times significantly slower than building from scratch.

According to https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2404-Readme.md, Homebrew should already be present on the Ubuntu images from GitHub Actions. So we should not need to install Homebrew itself.

@asispts
Copy link
Contributor Author

asispts commented Jan 28, 2025

@derrabus Thanks. I've used that one.

@jrfnl @fredden I've also simplified the steps.

@derrabus
Copy link

Can we output the libxml version that PHP uses? I doubt that simply installing libxml will make PHP magically pick it up.

php -r 'echo LIBXML_DOTTED_VERSION . PHP_EOL;'

Worst case, we need to compile PHP against that libxml version ourselves. 😓

@jrfnl
Copy link
Member

jrfnl commented Jan 29, 2025

Can we output the libxml version that PHP uses? I doubt that simply installing libxml will make PHP magically pick it up.

php -r 'echo LIBXML_DOTTED_VERSION . PHP_EOL;'

Worst case, we need to compile PHP against that libxml version ourselves. 😓

@derrabus Interestingly enough, it appears it does (magically pick it up).

This can be seen via the test failure of the builds for the original push: https://github.com/PHPCSStandards/PHP_CodeSniffer/actions/runs/12965930622/job/36168409300
Only after rebasing to include merged PR #797, did the test runs using libxml 2.12 pass.

I agree though that it wouldn't be a bad thing to have a debug step which outputs the version found.

@jrfnl
Copy link
Member

jrfnl commented Feb 6, 2025

Okay, for lack of answers to some of my questions about this PR and because I want to be sure that after all the updates to the PR, this still safeguards things properly, I've done some stress-testing.

These are the steps I took and my findings:

  • First off, using PHP 8.4 for this check is problematic as the tests are not being run on PHP 8.4 in the test job (as they are run in the code-coverage job instead), so I first changed the condition to install the updated version of libxml on PHP 8.3.
    Expected: passing build
    Result: passing build ✔️
  • With a passing build for that, I then reverted the changes from Tests: Fix libxml >= 2.12 compatibility #797 to verify that the build would fail correctly.
    Expected: failing build
    Result: passing build ❌ In other words: installing via homebrew does not get PHP to use the updated version of libxml. /cc @derrabus
  • Next, I changed the step to install libxml back to the script in commit bcc81fc which compiles libxml. The changes from Tests: Fix libxml >= 2.12 compatibility #797 are still reverted.
    Expected: failing build
    Result: failing build ✔️ Okay, so this way of updating libxml actually ensures that PHP uses this version.
  • Now, I reapplied the changes from Tests: Fix libxml >= 2.12 compatibility #797.
    Expected: passing build
    Result: passing build ✔️

I also tried to add a "DEBUG" step to get insight into the libxml version which is being used.
Unfortunately, using php -r 'echo "libxml version = ", LIBXML_DOTTED_VERSION, PHP_EOL;' does not work as it will always show the libxml version with which PHP was compiled, even when a newer libxml version is available on the system and is actually being used. /cc @fredden

While it is an extra step, installing xmllint and running xmllint --version will allow for displaying and verifying the real system version of libxml being used.

As the above means, we can't use homebrew to always get the latest libxml, we're back to using hard-coded versions, which is not great for maintenance.

My current thinking on this, is to explore using the GH API to retrieve the latest tag for the https://github.com/GNOME/libxml2 repo and see if we can get that working.

In the mean time, I think moving the hard-coded version from the update step to the matrix and having one PHP 8.* build run against libxml 2.12 and one against libxml 2.13 might be the best idea for now.

Having said that, the default version of libxml on ubuntu-latest appears to be 2.9.14, so maybe spreading the versions might even make sense. I.e. most builds use the default, one build uses a version in between (2.11) and one build uses the latest version 2.13.

Having the version in the matrix (or an update flag if we'd get the version via the GH API) will also allow for adding a note in the build name to draw attention to the different libxml version being used for select builds, making it more straight-forward to understand what's going on when a build fails.

@jrfnl
Copy link
Member

jrfnl commented Feb 6, 2025

@asispts Just checking - it looks like I can't push to your branch ? If you want to see the things I tested and the commits for some of the changes I envision for this PR, you can have a look here to see the code changes I made for the above tests: https://github.com/jrfnl/PHP_CodeSniffer/commits/asispts/bugfix/issue-767-action/

@fredden
Copy link
Member

fredden commented Feb 15, 2025

Unfortunately, using php -r 'echo "libxml version = ", LIBXML_DOTTED_VERSION, PHP_EOL;' does not work as it will always show the libxml version with which PHP was compiled, even when a newer libxml version is available on the system and is actually being used.

I've done some testing just now. From what I can tell, LIBXML_VERSION and LIBXML_DOTTED_VERSION both reflect the version of libxml which was used at compile time, whereas LIBXML_LOADED_VERSION shows the version that is currently in use. So this should work: php -r 'echo "LIBXML_LOADED_VERSION = ", LIBXML_LOADED_VERSION, PHP_EOL;'
It's not as pretty as the dotted variant, but it seems to show the correct information.

@jrfnl
Copy link
Member

jrfnl commented Feb 20, 2025

So this should work: php -r 'echo "LIBXML_LOADED_VERSION = ", LIBXML_LOADED_VERSION, PHP_EOL;' It's not as pretty as the dotted variant, but it seems to show the correct information.

Thanks @fredden, I can confirm that LIBXML_LOADED_VERSION works and would remove the need to install xmllint.

@asispts Just checking - do you still want to continue with this PR ? I'd like to get it merged in the same release as #797 as this would allow to safeguard cross-version support for various libxml versions via CI.

If you don't have the time or intention to finish this, please just let me know and I'll get it sorted out before the release myself.

@jrfnl
Copy link
Member

jrfnl commented Feb 27, 2025

For lack of response/progress on this PR, I've now opened PR #849 which brings the work done in this PR into a mergeable state. Feedback welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants