Move native AST identity cache into the Rust extension #168
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: MySQL Parser Extension Tests | |
| on: | |
| push: | |
| paths: | |
| - '.github/workflows/mysql-parser-extension-tests.yml' | |
| - 'packages/mysql-on-sqlite/**' | |
| pull_request: | |
| paths: | |
| - '.github/workflows/mysql-parser-extension-tests.yml' | |
| - 'packages/mysql-on-sqlite/**' | |
| workflow_dispatch: | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| extension-tests: | |
| name: PHP 8.2 / Rust extension / ubuntu-latest | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 20 | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up PHP | |
| uses: shivammathur/setup-php@v2 | |
| with: | |
| php-version: '8.2' | |
| coverage: none | |
| tools: phpunit-polyfills | |
| - name: Set up Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| - name: Install native build dependencies | |
| 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 | |
| run: cargo fmt --check | |
| working-directory: packages/php-ext-wp-mysql-parser | |
| - name: Build parser extension | |
| run: cargo build | |
| working-directory: packages/php-ext-wp-mysql-parser | |
| - name: Run native parser smoke tests | |
| run: | | |
| php -d extension="$GITHUB_WORKSPACE/packages/php-ext-wp-mysql-parser/target/debug/libwp_mysql_parser.so" -r ' | |
| require "src/load.php"; | |
| $lexer = new WP_MySQL_Lexer( "SELECT ID, post_title FROM wp_posts WHERE ID IN (1, 2, 3)" ); | |
| if ( ! ( $lexer instanceof WP_MySQL_Native_Lexer ) ) { | |
| fwrite( STDERR, "Native lexer is not available.\n" ); | |
| exit( 1 ); | |
| } | |
| $tokens = $lexer->remaining_tokens(); | |
| $parser = new WP_MySQL_Parser( new WP_Parser_Grammar( include "src/mysql/mysql-grammar.php" ), $tokens ); | |
| $ast = $parser->parse(); | |
| if ( ! $ast instanceof WP_Parser_Node || "query" !== $ast->rule_name ) { | |
| fwrite( STDERR, "Native parser did not produce the expected query AST.\n" ); | |
| exit( 1 ); | |
| } | |
| ' | |
| working-directory: packages/mysql-on-sqlite | |
| - name: Run PHPUnit tests with parser extension | |
| run: php -d extension="$GITHUB_WORKSPACE/packages/php-ext-wp-mysql-parser/target/debug/libwp_mysql_parser.so" ./vendor/bin/phpunit -c ./phpunit.xml.dist | |
| working-directory: packages/mysql-on-sqlite | |
| sqlite-driver-extension-tests: | |
| name: PHP 8.2 / SQLite driver / Rust extension / ubuntu-latest | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 20 | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up PHP | |
| uses: shivammathur/setup-php@v2 | |
| with: | |
| php-version: '8.2' | |
| coverage: none | |
| tools: phpunit-polyfills | |
| - name: Set up Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| - name: Install native build dependencies | |
| 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: Build parser extension | |
| run: cargo build | |
| working-directory: packages/php-ext-wp-mysql-parser | |
| - name: Verify SQLite driver selects the native parser path | |
| run: | | |
| php -d extension="$GITHUB_WORKSPACE/packages/php-ext-wp-mysql-parser/target/debug/libwp_mysql_parser.so" -r ' | |
| require "packages/mysql-on-sqlite/src/load.php"; | |
| $lexer = new WP_MySQL_Lexer( "SELECT 1" ); | |
| if ( ! ( $lexer instanceof WP_MySQL_Native_Lexer ) ) { | |
| fwrite( STDERR, "Native lexer is not available.\n" ); | |
| exit( 1 ); | |
| } | |
| $driver = new WP_PDO_MySQL_On_SQLite( "mysql-on-sqlite:path=:memory:;dbname=wp;" ); | |
| $parser = $driver->create_parser( "SELECT 1" ); | |
| $parser->next_query(); | |
| $ast = $parser->get_query_ast(); | |
| $property = ( new ReflectionClass( $ast ) )->getProperty( "native_ast" ); | |
| $property->setAccessible( true ); | |
| $native_ast = $property->getValue( $ast ); | |
| if ( ! is_object( $native_ast ) || "WP_MySQL_Native_Ast" !== get_class( $native_ast ) ) { | |
| fwrite( STDERR, "SQLite driver did not return a native-backed AST.\n" ); | |
| exit( 1 ); | |
| } | |
| ' | |
| - name: Run PHPUnit tests with SQLite driver using parser extension | |
| run: php -d extension="$GITHUB_WORKSPACE/packages/php-ext-wp-mysql-parser/target/debug/libwp_mysql_parser.so" ./vendor/bin/phpunit -c ./phpunit.xml.dist | |
| working-directory: packages/mysql-on-sqlite |