chore(ci): replace custom PHP setup action with community action

- Removed custom setup-php-apt action that installed PHP from Ondrej PPA
- Switched to using shivammathur/setup-php@v2 community action
- Updated workflow jobs to use ubuntu-latest instead of ubuntu-24.04
- Configured PHP extensions (curl, redis, mbstring, ffi) via setup action
- Set PHP ini values through action configuration including FFI enable,
  memory limits, and error reporting settings
- Updated PHP embed library installation
debug/ci-class-id-cache
韩天峰 8 hours ago
parent 821f639e8f
commit 7f587749f1
  1. 97
      .github/actions/setup-php-apt/action.yml
  2. 67
      .github/workflows/tests.yml

@ -1,97 +0,0 @@
name: Setup PHP from Ondrej PPA
description: Install a version-matched PHP CLI, development SDK, extensions and Embed SAPI.
inputs:
php-version:
description: PHP major.minor version to install.
required: true
runs:
using: composite
steps:
- name: Install PHP and extensions
shell: bash
env:
PHP_VERSION: ${{ inputs.php-version }}
run: |
set -euo pipefail
export DEBIAN_FRONTEND=noninteractive
sudo apt-get update
sudo apt-get install --yes software-properties-common
sudo add-apt-repository --yes ppa:ondrej/php
sudo apt-get update
php_packages=( \
"php${PHP_VERSION}-cli" \
"php${PHP_VERSION}-common" \
"php${PHP_VERSION}-curl" \
"php${PHP_VERSION}-dev" \
"php${PHP_VERSION}-mbstring" \
"php${PHP_VERSION}-readline" \
"php${PHP_VERSION}-redis" \
"php${PHP_VERSION}-xml" \
"php${PHP_VERSION}-zip" \
"libphp${PHP_VERSION}-embed" \
)
if apt-cache show "php${PHP_VERSION}-opcache" >/dev/null 2>&1; then
php_packages+=("php${PHP_VERSION}-opcache")
fi
sudo apt-get install --yes "${php_packages[@]}"
sudo update-alternatives --set php "/usr/bin/php${PHP_VERSION}"
sudo update-alternatives --set phpize "/usr/bin/phpize${PHP_VERSION}"
sudo update-alternatives --set php-config "/usr/bin/php-config${PHP_VERSION}"
sudo phpenmod -v "${PHP_VERSION}" ffi
if test -f "/etc/php/${PHP_VERSION}/mods-available/opcache.ini"; then
sudo phpenmod -v "${PHP_VERSION}" opcache
else
echo "OPcache is not available in the PPA for PHP ${PHP_VERSION}"
fi
php_ini_dir="/etc/php/${PHP_VERSION}/cli/conf.d"
printf '%s\n' \
'ffi.enable=1' \
'phpy.enable_operator_overloading=0' \
'opcache.jit=0' \
'precision=17' \
'memory_limit=4G' \
'error_reporting=E_ERROR | E_WARNING' \
'display_errors=1' \
'display_startup_errors=1' \
'log_errors=0' \
| sudo tee "${php_ini_dir}/99-typephp-ci.ini" >/dev/null
embed_package="libphp${PHP_VERSION}-embed"
php_version="$(php-config --version)"
embed_version="$(dpkg-query --show --showformat='${Version}' "${embed_package}")"
case "${embed_version}" in
"${php_version}"*) ;;
*)
echo "${embed_package} ${embed_version} does not match PHP ${php_version}" >&2
exit 1
;;
esac
embed_library="$(dpkg-query --listfiles "${embed_package}" \
| sed -n '/\/libphp[0-9][^/]*\.so$/ { p; q; }')"
test -n "${embed_library}"
test -f "${embed_library}"
php_home="${RUNNER_TEMP}/typephp-php-${PHP_VERSION}"
mkdir -p "${php_home}/bin" "${php_home}/include" "${php_home}/lib"
ln -s "$(command -v php-config)" "${php_home}/bin/php-config"
ln -s "$(php-config --include-dir)" "${php_home}/include/php"
ln -s "${embed_library}" "${php_home}/lib/libphp.so"
ln -s "${embed_library}" "${php_home}/lib/$(basename "${embed_library}")"
echo "PHP_HOME=${php_home}" >> "${GITHUB_ENV}"
echo "PHP_INI_SCAN_DIR=${php_ini_dir}" >> "${GITHUB_ENV}"
echo "PHP_EMBED_LIBRARY=${embed_library}" >> "${GITHUB_ENV}"
test "$(php -r 'echo PHP_MAJOR_VERSION, ".", PHP_MINOR_VERSION;')" = "${PHP_VERSION}"
php -r 'foreach (["curl", "ffi", "mbstring", "redis", "xml", "zip"] as $extension) { if (!extension_loaded($extension)) { fwrite(STDERR, "Missing PHP extension: $extension\n"); exit(1); } }'
if test -f "/etc/php/${PHP_VERSION}/mods-available/opcache.ini"; then
php -r 'if (!extension_loaded("Zend OPcache")) { fwrite(STDERR, "Missing PHP extension: Zend OPcache\n"); exit(1); }'
fi
composer --version
echo "Using ${embed_library} from ${embed_package} ${embed_version}"

