Add PostgreSQL backend scaffolding #1327
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: PHPUnit Tests | |
| on: | |
| push: | |
| branches: | |
| - trunk | |
| paths: | |
| - '.github/workflows/phpunit-tests.yml' | |
| - 'packages/mysql-on-sqlite/**' | |
| - 'packages/php-ext-wp-mysql-parser/**' | |
| - 'composer.json' | |
| - 'composer.lock' | |
| pull_request: | |
| paths: | |
| - '.github/workflows/phpunit-tests.yml' | |
| - 'packages/mysql-on-sqlite/**' | |
| - 'packages/php-ext-wp-mysql-parser/**' | |
| - 'composer.json' | |
| - 'composer.lock' | |
| workflow_dispatch: | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| # Disable permissions for all available scopes by default. | |
| # Any needed permissions should be configured at the job level. | |
| permissions: {} | |
| jobs: | |
| test: | |
| # The pure-PHP parser is exercised across the full PHP/SQLite range; the | |
| # native Rust parser extension is exercised on PHP 8.0+ (its minimum). | |
| # PostgreSQL-specific tests run in one bounded adapter lane. | |
| name: PHP ${{ matrix.php }}${{ matrix.extension && ' + ext-wp-mysql-parser' || '' }} / SQLite ${{ matrix.sqlite }} / ${{ matrix.testsuite }} | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 30 | |
| permissions: | |
| contents: read # Required to clone the repo. | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| # Pure-PHP parser, across the supported PHP versions, each pinned to a | |
| # representative SQLite version spanning the supported range. | |
| - { php: '7.2', sqlite: '3.27.0', extension: false, testsuite: default } # minimum with WP_SQLITE_UNSAFE_ENABLE_UNSUPPORTED_VERSIONS | |
| - { php: '7.3', sqlite: '3.31.1', extension: false, testsuite: default } # Ubuntu 20.04 LTS | |
| - { php: '7.4', sqlite: '3.34.1', extension: false, testsuite: default } # Debian 11 (Bullseye) | |
| - { php: '8.0', sqlite: '3.37.0', extension: false, testsuite: default } # minimum supported version (STRICT tables) | |
| - { php: '8.1', sqlite: '3.40.1', extension: false, testsuite: default } # Debian 12 (Bookworm) | |
| - { php: '8.2', sqlite: '3.45.1', extension: false, testsuite: default } # Ubuntu 24.04 LTS | |
| - { php: '8.3', sqlite: '3.46.1', extension: false, testsuite: default } # Debian 13 (Trixie) | |
| - { php: '8.4', sqlite: '3.51.2', extension: false, testsuite: default } # First 2026 release | |
| - { php: '8.5', sqlite: 'latest', extension: false, testsuite: default } | |
| # PostgreSQL adapter tests run once in a bounded package lane. | |
| - { php: '8.3', sqlite: '3.46.1', extension: false, testsuite: postgresql } | |
| # Native Rust parser extension (requires PHP 8.0+). | |
| - { php: '8.0', sqlite: '3.37.0', extension: true, testsuite: default } | |
| - { php: '8.1', sqlite: '3.40.1', extension: true, testsuite: default } | |
| - { php: '8.2', sqlite: '3.45.1', extension: true, testsuite: default } | |
| - { php: '8.3', sqlite: '3.46.1', extension: true, testsuite: default } | |
| - { php: '8.4', sqlite: '3.51.2', extension: true, testsuite: default } | |
| - { php: '8.5', sqlite: 'latest', extension: true, testsuite: default } | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up SQLite | |
| run: | | |
| VERSION='${{ matrix.sqlite }}' | |
| if [ "$VERSION" = 'latest' ]; then | |
| TAG='release' | |
| else | |
| TAG="version-${VERSION}" | |
| fi | |
| SQLITE_SOURCE="https://sqlite.org/src/tarball/sqlite.tar.gz?r=${TAG}" | |
| SQLITE_MIRROR="https://github.com/sqlite/sqlite/archive/refs/tags/${TAG}.tar.gz" | |
| DOWNLOADED=0 | |
| for url in "$SQLITE_SOURCE" "$SQLITE_MIRROR"; do | |
| for attempt in 1 2 3 4 5; do | |
| if wget -O sqlite.tar.gz "$url"; then | |
| DOWNLOADED=1 | |
| break 2 | |
| fi | |
| if [ "$attempt" -lt 5 ]; then | |
| sleep $(( attempt * 10 )) | |
| fi | |
| done | |
| done | |
| if [ "$DOWNLOADED" -ne 1 ]; then | |
| exit 1 | |
| fi | |
| tar xzf sqlite.tar.gz | |
| if [ ! -d sqlite ]; then | |
| SQLITE_DIR=$(find . -maxdepth 1 -type d -name 'sqlite-*' | head -n 1) | |
| if [ -z "$SQLITE_DIR" ]; then | |
| exit 1 | |
| fi | |
| mv "$SQLITE_DIR" sqlite | |
| fi | |
| cd sqlite | |
| ./configure --prefix=/usr/local CFLAGS="-DSQLITE_ENABLE_COLUMN_METADATA -DSQLITE_ENABLE_FTS5 -DSQLITE_USE_URI -DSQLITE_ENABLE_JSON1" LDFLAGS="-lm" | |
| make -j$(nproc) | |
| sudo make install | |
| sudo ldconfig | |
| - name: Set up PHP | |
| uses: shivammathur/setup-php@v2 | |
| with: | |
| php-version: ${{ matrix.php }} | |
| coverage: none | |
| tools: phpunit-polyfills | |
| - name: Verify SQLite version in PHP | |
| run: | | |
| EXPECTED='${{ matrix.sqlite }}' | |
| if [ "$EXPECTED" = 'latest' ]; then | |
| EXPECTED=$(cat sqlite/VERSION) | |
| fi | |
| PDO=$(php -r "echo (new PDO('sqlite::memory'))->query('SELECT SQLITE_VERSION();')->fetch()[0];") | |
| echo "Expected SQLite version: $EXPECTED" | |
| echo "PHP PDO SQLite version: $PDO" | |
| if [ "$EXPECTED" != "$PDO" ]; then | |
| echo "Error: Expected SQLite version $EXPECTED, but PHP PDO uses $PDO" | |
| exit 1 | |
| fi | |
| - name: Set up Rust | |
| if: matrix.extension | |
| uses: dtolnay/rust-toolchain@stable | |
| - name: Cache Rust build | |
| if: matrix.extension | |
| uses: Swatinem/rust-cache@v2 | |
| with: | |
| workspaces: packages/php-ext-wp-mysql-parser | |
| # Segregate by PHP version: the extension links against the PHP headers | |
| # of the matrix's php-config, so a build cached for one PHP version is | |
| # ABI-incompatible with another (Zend module API mismatch on load). | |
| key: php-${{ matrix.php }} | |
| - name: Install native build dependencies | |
| if: matrix.extension | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y libclang-dev | |
| echo "PHP_CONFIG=$(command -v php-config)" >> "$GITHUB_ENV" | |
| LIBCLANG_SO="$(find /usr/lib -name 'libclang.so*' | head -n 1)" | |
| echo "LIBCLANG_PATH=$(dirname "$LIBCLANG_SO")" >> "$GITHUB_ENV" | |
| - name: Install Composer dependencies (root) | |
| uses: ramsey/composer-install@v3 | |
| with: | |
| ignore-cache: "yes" | |
| composer-options: "--optimize-autoloader" | |
| - name: Install Composer dependencies (mysql-on-sqlite) | |
| uses: ramsey/composer-install@v3 | |
| with: | |
| working-directory: packages/mysql-on-sqlite | |
| ignore-cache: "yes" | |
| composer-options: "--optimize-autoloader" | |
| - name: Check Rust formatting | |
| if: ${{ matrix.extension && matrix.php == '8.2' }} | |
| run: cargo fmt --check | |
| working-directory: packages/php-ext-wp-mysql-parser | |
| - name: Build parser extension | |
| if: matrix.extension | |
| run: cargo build --release | |
| working-directory: packages/php-ext-wp-mysql-parser | |
| - name: Verify native parser extension | |
| if: matrix.extension | |
| run: php -d extension="$GITHUB_WORKSPACE/packages/php-ext-wp-mysql-parser/target/release/libwp_mysql_parser.so" tests/tools/verify-native-parser-extension.php | |
| working-directory: packages/mysql-on-sqlite | |
| - name: Run PHPUnit suite with parser extension | |
| if: matrix.extension | |
| env: | |
| WP_SQLITE_REQUIRE_NATIVE_PARSER_EXTENSION: '1' | |
| run: php -d extension="$GITHUB_WORKSPACE/packages/php-ext-wp-mysql-parser/target/release/libwp_mysql_parser.so" ./vendor/bin/phpunit -c ./phpunit.xml.dist --testsuite default | |
| working-directory: packages/mysql-on-sqlite | |
| - name: Run PHPUnit suite | |
| if: ${{ ! matrix.extension && matrix.testsuite == 'default' }} | |
| run: php ./vendor/bin/phpunit -c ./phpunit.xml.dist --testsuite default | |
| working-directory: packages/mysql-on-sqlite | |
| - name: Run PostgreSQL PHPUnit suite | |
| if: ${{ matrix.testsuite == 'postgresql' }} | |
| run: php ./vendor/bin/phpunit -c ./phpunit.xml.dist --testsuite postgresql | |
| working-directory: packages/mysql-on-sqlite |