Skip to content

Commit e2040ed

Browse files
committed
GH Actions/test: iterate on libxml installation steps
This commit updates the initial implementation for updating `libxml2` on the fly for select PHP versions. Compared to the original implementation, the following changes were made: * Use a `libxml_minor` flag in the matrix to indicate whether `libxml` should be updated for a particular job or not. This `libxml_minor` flag also allows for specifying a specific minor to use for the update. This flag is now set on the linux PHP 8.0 and PHP 8.3 builds. _Take note: PHP 8.4 is explicitly not used, as the tests are not run in this job for that version (they are run in the `coverage` job instead)._ _In effect that meant that installing `libxml` on PHP 8.4 in the workflow, as per the original PR, wasn't safeguarding anything as without tests running, the tests couldn't fail._ * Based on the `libxml_minor` flag, update the job name to make it clear when a particular job uses a non-default `libxml` version. * On the fly figure out what the latest relevant tag is for a certain `libxml` minor. This makes the workflow more flexible by: - Allowing for different minors. - Prevents having a specific patch version hard-coded in the workflow (maintenance issue). * Splits the `sudo apt-get update` command off to its own step as it is prone to intermittent failures. * Splits the "Install" step into two steps: one to download and compile, one to install the newly compiled `libxml` version. Doing this allows for caching the result of the compile step, diminishing the impact on the actions run time of compiling `libxml`. * Adds an (unconditional) "debug" step to allow for verifying which `libxml` version is being used in each job.
1 parent 33e794f commit e2040ed

File tree

1 file changed

+72
-9
lines changed

1 file changed

+72
-9
lines changed

.github/workflows/test.yml

Lines changed: 72 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,24 @@ jobs:
6565
- php: '8.4'
6666
skip_tests: true
6767

68+
# The default libxml library on Ubuntu images is a little out of date.
69+
# To safeguard support for the latest libxml we need to update the library on the fly.
70+
# This only needs to be tested with one PHP version for each libxml minor to verify support.
71+
# Testing against multiple PHP versions would not yield a difference in results.
72+
- php: '8.0'
73+
os: 'ubuntu-latest'
74+
libxml_minor: '2.11'
75+
- php: '8.3'
76+
os: 'ubuntu-latest'
77+
libxml_minor: '2.13'
78+
6879
# Extra builds running only the unit tests with different PHP ini settings.
6980
- php: '7.4'
7081
os: 'ubuntu-latest'
7182
custom_ini: true
7283

7384
# yamllint disable-line rule:line-length
74-
name: "PHP: ${{ matrix.php }} ${{ matrix.custom_ini && ' with custom ini settings' || '' }} (${{ matrix.os == 'ubuntu-latest' && 'Linux' || 'Win' }})"
85+
name: "PHP: ${{ matrix.php }} ${{ matrix.custom_ini && ' with custom ini settings' || '' }}${{ matrix.libxml_minor && format( ' with libxml {0}', matrix.libxml_minor ) || '' }} (${{ matrix.os == 'ubuntu-latest' && 'Linux' || 'Win' }})"
7586

7687
continue-on-error: ${{ matrix.php == '8.5' }}
7788

@@ -82,18 +93,67 @@ jobs:
8293
- name: Checkout code
8394
uses: actions/checkout@v4
8495

