Skip to content

Commit 59e37ab

Browse files
committed
Use different SQLite versions in CI
1 parent 88dc27d commit 59e37ab

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

.github/workflows/phpunit-tests-run.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ on:
1717
required: false
1818
type: 'string'
1919
default: 'phpunit.xml.dist'
20+
sqlite:
21+
description: 'SQLite version to install (e.g., 3.24.0). Leave empty for latest version.'
22+
required: false
23+
type: 'string'
24+
default: 'latest'
2025
env:
2126
LOCAL_PHP: ${{ inputs.php }}-fpm
2227
PHPUNIT_CONFIG: ${{ inputs.phpunit-config }}
@@ -31,12 +36,42 @@ jobs:
3136
- name: Checkout repository
3237
uses: actions/checkout@v4
3338

39+
- name: Set up SQLite
40+
run: |
41+
VERSION='${{ inputs.sqlite }}'
42+
if [ "$VERSION" = 'latest' ]; then
43+
TAG='release'
44+
else
45+
TAG="version-${VERSION}"
46+
fi
47+
wget -O sqlite.tar.gz "https://sqlite.org/src/tarball/sqlite.tar.gz?r=${TAG}"
48+
tar xzf sqlite.tar.gz
49+
cd sqlite
50+
./configure --prefix=/usr/local CFLAGS="-DSQLITE_ENABLE_COLUMN_METADATA -DSQLITE_ENABLE_FTS5 -DSQLITE_USE_URI" LDFLAGS="-lm"
51+
make -j$(nproc)
52+
sudo make install
53+
sudo ldconfig
54+
3455
- name: Set up PHP
3556
uses: shivammathur/setup-php@v2
3657
with:
3758
php-version: '${{ inputs.php }}'
3859
tools: phpunit-polyfills
3960

61+
- name: Verify SQLite version in PHP
62+
run: |
63+
EXPECTED='${{ inputs.sqlite }}'
64+
if [ "$EXPECTED" = 'latest' ]; then
65+
EXPECTED=$(cat sqlite/VERSION)
66+
fi
67+
PDO=$(php -r "echo (new PDO('sqlite::memory'))->query('SELECT SQLITE_VERSION();')->fetch()[0];")
68+
echo "Expected SQLite version: $EXPECTED"
69+
echo "PHP PDO SQLite version: $PDO"
70+
if [ "$EXPECTED" != "$PDO" ]; then
71+
echo "Error: Expected SQLite version $EXPECTED, but PHP PDO uses $PDO"
72+
exit 1
73+
fi
74+
4075
- name: Install Composer dependencies
4176
uses: ramsey/composer-install@v3
4277
with:

.github/workflows/phpunit-tests.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88

99
jobs:
1010
test:
11-
name: PHP ${{ matrix.php }}
11+
name: PHP ${{ matrix.php }} / SQLite ${{ matrix.sqlite }}
1212
uses: ./.github/workflows/phpunit-tests-run.yml
1313
permissions:
1414
contents: read
@@ -18,8 +18,21 @@ jobs:
1818
matrix:
1919
os: [ ubuntu-latest ]
2020
php: [ '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5' ]
21+
include:
22+
# Add specific SQLite versions for specific PHP versions here:
23+
- php: '7.2'
24+
sqlite: '3.27.0' # minimum version with WP_SQLITE_UNSAFE_ENABLE_UNSUPPORTED_VERSIONS
25+
- php: '7.3'
26+
sqlite: '3.34.1' # Debian 11 (Bullseye), common with PHP < 8.1
27+
- php: '7.4'
28+
sqlite: '3.37.0' # minimum supported version (STRICT table support)
29+
- php: '8.0'
30+
sqlite: '3.40.1' # Debian 12 (Bookworm)
31+
- php: '8.1'
32+
sqlite: '3.46.1' # Debian 13 (Trixie), Ubuntu >= 24.10
2133

2234
with:
2335
os: ${{ matrix.os }}
2436
php: ${{ matrix.php }}
37+
sqlite: ${{ matrix.sqlite || 'latest' }}
2538
phpunit-config: ${{ 'phpunit.xml.dist' }}

tests/bootstrap.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
require_once __DIR__ . '/../wp-includes/sqlite/class-wp-sqlite-pdo-user-defined-functions.php';
99
require_once __DIR__ . '/../wp-includes/sqlite/class-wp-sqlite-translator.php';
1010

11+
// When on an older SQLite version, enable unsafe back compatibility.
12+
$sqlite_version = ( new PDO( 'sqlite::memory:' ) )->query( 'SELECT SQLITE_VERSION();' )->fetch()[0];
13+
if ( version_compare( $sqlite_version, WP_PDO_MySQL_On_SQLite::MINIMUM_SQLITE_VERSION, '<' ) ) {
14+
define( 'WP_SQLITE_UNSAFE_ENABLE_UNSUPPORTED_VERSIONS', true );
15+
}
16+
1117
// Configure the test environment.
1218
error_reporting( E_ALL );
1319
define( 'FQDB', ':memory:' );

0 commit comments

Comments
 (0)