Compare commits

..
4 Commits
Author SHA1 Message Date
Florian Engelhardt abf2248889 Add asan usage 2026-11-27 03:46:14 +05:30
Shivam Mathur fad0ff9c5d Set the setup-php user agent for tool downloads and Node fetches 2026-11-27 01:39:28 +05:30
Jordi Boggiano 66f29b02f3 Send a setup-php user agent and request compressed tool downloads (#1168)
Downloads used curl's default user agent and no Accept-Encoding, so
fallbacks to getcomposer.org transferred the full ~3.8MB phar instead of
~0.9MB gzipped, and could not be told apart from other curl traffic.
2026-11-27 00:40:41 +05:30
Till Krüss 940ea09f22 Add support for Relay on PHP 8.6 (#1166) 2026-11-24 13:05:34 +05:30
10 changed files with 81 additions and 12 deletions
+46
View File
@@ -44,6 +44,7 @@ Setup PHP with required extensions, php.ini configuration, code-coverage support
- [Nightly Build Setup](#nightly-build-setup) - [Nightly Build Setup](#nightly-build-setup)
- [Debug Build Setup](#debug-build-setup) - [Debug Build Setup](#debug-build-setup)
- [Thread Safe Setup](#thread-safe-setup) - [Thread Safe Setup](#thread-safe-setup)
- [ASAN Build Setup](#asan-build-setup)
- [Force Update Setup](#force-update-setup) - [Force Update Setup](#force-update-setup)
- [Verbose Setup](#verbose-setup) - [Verbose Setup](#verbose-setup)
- [Multi-Arch Setup](#multi-arch-setup) - [Multi-Arch Setup](#multi-arch-setup)
@@ -531,6 +532,13 @@ On GitHub Actions you can assign the `setup-php` step an `id`, you can use the s
- By default, it is set to `nts`. - By default, it is set to `nts`.
- See [thread safe setup](#thread-safe-setup) for more info. - See [thread safe setup](#thread-safe-setup) for more info.
#### `asan` (optional)
- Specify to set up PHP with AddressSanitizer (ASAN) for memory error detection.
- Accepts `true` or `false`.
- Only available for PHP 8.0 and above on Linux runners.
- See [ASAN build setup](#asan-build-setup) for more info.
#### `update` (optional) #### `update` (optional)
- Specify to update PHP on the runner to the latest patch version. - Specify to update PHP on the runner to the latest patch version.
@@ -652,6 +660,44 @@ jobs:
phpts: ts # specify ts or nts phpts: ts # specify ts or nts
``` ```
### ASAN Build Setup
> Set up PHP with AddressSanitizer (ASAN) for memory error detection.
- ASAN builds include both `AddressSanitizer` and `UndefinedBehaviorSanitizer (UBSan)`.
- Only available for PHP 8.0 and above on Linux based runners.
- Useful for detecting memory errors such as buffer overflows, use-after-free, and memory leaks.
```yaml
jobs:
run:
runs-on: ubuntu-latest
name: Setup PHP with ASAN
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.5'
env:
asan: true
```
You can combine ASAN with other options:
```yaml
- name: Setup PHP with ASAN and thread safety
uses: shivammathur/setup-php@v2
with:
php-version: '8.5'
env:
asan: true
phpts: ts
```
> [!NOTE]
> - ASAN builds have a performance overhead due to the instrumentation, so they are recommended for testing and debugging only.
> - You can configure ASAN behavior using the `ASAN_OPTIONS` environment variable in your test steps.
### Force Update Setup ### Force Update Setup
> Update to the latest patch of PHP versions. > Update to the latest patch of PHP versions.
+2
View File
@@ -72,6 +72,7 @@ describe('Extension tests', () => {
${'phalcon3'} | ${'7.3'} | ${'add_phalcon phalcon3'} ${'phalcon3'} | ${'7.3'} | ${'add_phalcon phalcon3'}
${'relay'} | ${'7.4'} | ${'add_relay relay'} ${'relay'} | ${'7.4'} | ${'add_relay relay'}
${'relay-v1.2.3'} | ${'7.4'} | ${'add_relay relay-v1.2.3'} ${'relay-v1.2.3'} | ${'7.4'} | ${'add_relay relay-v1.2.3'}
${'relay-nightly'} | ${'8.6'} | ${'add_relay relay-nightly'}
${'sqlite'} | ${'7.4'} | ${'add_extension sqlite3'} ${'sqlite'} | ${'7.4'} | ${'add_extension sqlite3'}
${'sqlsrv-1.2.3-beta1'} | ${'7.4'} | ${'add_pecl_extension sqlsrv 1.2.3beta1 extension'} ${'sqlsrv-1.2.3-beta1'} | ${'7.4'} | ${'add_pecl_extension sqlsrv 1.2.3beta1 extension'}
${'Xdebug'} | ${'7.4'} | ${'add_extension xdebug'} ${'Xdebug'} | ${'7.4'} | ${'add_extension xdebug'}
@@ -107,6 +108,7 @@ describe('Extension tests', () => {
${'pdo_oci'} | ${'7.3'} | ${'add_oci pdo_oci'} ${'pdo_oci'} | ${'7.3'} | ${'add_oci pdo_oci'}
${'pecl_http'} | ${'7.3'} | ${'add_http'} ${'pecl_http'} | ${'7.3'} | ${'add_http'}
${'relay-1.2.3'} | ${'7.4'} | ${'add_relay relay-1.2.3'} ${'relay-1.2.3'} | ${'7.4'} | ${'add_relay relay-1.2.3'}
${'relay-nightly'} | ${'8.6'} | ${'add_relay relay-nightly'}
${'sqlite'} | ${'7.2'} | ${'add_extension sqlite3'} ${'sqlite'} | ${'7.2'} | ${'add_extension sqlite3'}
${'xdebug2'} | ${'7.4'} | ${'add_brew_extension xdebug2 zend_extension 2.9.8'} ${'xdebug2'} | ${'7.4'} | ${'add_brew_extension xdebug2 zend_extension 2.9.8'}
${'zephir_parser-v1.2.3'} | ${'7.2'} | ${'add_zephir_parser zephir_parser-v1.2.3'} ${'zephir_parser-v1.2.3'} | ${'7.2'} | ${'add_zephir_parser zephir_parser-v1.2.3'}
+4
View File
@@ -21,6 +21,10 @@ it('checking fetch', async () => {
nock(host_url) nock(host_url)
.get('/manifest') .get('/manifest')
.matchHeader(
'user-agent',
`setup-php (${process.platform}; ${process.arch}; +https://setup-php.com)`
)
.reply(200, {latest: 'latest'}) .reply(200, {latest: 'latest'})
.get('/manifest') .get('/manifest')
.matchHeader('authorization', 'Bearer invalid_token') .matchHeader('authorization', 'Bearer invalid_token')
+1 -1
View File
File diff suppressed because one or more lines are too long
+4 -4
View File
@@ -31,14 +31,14 @@ export async function addExtensionDarwin(
case /.+-.+\/.+@.+/.test(extension): case /.+-.+\/.+@.+/.test(extension):
add_script += await utils.parseExtensionSource(extension, ext_prefix); add_script += await utils.parseExtensionSource(extension, ext_prefix);
return; return;
// match 7.4relay...8.5relay // match 7.4relay...8.6relay
// match 5.3blackfire...8.5blackfire // match 5.3blackfire...8.5blackfire
// match 5.3blackfire-(semver)...8.5blackfire-(semver) // match 5.3blackfire-(semver)...8.5blackfire-(semver)
// match couchbase, event, geos, ibm_db2, pdo_ibm, pdo_oci, oci8, http, pecl_http // match couchbase, event, geos, ibm_db2, pdo_ibm, pdo_oci, oci8, http, pecl_http
// match 5.3ioncube...8.5ioncube // match 5.3ioncube...8.5ioncube
// match 7.0phalcon3...7.3phalcon3, 7.2phalcon4...7.4phalcon4, and 7.4phalcon5...8.4phalcon5 // match 7.0phalcon3...7.3phalcon3, 7.2phalcon4...7.4phalcon4, and 7.4phalcon5...8.4phalcon5
// match 7.0zephir_parser...8.5zephir_parser // match 7.0zephir_parser...8.5zephir_parser
case /^(7\.4|8\.[0-5])relay(-v?\d+\.\d+\.\d+|-nightly)?$/.test( case /^(7\.4|8\.[0-6])relay(-v?\d+\.\d+\.\d+|-nightly)?$/.test(
version_extension version_extension
): ):
case /^(5\.[3-6]|7\.[0-4]|8\.[0-5])blackfire(-\d+\.\d+\.\d+)?$/.test( case /^(5\.[3-6]|7\.[0-4]|8\.[0-5])blackfire(-\d+\.\d+\.\d+)?$/.test(
@@ -277,7 +277,7 @@ export async function addExtensionLinux(
case /.+-.+\/.+@.+/.test(extension): case /.+-.+\/.+@.+/.test(extension):
add_script += await utils.parseExtensionSource(extension, ext_prefix); add_script += await utils.parseExtensionSource(extension, ext_prefix);
return; return;
// match 7.4relay...8.5relay // match 7.4relay...8.6relay
// match 5.3blackfire...8.5blackfire // match 5.3blackfire...8.5blackfire
// match 5.3blackfire-(semver)...8.5blackfire-(semver) // match 5.3blackfire-(semver)...8.5blackfire-(semver)
// match 5.3pdo_cubrid...7.2php_cubrid, 5.3cubrid...7.4cubrid // match 5.3pdo_cubrid...7.2php_cubrid, 5.3cubrid...7.4cubrid
@@ -285,7 +285,7 @@ export async function addExtensionLinux(
// match 5.3ioncube...8.5ioncube // match 5.3ioncube...8.5ioncube
// match 7.0phalcon3...7.3phalcon3, 7.2phalcon4...7.4phalcon4, 7.4phalcon5...8.4phalcon5 // match 7.0phalcon3...7.3phalcon3, 7.2phalcon4...7.4phalcon4, 7.4phalcon5...8.4phalcon5
// match 7.0zephir_parser...8.5zephir_parser // match 7.0zephir_parser...8.5zephir_parser
case /^(7\.4|8\.[0-5])relay(-v?\d+\.\d+\.\d+|-nightly)?$/.test( case /^(7\.4|8\.[0-6])relay(-v?\d+\.\d+\.\d+|-nightly)?$/.test(
version_extension version_extension
): ):
case /^(5\.[3-6]|7\.[0-4]|8\.[0-5])blackfire(-\d+\.\d+\.\d+)?$/.test( case /^(5\.[3-6]|7\.[0-4]|8\.[0-5])blackfire(-\d+\.\d+\.\d+)?$/.test(
+1 -1
View File
@@ -16,7 +16,7 @@ export async function fetch(
redirect_count = 5 redirect_count = 5
): Promise<Record<string, string>> { ): Promise<Record<string, string>> {
const headers: Record<string, string> = { const headers: Record<string, string> = {
'User-Agent': `Mozilla/5.0 (${process.platform} ${process.arch}) setup-php` 'User-Agent': `setup-php (${process.platform}; ${process.arch}; +https://setup-php.com)`
}; };
if (auth_token) { if (auth_token) {
headers['Authorization'] = 'Bearer ' + auth_token; headers['Authorization'] = 'Bearer ' + auth_token;
+6 -2
View File
@@ -124,7 +124,11 @@ add_devtools() {
# Function to setup PHP from the shivammathur/php-builder builds. # Function to setup PHP from the shivammathur/php-builder builds.
setup_php_builder() { setup_php_builder() {
run_script "php-builder" "${runner:?}" "$version" "${debug:?}" "${ts:?}" if [[ -n "${asan:-}" && "$version" =~ ${no_asan_builds:?} ]]; then
add_log "${cross:?}" "PHP" "ASAN is only supported for PHP 8.0+"
exit 1
fi
run_script "php-builder" "${runner:?}" "$version" "${debug:?}" "${ts:?}" "${asan:-}"
} }
# Function to setup PHP 5.3, PHP 5.4 and PHP 5.5. # Function to setup PHP 5.3, PHP 5.4 and PHP 5.5.
@@ -237,7 +241,7 @@ update_php() {
# Function to install PHP. # Function to install PHP.
add_php() { add_php() {
if [ "${runner:?}" = "self-hosted" ] || [ "${use_builds_cache:-true}" = "false" ]; then if [ "${runner:?}" = "self-hosted" ] || [ "${use_builds_cache:-true}" = "false" ]; then
if [[ "$version" =~ ${php_builder_versions:?} || "$ts" = "zts" ]]; then if [[ "$version" =~ ${php_builder_versions:?} || "$ts" = "zts" || -n "${asan:-}" ]]; then
setup_php_builder setup_php_builder
else else
add_packaged_php add_packaged_php
+3 -2
View File
@@ -304,9 +304,10 @@ Function Add-Tool() {
} else { } else {
$backup_path = "$tool_path.bak" $backup_path = "$tool_path.bak"
if (Test-Path $tool_path) { Copy-Item $tool_path -Destination $backup_path -Force } if (Test-Path $tool_path) { Copy-Item $tool_path -Destination $backup_path -Force }
$user_agent = "setup-php ($env:RUNNER_OS; $env:RUNNER_ARCH; +https://setup-php.com)"
foreach ($url in $urls){ foreach ($url in $urls){
try { try {
$status_code = (Invoke-WebRequest -Passthru -Uri $url -OutFile $tool_path).StatusCode $status_code = (Invoke-WebRequest -Passthru -Uri $url -UserAgent $user_agent -OutFile $tool_path).StatusCode
} catch { } catch {
$status_code = 0 $status_code = 0
if($url -match '^https://github\.com/[^/]+/[^/]+/releases/latest/download/[^/?#]+$') { if($url -match '^https://github\.com/[^/]+/[^/]+/releases/latest/download/[^/?#]+$') {
@@ -314,7 +315,7 @@ Function Add-Tool() {
$release_url = Get-LastRelease $url $release_url = Get-LastRelease $url
if ($release_url) { if ($release_url) {
$url = $release_url $url = $release_url
$status_code = (Invoke-WebRequest -Passthru -Uri $url -OutFile $tool_path).StatusCode $status_code = (Invoke-WebRequest -Passthru -Uri $url -UserAgent $user_agent -OutFile $tool_path).StatusCode
} }
} catch { } catch {
$status_code = 0 $status_code = 0
+11 -2
View File
@@ -224,6 +224,12 @@ get_last_release() {
done done
} }
# Download a tool with the setup-php user agent.
download_tool() {
local curl_opts=("${curl_opts[@]}" -A "setup-php ($RUNNER_OS; $RUNNER_ARCH; +https://setup-php.com)")
get -v -e "$@"
}
# Function to setup a remote tool. # Function to setup a remote tool.
add_tool() { add_tool() {
url=$1 url=$1
@@ -263,12 +269,15 @@ add_tool() {
fi fi
else else
[ -f "$tool_path" ] && sudo cp -a "$tool_path" "$tool_path.bak" [ -f "$tool_path" ] && sudo cp -a "$tool_path" "$tool_path.bak"
status_code=$(get -v -e "$tool_path" "${url[@]}") # Tools are single files, so let servers gzip them in transit when curl can decode it.
local curl_opts=("${curl_opts[@]}")
curl -V | grep -qw libz && curl_opts+=(--compressed)
status_code=$(download_tool "$tool_path" "${url[@]}")
if [ "$status_code" != "200" ] && [[ "${url[0]}" =~ ^https://github\.com/[^/]+/[^/]+/releases/latest/download/[^/?#]+$ ]]; then if [ "$status_code" != "200" ] && [[ "${url[0]}" =~ ^https://github\.com/[^/]+/[^/]+/releases/latest/download/[^/?#]+$ ]]; then
local release_url local release_url
if release_url=$(get_last_release "${url[0]}"); then if release_url=$(get_last_release "${url[0]}"); then
url[0]="$release_url" url[0]="$release_url"
status_code=$(get -v -e "$tool_path" "${url[0]}") status_code=$(download_tool "$tool_path" "${url[0]}")
fi fi
fi fi
if [ "$status_code" = "200" ]; then if [ "$status_code" = "200" ]; then
+3
View File
@@ -7,6 +7,7 @@ export jit_versions="8.[0-9]"
export php_builder_versions="8.[3-9]" export php_builder_versions="8.[3-9]"
export nightly_versions="8.[7-9]" export nightly_versions="8.[7-9]"
export xdebug3_versions="7.[2-4]|8.[0-9]" export xdebug3_versions="7.[2-4]|8.[0-9]"
export no_asan_builds="5.[3-6]|7.[0-4]"
export latest="releases/latest/download" export latest="releases/latest/download"
export github="https://github.com/shivammathur" export github="https://github.com/shivammathur"
export jsdeliver="https://cdn.jsdelivr.net/gh/shivammathur" export jsdeliver="https://cdn.jsdelivr.net/gh/shivammathur"
@@ -84,6 +85,7 @@ read_env() {
update="${update:-${UPDATE:-false}}" update="${update:-${UPDATE:-false}}"
[ "${debug:-${DEBUG:-false}}" = "true" ] && debug=debug && update=true || debug=release [ "${debug:-${DEBUG:-false}}" = "true" ] && debug=debug && update=true || debug=release
[[ "${phpts:-${PHPTS:-nts}}" = "ts" || "${phpts:-${PHPTS:-nts}}" = "zts" ]] && ts=zts && update=true || ts=nts [[ "${phpts:-${PHPTS:-nts}}" = "ts" || "${phpts:-${PHPTS:-nts}}" = "zts" ]] && ts=zts && update=true || ts=nts
[[ "${asan:-${ASAN:-false}}" = "true" ]] && asan=asan && update=true || asan=
fail_fast="${fail_fast:-${FAIL_FAST:-false}}" fail_fast="${fail_fast:-${FAIL_FAST:-false}}"
use_builds_cache="${use_builds_cache:-${use_package_cache:-}}" use_builds_cache="${use_builds_cache:-${use_package_cache:-}}"
[[ ( -z "$ImageOS" && -z "$ImageVersion" ) || [[ ( -z "$ImageOS" && -z "$ImageVersion" ) ||
@@ -120,6 +122,7 @@ read_env() {
export runner export runner
export update export update
export ts export ts
export asan
export tool_path_dir export tool_path_dir
export tool_cache_path_dir export tool_cache_path_dir
} }