@ -19,7 +19,7 @@ env:
jobs:
build-phpx:
name: Build PHPX (PHP ${{ matrix.php }})
runs-on: ubuntu-24.04
runs-on: ubuntu-latest
timeout-minutes: 30
strategy:
fail-fast: false
@ -38,16 +38,20 @@ jobs:
repository: swoole/phpy
path: third_party/phpy
- name: Setup PHP from PPA
uses: ./.github/actions/setup-php-apt
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none
ini-values: precision=17, memory_limit=4G, error_reporting=E_ERROR|E_WARNING, display_errors=1, display_startup_errors=1, log_errors=0
tools: composer:v2
- name: Patch php_hash.h C++ compatibility
uses: ./.github/actions/patch-php-headers
- name: Install native build dependencies
run: |
sudo apt-get update
sudo apt-get install --yes build-essential cmake libgmp-dev libmpfr-dev pkg-config python3-dev
- name: Install Composer dependencies
@ -90,7 +94,7 @@ jobs:
phpunit:
name: PHPUnit (PHP ${{ matrix.php }})
runs-on: ubuntu-24.04
runs-on: ubuntu-latest
timeout-minutes: 30
needs: build-phpx
strategy:
@ -104,16 +108,21 @@ jobs:
- name: Checkout TypePHP
uses: actions/checkout@v4
- name: Setup PHP from PPA
uses: ./.github/actions/setup-php-apt
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none
extensions: curl, redis, mbstring, ffi
ini-values: ffi.enable=1, phpy.enable_operator_overloading=0, precision=17, memory_limit=4G, error_reporting=E_ERROR|E_WARNING, display_errors=1, display_startup_errors=1, log_errors=0
tools: composer:v2
- name: Patch php_hash.h C++ compatibility
uses: ./.github/actions/patch-php-headers
- name: Install native build dependencies
run: |
sudo apt-get update
sudo apt-get install --yes build-essential cmake libgmp-dev libmpfr-dev pkg-config python3-dev
- name: Install Composer dependencies
@ -134,21 +143,22 @@ jobs:
- name: Enable phpy extension
shell: bash
run: |
php_ini_dir="/etc/php/${{ matrix.php }}/cli/conf.d"
php_ini_dir="$(php-config --ini-dir)"
echo "extension=${GITHUB_WORKSPACE}/third_party/phpy/modules/phpy.so" \
| sudo tee "${php_ini_dir}/90-phpy.ini"
echo "PHP_INI_SCAN_DIR=${php_ini_dir}" >> "${GITHUB_ENV}"
php --ri phpy
- name: Configure native library path
shell: bash
run: echo "LD_LIBRARY_PATH=${PHPX_HOME}/lib:${PHP_HOME}/lib" >> "${GITHUB_ENV}"
run: echo "LD_LIBRARY_PATH=${PHPX_HOME}/lib:$(php-config --prefix)/lib" >> "${GITHUB_ENV}"
- name: Run PHPUnit
run: vendor/bin/phpunit
phpt:
name: PHPT (PHP ${{ matrix.php }})
runs-on: ubuntu-24.04
runs-on: ubuntu-latest
timeout-minutes: 180
needs: build-phpx
strategy:
@ -164,17 +174,47 @@ jobs:
- name: Checkout TypePHP
uses: actions/checkout@v4
- name: Setup PHP from PPA
uses: ./.github/actions/setup-php-apt
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none
extensions: curl, redis, mbstring, ffi
ini-values: ffi.enable=1, phpy.enable_operator_overloading=0, opcache.jit=0, precision=17, memory_limit=4G, error_reporting=E_ERROR|E_WARNING, display_errors=1, display_startup_errors=1, log_errors=0
tools: composer:v2
- name: Patch php_hash.h C++ compatibility
uses: ./.github/actions/patch-php-headers
- name: Install native build dependencies
run: |
sudo apt-get install --yes build-essential cmake libgmp-dev libmpfr-dev pkg-config python3-dev
sudo apt-get update
sudo apt-get install --yes build-essential cmake libgmp-dev libmpfr-dev pkg-config python3-dev \
"libphp${{ matrix.php }}-embed"
- name: Configure version-matched PHP embed library
shell: bash
run: |
embed_package="libphp${{ matrix.php }}-embed"
php_version="$(php-config --version)"
embed_version="$(dpkg-query --show --showformat='${Version}' "${embed_package}")"
case "${embed_version}" in
"${php_version}"*) ;;
*) echo "PHP embed package ${embed_version} does not match PHP ${php_version}" >&2; exit 1 ;;
esac
embed_library="$(dpkg-query --listfiles "${embed_package}" \
| sed -n '/\/libphp[0-9][^/]*\.so$/ { p; q; }')"
test -n "${embed_library}"
test -f "${embed_library}"
php_home="${RUNNER_TEMP}/typephp-php-${{ matrix.php }}"
mkdir -p "${php_home}/bin" "${php_home}/include" "${php_home}/lib"
ln -s "$(command -v php-config)" "${php_home}/bin/php-config"
ln -s "$(php-config --include-dir)" "${php_home}/include/php"
ln -s "${embed_library}" "${php_home}/lib/libphp.so"
echo "PHP_HOME=${php_home}" >> "${GITHUB_ENV}"
echo "Using ${embed_library} from ${embed_package} ${embed_version} for PHP ${php_version}"
- name: Install Composer dependencies
run: composer install --prefer-dist --no-progress
@ -194,9 +234,10 @@ jobs:
- name: Enable phpy extension
shell: bash
run: |
php_ini_dir="/etc/php/${{ matrix.php }}/cli/conf.d"
php_ini_dir="$(php-config --ini-dir)"
echo "extension=${GITHUB_WORKSPACE}/third_party/phpy/modules/phpy.so" \
| sudo tee "${php_ini_dir}/90-phpy.ini"
echo "PHP_INI_SCAN_DIR=${php_ini_dir}" >> "${GITHUB_ENV}"
php --ri phpy
- name: Configure native library path

Loading…
Cancel
Save