chore(ci): migrate PHP setup to custom action with Ubuntu 24.04

- Replace shivammathur/setup-php@v2 with custom setup-php-apt action
- Update all workflow jobs to use ubuntu-24.04 runner
- Create new composite action for installing PHP from Ondrej PPA
- Simplify PHP configuration by using predefined ini settings
- Remove redundant apt-get update commands in build steps
- Update PHP embed library configuration and linking
- Fix ldd command regex pattern for libphp.so detection
- Standardize PHP INI directory paths across all workflows
- Remove unused PHP_INI_SCAN_DIR environment variable exports
master
韩天峰 6 days ago
parent e4817819dc
commit 978e553480
  1. 85
      .github/actions/setup-php-apt/action.yml
  2. 69
      .github/workflows/tests.yml

@ -0,0 +1,85 @@
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
sudo apt-get install --yes \
"php${PHP_VERSION}-cli" \
"php${PHP_VERSION}-common" \
"php${PHP_VERSION}-curl" \
"php${PHP_VERSION}-dev" \
"php${PHP_VERSION}-mbstring" \
"php${PHP_VERSION}-opcache" \
"php${PHP_VERSION}-readline" \
"php${PHP_VERSION}-redis" \
"php${PHP_VERSION}-xml" \
"php${PHP_VERSION}-zip" \
"libphp${PHP_VERSION}-embed"
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 opcache
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", "Zend OPcache"] as $extension) { if (!extension_loaded($extension)) { fwrite(STDERR, "Missing PHP extension: $extension\n"); exit(1); } }'
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-latest
runs-on: ubuntu-24.04
timeout-minutes: 30
strategy:
fail-fast: false
@ -38,20 +38,16 @@ jobs:
repository: swoole/phpy
path: third_party/phpy
- name: Setup PHP
uses: shivammathur/setup-php@v2
- name: Setup PHP from PPA
uses: ./.github/actions/setup-php-apt
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
@ -94,7 +90,7 @@ jobs:
phpunit:
name: PHPUnit (PHP ${{ matrix.php }})
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
timeout-minutes: 30
needs: build-phpx
strategy:
@ -108,21 +104,16 @@ jobs:
- name: Checkout TypePHP
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
- name: Setup PHP from PPA
uses: ./.github/actions/setup-php-apt
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
@ -143,22 +134,21 @@ jobs:
- name: Enable phpy extension
shell: bash
run: |
php_ini_dir="$(php-config --ini-dir)"
php_ini_dir="/etc/php/${{ matrix.php }}/cli/conf.d"
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-config --prefix)/lib" >> "${GITHUB_ENV}"
run: echo "LD_LIBRARY_PATH=${PHPX_HOME}/lib:${PHP_HOME}/lib" >> "${GITHUB_ENV}"
- name: Run PHPUnit
run: vendor/bin/phpunit
phpt:
name: PHPT (PHP ${{ matrix.php }})
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
timeout-minutes: 180
needs: build-phpx
strategy:
@ -174,47 +164,17 @@ jobs:
- name: Checkout TypePHP
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
- name: Setup PHP from PPA
uses: ./.github/actions/setup-php-apt
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 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}"
sudo apt-get install --yes build-essential cmake libgmp-dev libmpfr-dev pkg-config python3-dev
- name: Install Composer dependencies
run: composer install --prefer-dist --no-progress
@ -234,10 +194,9 @@ jobs:
- name: Enable phpy extension
shell: bash
run: |
php_ini_dir="$(php-config --ini-dir)"
php_ini_dir="/etc/php/${{ matrix.php }}/cli/conf.d"
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
@ -257,7 +216,7 @@ jobs:
run: |
php -v
php --ini
ldd ./tpc | grep -E 'libphp(x)?\.so'
ldd ./tpc | grep -E 'libphp(x)?[0-9.]*\.so'
cmake --version
c++ --version

Loading…
Cancel
Save