Ship wp_mysql_parser as WASM #21
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: WASM extension build | |
| on: | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - 'packages/php-ext-wp-mysql-parser/**' | |
| - '.github/workflows/wasm-spike.yml' | |
| pull_request: | |
| paths: | |
| - 'packages/php-ext-wp-mysql-parser/**' | |
| - '.github/workflows/wasm-spike.yml' | |
| workflow_dispatch: | |
| inputs: | |
| playground-ref: | |
| description: 'wordpress-playground branch/tag/SHA to build against' | |
| required: false | |
| default: 'adamziel/compile-extension-rust-recipe' | |
| jobs: | |
| build-and-load: | |
| name: Build wp_mysql_parser.so and load it in Playground (PHP ${{ matrix.php }}) | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 45 | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| php: ['8.4'] | |
| async-mode: ['jspi'] | |
| steps: | |
| - name: Check out sqlite-database-integration | |
| uses: actions/checkout@v4 | |
| with: | |
| path: sqlite-database-integration | |
| - name: Check out wordpress-playground | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: WordPress/wordpress-playground | |
| ref: ${{ github.event.inputs.playground-ref || 'adamziel/compile-extension-rust-recipe' }} | |
| path: wordpress-playground | |
| - name: Set up Node | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '24' | |
| cache: 'npm' | |
| cache-dependency-path: wordpress-playground/package-lock.json | |
| - name: Install Playground deps | |
| working-directory: wordpress-playground | |
| run: npm ci | |
| - name: Resolve PHP release for ${{ matrix.php }} | |
| id: php-release | |
| working-directory: wordpress-playground | |
| run: | | |
| # Mirror @php-wasm/compile-extension's resolvePHPRelease() by | |
| # parsing its source map so we tag the image with the exact same | |
| # PHP_VERSION value the CLI would use. | |
| RELEASE=$(node -e " | |
| const fs=require('fs'); | |
| const src=fs.readFileSync('./packages/php-wasm/compile-extension/src/compile.ts','utf8'); | |
| const map=Object.fromEntries([...src.matchAll(/'(\d+\.\d+)':\s*'(\d+\.\d+\.\d+)'/g)].map(m=>[m[1],m[2]])); | |
| const r=map['${{ matrix.php }}']; | |
| if (!r) { process.exit(1); } | |
| console.log(r); | |
| ") | |
| echo "release=$RELEASE" >> "$GITHUB_OUTPUT" | |
| echo "Resolved PHP ${{ matrix.php }} -> $RELEASE" | |
| - name: Configure Docker DNS | |
| run: | | |
| # GitHub-hosted runners occasionally have a Docker daemon whose | |
| # default bridge network can't resolve archive.ubuntu.com. Pin | |
| # explicit public resolvers so apt-get inside the base image build | |
| # can reach the Ubuntu mirrors. | |
| echo '{"dns": ["8.8.8.8", "1.1.1.1"]}' | sudo tee /etc/docker/daemon.json | |
| sudo systemctl restart docker | |
| # Wait for Docker to come back up. | |
| for i in 1 2 3 4 5 6 7 8 9 10; do | |
| if docker info >/dev/null 2>&1; then break; fi | |
| sleep 2 | |
| done | |
| - name: Build playground-php-wasm:base image | |
| working-directory: wordpress-playground/packages/php-wasm/compile | |
| run: make base-image | |
| - name: Build per-version compile-extension image | |
| working-directory: wordpress-playground/packages/php-wasm | |
| env: | |
| IMAGE_TAG: playground-php-wasm:compile-extension-php${{ matrix.php == '8.4' && '8-4' || matrix.php == '8.3' && '8-3' || matrix.php == '8.2' && '8-2' || matrix.php == '8.1' && '8-1' || matrix.php == '8.0' && '8-0' || matrix.php == '7.4' && '7-4' || matrix.php == '7.3' && '7-3' || matrix.php == '7.2' && '7-2' || matrix.php }}-${{ matrix.async-mode }} | |
| run: | | |
| JSPI_FLAG=no | |
| if [ "${{ matrix.async-mode }}" = "jspi" ]; then JSPI_FLAG=yes; fi | |
| docker build \ | |
| -f compile-extension/docker/Dockerfile.ext \ | |
| . \ | |
| --tag "$IMAGE_TAG" \ | |
| --progress=plain \ | |
| --build-arg "PHP_VERSION=${{ steps.php-release.outputs.release }}" \ | |
| --build-arg "JSPI=$JSPI_FLAG" | |
| docker images | grep playground-php-wasm | |
| - name: Build wp_mysql_parser side module | |
| working-directory: sqlite-database-integration/packages/php-ext-wp-mysql-parser/wasm-spike | |
| env: | |
| PHP_VERSION: ${{ matrix.php }} | |
| ASYNC_MODE: ${{ matrix.async-mode }} | |
| run: bash build-in-docker-rust.sh | |
| - name: Verify build artifacts exist | |
| working-directory: sqlite-database-integration/packages/php-ext-wp-mysql-parser/wasm-spike | |
| run: | | |
| test -f dist/wp_mysql_parser-php${{ matrix.php }}-${{ matrix.async-mode }}.so | |
| test -f dist/manifest.json | |
| test -f dist/libwp_mysql_parser.a | |
| ls -lh dist/ | |
| - name: Verify manifest sha256 matches the .so byte-for-byte | |
| working-directory: sqlite-database-integration/packages/php-ext-wp-mysql-parser/wasm-spike | |
| run: | | |
| MANIFEST_SHA=$(node -e "console.log(require('./dist/manifest.json').artifacts[0].sha256)") | |
| ACTUAL_SHA=$(sha256sum dist/wp_mysql_parser-php${{ matrix.php }}-${{ matrix.async-mode }}.so | cut -d' ' -f1) | |
| echo "manifest: $MANIFEST_SHA" | |
| echo "actual: $ACTUAL_SHA" | |
| test "$MANIFEST_SHA" = "$ACTUAL_SHA" | |
| - name: Load the extension in Playground and parse a query | |
| working-directory: sqlite-database-integration/packages/php-ext-wp-mysql-parser/wasm-spike | |
| env: | |
| PLAYGROUND_REPO: ${{ github.workspace }}/wordpress-playground | |
| run: node run-spike.mjs | |
| - name: Upload artifacts on success | |
| if: success() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: wp_mysql_parser-php${{ matrix.php }}-${{ matrix.async-mode }} | |
| path: sqlite-database-integration/packages/php-ext-wp-mysql-parser/wasm-spike/dist/ | |
| if-no-files-found: error | |
| retention-days: 14 | |
| - name: Upload diagnostic logs on failure | |
| if: failure() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: wasm-spike-failure-php${{ matrix.php }}-${{ matrix.async-mode }} | |
| path: | | |
| sqlite-database-integration/packages/php-ext-wp-mysql-parser/wasm-spike/dist/ | |
| sqlite-database-integration/packages/php-ext-wp-mysql-parser/wasm-spike/*.log | |
| if-no-files-found: ignore | |
| retention-days: 14 |