85-
# This is a temporary solution.
86-
# Once ubuntu-latest includes the latest libxml2 version, this step can be removed.
87-
- name: Install latest libxml2 on PHP 8.4 (linux only)
88-
if: ${{ matrix.os == 'ubuntu-latest' && matrix.php == '8.4' }}
96+
- name: "libxml2: find the latest relevant tag"
97+
if: ${{ matrix.libxml_minor }}
98+
id: libxml_version
99+
uses: oprypin/find-latest-tag@v1
100+
with:
101+
repository: GNOME/libxml2
102+
releases-only: false # The libxml2 repository doesn't use GitHub's "release" feature.
103+
prefix: 'v${{ matrix.libxml_minor }}.' # Limit the result to the minor we're interested in.
104+
sort-tags: true # Find the "greatest" version for that minor based on semver.
105+
106+
# To put it simply: we need to remove the 'v' prefix from the version number.
107+
- name: "libxml2: parse the version to a patch version"
108+
if: ${{ matrix.libxml_minor }}
109+
id: libxml_patch_version
110+
shell: bash
111+
env:
112+
TAG: ${{ steps.libxml_version.outputs.tag }}
113+
run: echo "PATCH=$( echo "$TAG" | cut -b 2- )" >> "$GITHUB_OUTPUT"
114+
115+
- name: "libxml2: restore cache"
116+
if: ${{ matrix.libxml_minor }}
117+
id: libxml_cache_restore
118+
uses: actions/cache/restore@v4
119+
with:
120+
path: "libxml2-${{ steps.libxml_patch_version.outputs.PATCH }}"
121+
key: "${{ matrix.os }}-libxml-${{ matrix.libxml_minor }}-${{ steps.libxml_patch_version.outputs.PATCH }}"
122+
123+
# Updating the lists can fail intermittently, typically after Microsoft has released a new package.
124+
# This should not be blocking for this job, so ignore any errors from this step.
125+
# Ref: https://github.com/dotnet/core/issues/4167
126+
- name: "libxml2: Update the available packages list"
127+
if: ${{ matrix.libxml_minor && steps.libxml_cache_restore.outputs.cache-hit != 'true' }}
128+
continue-on-error: true
129+
run: sudo apt-get update
130+
131+
- name: "libxml2: Download and build package (linux only)"
132+
if: ${{ matrix.libxml_minor && steps.libxml_cache_restore.outputs.cache-hit != 'true' }}
133+
env:
134+
PATCH: ${{ steps.libxml_patch_version.outputs.PATCH }}
89135
run: |
90-
sudo apt-get update
91136
sudo apt-get install -y wget build-essential
92-
wget https://download.gnome.org/sources/libxml2/2.12/libxml2-2.12.9.tar.xz
93-
tar -xf libxml2-2.12.9.tar.xz
94-
cd libxml2-2.12.9
137+
wget "https://download.gnome.org/sources/libxml2/${{ matrix.libxml_minor }}/libxml2-$PATCH.tar.xz"
138+
tar -xf "libxml2-$PATCH.tar.xz"
139+
cd "libxml2-$PATCH"
95140
./configure --prefix=/usr/local
96141
make
142+
143+
- name: "libxml2: save cache"
144+
if: ${{ matrix.libxml_minor && steps.libxml_cache_restore.outputs.cache-hit != 'true' }}
145+
id: libxml_cache_save
146+
uses: actions/cache/save@v4
147+
with:
148+
path: "libxml2-${{ steps.libxml_patch_version.outputs.PATCH }}"
149+
key: ${{ steps.libxml_cache_restore.outputs.cache-primary-key }}
150+
151+
- name: "libxml2: Install package (linux only)"
152+
if: ${{ matrix.libxml_minor }}
153+
env:
154+
PATCH: ${{ steps.libxml_patch_version.outputs.PATCH }}
155+
run: |
156+
cd "libxml2-$PATCH"
97157
sudo make install
98158
sudo ldconfig
99159
@@ -117,6 +177,9 @@ jobs:
117177
coverage: none
118178
tools: cs2pr
119179

180+
- name: "DEBUG: show libxml loaded version (php)"
181+
run: php -r 'echo "libxml loaded version = ", LIBXML_LOADED_VERSION, PHP_EOL;'
182+
120183
# Install dependencies and handle caching in one go.
121184
# @link https://github.com/marketplace/actions/install-php-dependencies-with-composer
122185
- name: Install Composer dependencies

0 commit comments

Comments
 (0)