2023-11-19 13:38:55 +08:00
< ? php
2024-01-10 21:08:25 +08:00
/** @noinspection ALL */
2023-11-19 13:38:55 +08:00
declare ( strict_types = 1 );
2024-01-03 10:31:21 +08:00
/**
* This is GitHub Actions automatic test extension args generator .
2025-03-20 16:11:45 +08:00
* You can edit $test_php_version , $test_os , $zts , $no_strip , $upx , $prefer_pre_built , $extensions , $with_libs and $base_combination .
2024-01-03 10:31:21 +08:00
*/
2023-12-19 19:31:56 +08:00
2024-01-03 10:31:21 +08:00
// --------------------------------- edit area ---------------------------------
2023-12-23 14:48:59 +08:00
2025-03-20 16:11:45 +08:00
// test php version (8.1 ~ 8.4 available, multiple for matrix)
2024-10-04 15:48:12 +08:00
$test_php_version = [
2025-06-19 19:31:25 +08:00
'8.1' ,
'8.2' ,
'8.3' ,
2024-10-25 16:38:02 +08:00
'8.4' ,
2024-10-04 15:48:12 +08:00
];
2025-04-22 15:09:31 +08:00
// test os (macos-13, macos-14, macos-15, ubuntu-latest, windows-latest are available)
2024-10-04 15:48:12 +08:00
$test_os = [
2025-06-12 01:20:02 +08:00
'macos-13' ,
2025-04-24 14:21:37 +08:00
// 'macos-14',
2025-06-07 21:33:02 +07:00
'macos-15' ,
2025-06-19 19:31:25 +08:00
// 'ubuntu-latest',
// 'ubuntu-22.04',
// 'ubuntu-24.04',
// 'ubuntu-22.04-arm',
// 'ubuntu-24.04-arm',
2025-05-06 16:53:33 +07:00
// 'windows-latest',
2024-10-04 15:48:12 +08:00
];
// whether enable thread safe
2025-06-19 19:31:25 +08:00
$zts = false ;
2024-05-11 14:46:36 +08:00
2024-06-03 23:16:15 +08:00
$no_strip = false ;
2024-10-04 15:48:12 +08:00
// compress with upx
2025-03-30 23:37:22 +07:00
$upx = false ;
2024-06-03 23:16:15 +08:00
2025-06-18 21:06:08 +08:00
// whether to test frankenphp build, only available for macos and linux
2025-06-19 19:31:25 +08:00
$frankenphp = false ;
2025-06-18 21:06:08 +08:00
2024-10-04 15:48:12 +08:00
// prefer downloading pre-built packages to speed up the build process
2025-06-19 19:31:25 +08:00
$prefer_pre_built = true ;
2024-10-01 16:00:13 +08:00
2024-01-03 10:31:21 +08:00
// If you want to test your added extensions and libs, add below (comma separated, example `bcmath,openssl`).
2024-01-10 21:08:25 +08:00
$extensions = match ( PHP_OS_FAMILY ) {
2025-06-19 12:40:42 +07:00
'Linux' , 'Darwin' => 'apcu,ast,bcmath,calendar,ctype,curl,dba,dom,exif,fileinfo,filter,iconv,libxml,mbregex,mbstring,opcache,openssl,pcntl,phar,posix,readline,session,simplexml,sockets,sodium,tokenizer,xml,xmlreader,xmlwriter,zip,zlib' ,
2025-04-28 14:35:08 +08:00
'Windows' => 'xlswriter,openssl' ,
2024-01-10 21:08:25 +08:00
};
2023-11-19 13:38:55 +08:00
2025-04-18 15:43:54 +07:00
// If you want to test shared extensions, add them below (comma separated, example `bcmath,openssl`).
$shared_extensions = match ( PHP_OS_FAMILY ) {
2025-06-11 22:40:43 +08:00
'Linux' => '' ,
2025-06-07 21:33:02 +07:00
'Darwin' => '' ,
'Windows' => '' ,
2025-04-18 15:43:54 +07:00
};
2025-06-11 11:43:00 +07:00
// If you want to test lib-suggests for all extensions and libraries, set it to true.
$with_suggested_libs = true ;
// If you want to test extra libs for extensions, add them below (comma separated, example `libwebp,libavif`). Unnecessary, when $with_suggested_libs is true.
2024-01-10 21:08:25 +08:00
$with_libs = match ( PHP_OS_FAMILY ) {
2025-06-11 11:43:00 +07:00
'Linux' , 'Darwin' => '' ,
2025-03-23 22:33:26 +08:00
'Windows' => '' ,
2024-01-10 21:08:25 +08:00
};
2024-01-03 10:31:21 +08:00
// Please change your test base combination. We recommend testing with `common`.
// You can use `common`, `bulk`, `minimal` or `none`.
2024-01-10 21:08:25 +08:00
// note: combination is only available for *nix platform. Windows must use `none` combination
$base_combination = match ( PHP_OS_FAMILY ) {
2025-04-19 20:39:48 +08:00
'Linux' , 'Darwin' => 'minimal' ,
2024-01-10 21:08:25 +08:00
'Windows' => 'none' ,
};
2024-01-03 10:31:21 +08:00
// -------------------------- code area, do not modify --------------------------
/**
* get combination for tests , do not modify it if not necessary .
*/
function _getCombination ( string $type = 'common' ) : string
{
return match ( $type ) {
'common' => 'bcmath,bz2,calendar,ctype,curl,dom,exif,fileinfo,filter,ftp,gd,gmp,iconv,xml,mbstring,mbregex,' .
'mysqlnd,openssl,pcntl,pdo,pdo_mysql,pdo_sqlite,phar,posix,redis,session,simplexml,soap,sockets,' .
'sqlite3,tokenizer,xmlwriter,xmlreader,zlib,zip' ,
'bulk' => 'apcu,bcmath,bz2,calendar,ctype,curl,dba,dom,event,exif,fileinfo,filter,ftp,gd,gmp,iconv,imagick,imap,' .
'intl,mbregex,mbstring,mysqli,mysqlnd,opcache,openssl,pcntl,pdo,pdo_mysql,pdo_pgsql,pdo_sqlite,pgsql,phar,' .
'posix,protobuf,readline,redis,session,shmop,simplexml,soap,sockets,sodium,sqlite3,swoole,sysvmsg,sysvsem,' .
'sysvshm,tokenizer,xml,xmlreader,xmlwriter,xsl,zip,zlib' ,
'minimal' => 'pcntl,posix,mbstring,tokenizer,phar' ,
default => '' , // none
};
}
2023-12-23 13:53:22 +08:00
2023-12-23 14:48:59 +08:00
if ( ! isset ( $argv [ 1 ])) {
2024-09-29 15:24:33 +08:00
exit ( " Please use 'extensions', 'cmd', 'os', 'php' or 'libs' as output type " );
2023-12-23 14:48:59 +08:00
}
2024-01-03 10:31:21 +08:00
$trim_value = " \r \n \t , " ;
$final_extensions = trim ( trim ( $extensions , $trim_value ) . ',' . _getCombination ( $base_combination ), $trim_value );
2025-04-18 15:43:54 +07:00
$download_extensions = trim ( $final_extensions . ',' . $shared_extensions , $trim_value );
2024-01-03 10:31:21 +08:00
$final_libs = trim ( $with_libs , $trim_value );
2024-01-10 21:19:26 +08:00
if ( PHP_OS_FAMILY === 'Windows' ) {
$final_extensions_cmd = '"' . $final_extensions . '"' ;
} else {
$final_extensions_cmd = $final_extensions ;
}
2024-10-04 15:54:13 +08:00
function quote2 ( string $param ) : string
{
global $argv ;
if ( str_starts_with ( $argv [ 2 ], 'windows-' )) {
return '"' . $param . '"' ;
}
return $param ;
}
2024-10-04 15:48:12 +08:00
// generate download command
2024-10-04 15:49:57 +08:00
if ( $argv [ 1 ] === 'download_cmd' ) {
$down_cmd = 'download ' ;
2025-04-18 15:43:54 +07:00
$down_cmd .= '--for-extensions=' . quote2 ( $download_extensions ) . ' ' ;
2024-10-04 15:54:13 +08:00
$down_cmd .= '--for-libs=' . quote2 ( $final_libs ) . ' ' ;
$down_cmd .= '--with-php=' . quote2 ( $argv [ 3 ]) . ' ' ;
2024-10-04 15:49:57 +08:00
$down_cmd .= '--ignore-cache-sources=php-src ' ;
$down_cmd .= '--debug ' ;
$down_cmd .= '--retry=5 ' ;
$down_cmd .= '--shallow-clone ' ;
$down_cmd .= $prefer_pre_built ? '--prefer-pre-built ' : '' ;
}
2024-10-04 15:48:12 +08:00
2025-03-30 20:53:41 +08:00
if ( $argv [ 1 ] === 'doctor_cmd' ) {
$doctor_cmd = 'doctor --auto-fix --debug' ;
}
2025-03-30 21:03:11 +08:00
if ( $argv [ 1 ] === 'install_upx_cmd' ) {
2025-05-21 15:11:42 +08:00
$install_upx_cmd = 'install-pkg upx --debug' ;
2025-03-30 21:03:11 +08:00
}
2025-03-30 20:53:41 +08:00
2025-04-19 15:18:48 +08:00
$prefix = match ( $argv [ 2 ] ? ? null ) {
'windows-latest' , 'windows-2022' , 'windows-2019' , 'windows-2025' => 'powershell.exe -file .\bin\spc.ps1 ' ,
'ubuntu-latest' => 'bin/spc-alpine-docker ' ,
'ubuntu-24.04' , 'ubuntu-24.04-arm' => './bin/spc ' ,
'ubuntu-22.04' , 'ubuntu-22.04-arm' => 'bin/spc-gnu-docker ' ,
default => 'bin/spc ' ,
};
// shared_extension build
if ( $shared_extensions ) {
switch ( $argv [ 2 ] ? ? null ) {
case 'ubuntu-22.04' :
case 'ubuntu-22.04-arm' :
$shared_cmd = ' --build-shared=' . quote2 ( $shared_extensions ) . ' ' ;
break ;
case 'macos-13' :
case 'macos-14' :
2025-04-22 15:09:31 +08:00
case 'macos-15' :
2025-04-19 15:18:48 +08:00
$shared_cmd = ' --build-shared=' . quote2 ( $shared_extensions ) . ' ' ;
$no_strip = true ;
break ;
default :
$shared_cmd = '' ;
break ;
}
} else {
$shared_cmd = '' ;
}
2024-10-04 15:48:12 +08:00
// generate build command
2024-12-10 23:55:33 +08:00
if ( $argv [ 1 ] === 'build_cmd' || $argv [ 1 ] === 'build_embed_cmd' ) {
2024-10-04 15:49:57 +08:00
$build_cmd = 'build ' ;
2024-10-04 15:54:13 +08:00
$build_cmd .= quote2 ( $final_extensions ) . ' ' ;
2025-04-19 15:18:48 +08:00
$build_cmd .= $shared_cmd ;
2025-06-11 11:43:00 +07:00
$build_cmd .= $with_suggested_libs ? '--with-suggested-libs ' : '' ;
2024-10-04 15:49:57 +08:00
$build_cmd .= $zts ? '--enable-zts ' : '' ;
$build_cmd .= $no_strip ? '--no-strip ' : '' ;
$build_cmd .= $upx ? '--with-upx-pack ' : '' ;
2024-10-04 15:54:13 +08:00
$build_cmd .= $final_libs === '' ? '' : ( '--with-libs=' . quote2 ( $final_libs ) . ' ' );
2025-06-18 21:06:08 +08:00
$build_cmd .= str_starts_with ( $argv [ 2 ], 'windows-' ) ? '' : '--build-fpm ' ;
2024-10-04 15:49:57 +08:00
$build_cmd .= '--debug ' ;
}
2024-10-04 15:48:12 +08:00
2023-12-23 14:48:59 +08:00
echo match ( $argv [ 1 ]) {
2024-09-29 15:24:33 +08:00
'os' => json_encode ( $test_os ),
'php' => json_encode ( $test_php_version ),
2024-01-03 10:31:21 +08:00
'extensions' => $final_extensions ,
'libs' => $final_libs ,
2024-03-01 19:19:47 +08:00
'libs_cmd' => ( $final_libs === '' ? '' : ( ' --with-libs=' . $final_libs )),
'cmd' => $final_extensions_cmd . ( $final_libs === '' ? '' : ( ' --with-libs=' . $final_libs )),
2024-05-11 14:46:36 +08:00
'zts' => $zts ? '--enable-zts' : '' ,
2024-06-03 23:16:15 +08:00
'no_strip' => $no_strip ? '--no-strip' : '' ,
'upx' => $upx ? '--with-upx-pack' : '' ,
2024-10-01 16:00:13 +08:00
'prefer_pre_built' => $prefer_pre_built ? '--prefer-pre-built' : '' ,
2024-10-04 15:48:12 +08:00
'download_cmd' => $down_cmd ,
2025-03-30 21:03:11 +08:00
'install_upx_cmd' => $install_upx_cmd ,
2025-03-30 20:53:41 +08:00
'doctor_cmd' => $doctor_cmd ,
2024-10-04 15:48:12 +08:00
'build_cmd' => $build_cmd ,
2024-12-10 23:39:13 +08:00
'build_embed_cmd' => $build_cmd ,
2023-12-23 14:48:59 +08:00
default => '' ,
};
2024-10-04 16:04:13 +08:00
2025-04-19 15:18:48 +08:00
switch ( $argv [ 1 ] ? ? null ) {
case 'download_cmd' :
passthru ( $prefix . $down_cmd , $retcode );
break ;
case 'build_cmd' :
passthru ( $prefix . $build_cmd . ' --build-cli --build-micro' , $retcode );
break ;
case 'build_embed_cmd' :
2025-06-18 21:08:05 +08:00
if ( $frankenphp ) {
2025-06-19 12:07:22 +07:00
passthru ( " { $prefix } install-pkg go-xcaddy --debug " , $retcode );
2025-06-18 21:08:05 +08:00
if ( $retcode !== 0 ) {
break ;
}
}
2025-06-18 21:06:08 +08:00
passthru ( $prefix . $build_cmd . ( str_starts_with ( $argv [ 2 ], 'windows-' ) ? ' --build-cli' : ( ' --build-embed' . ( $frankenphp ? ' --build-frankenphp' : '' ))), $retcode );
2025-04-19 15:18:48 +08:00
break ;
case 'doctor_cmd' :
passthru ( $prefix . $doctor_cmd , $retcode );
break ;
case 'install_upx_cmd' :
passthru ( $prefix . $install_upx_cmd , $retcode );
break ;
default :
$retcode = 0 ;
break ;
2024-10-04 16:06:46 +08:00
}
2024-10-04 16:53:24 +08:00
exit ( $retcode );