Skip to content

Commit f7157d5

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 490ca55 commit f7157d5

File tree

1 file changed

+72
-9
lines changed

1 file changed

+72
-9
lines changed

.github/workflows/test.yml

+72-9
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,17 @@ jobs:
7373
- php: '8.4'
7474
skip_tests: true
7575

76+
# The default libxml library on Ubuntu images is a little out of date.
77+
# To safeguard support for the latest libxml we need to update the library on the fly.
78+
# This only needs to be tested with one PHP version for each libxml minor to verify support.
79+
# Testing against multiple PHP versions would not yield a difference in results.
80+
- php: '8.0'
81+
os: 'ubuntu-latest'
82+
libxml_minor: '2.11'
83+
- php: '8.3'
84+
os: 'ubuntu-latest'
85+
libxml_minor: '2.13'
86+
7687
# Extra builds running only the unit tests with different PHP ini settings.
7788
- php: '5.5'
7889
os: 'ubuntu-latest'
@@ -82,7 +93,7 @@ jobs:
8293
custom_ini: true
8394

8495
# yamllint disable-line rule:line-length
85-
name: "PHP: ${{ matrix.php }} ${{ matrix.custom_ini && ' with custom ini settings' || '' }} (${{ matrix.os == 'ubuntu-latest' && 'Linux' || 'Win' }})"
96+
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' }})"
8697

8798
continue-on-error: ${{ matrix.php == '8.5' }}
8899

@@ -93,18 +104,67 @@ jobs:
93104
- name: Checkout code
94105
uses: actions/checkout@v4
95106

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

193+
- name: "DEBUG: show libxml loaded version (php)"
194+
run: php -r 'echo "libxml loaded version = ", LIBXML_LOADED_VERSION, PHP_EOL;'
195+
133196
# This action also handles the caching of the dependencies.
134197
- name: Set up node
135198
if: ${{ matrix.custom_ini == false }}

0 commit comments

Comments
 (0)