mirror of
https://github.com/shivammathur/setup-php.git
synced 2026-12-06 09:50:56 +00:00
Compare commits
4
Commits
main
...
florian/asan
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
abf2248889 | ||
|
|
fad0ff9c5d | ||
|
|
66f29b02f3 | ||
|
|
940ea09f22 |
@@ -44,6 +44,7 @@ Setup PHP with required extensions, php.ini configuration, code-coverage support
|
||||
- [Nightly Build Setup](#nightly-build-setup)
|
||||
- [Debug Build Setup](#debug-build-setup)
|
||||
- [Thread Safe Setup](#thread-safe-setup)
|
||||
- [ASAN Build Setup](#asan-build-setup)
|
||||
- [Force Update Setup](#force-update-setup)
|
||||
- [Verbose Setup](#verbose-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`.
|
||||
- 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)
|
||||
|
||||
- Specify to update PHP on the runner to the latest patch version.
|
||||
@@ -652,6 +660,44 @@ jobs:
|
||||
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
|
||||
|
||||
> Update to the latest patch of PHP versions.
|
||||
|
||||
@@ -72,6 +72,7 @@ describe('Extension tests', () => {
|
||||
${'phalcon3'} | ${'7.3'} | ${'add_phalcon phalcon3'}
|
||||
${'relay'} | ${'7.4'} | ${'add_relay relay'}
|
||||
${'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'}
|
||||
${'sqlsrv-1.2.3-beta1'} | ${'7.4'} | ${'add_pecl_extension sqlsrv 1.2.3beta1 extension'}
|
||||
${'Xdebug'} | ${'7.4'} | ${'add_extension xdebug'}
|
||||
@@ -107,6 +108,7 @@ describe('Extension tests', () => {
|
||||
${'pdo_oci'} | ${'7.3'} | ${'add_oci pdo_oci'}
|
||||
${'pecl_http'} | ${'7.3'} | ${'add_http'}
|
||||
${'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'}
|
||||
${'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'}
|
||||
|
||||
@@ -21,6 +21,10 @@ it('checking fetch', async () => {
|
||||
|
||||
nock(host_url)
|
||||
.get('/manifest')
|
||||
.matchHeader(
|
||||
'user-agent',
|
||||
`setup-php (${process.platform}; ${process.arch}; +https://setup-php.com)`
|
||||
)
|
||||
.reply(200, {latest: 'latest'})
|
||||
.get('/manifest')
|
||||
.matchHeader('authorization', 'Bearer invalid_token')
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
+4
-4
@@ -31,14 +31,14 @@ export async function addExtensionDarwin(
|
||||
case /.+-.+\/.+@.+/.test(extension):
|
||||
add_script += await utils.parseExtensionSource(extension, ext_prefix);
|
||||
return;
|
||||
// match 7.4relay...8.5relay
|
||||
// match 7.4relay...8.6relay
|
||||
// match 5.3blackfire...8.5blackfire
|
||||
// match 5.3blackfire-(semver)...8.5blackfire-(semver)
|
||||
// match couchbase, event, geos, ibm_db2, pdo_ibm, pdo_oci, oci8, http, pecl_http
|
||||
// match 5.3ioncube...8.5ioncube
|
||||
// match 7.0phalcon3...7.3phalcon3, 7.2phalcon4...7.4phalcon4, and 7.4phalcon5...8.4phalcon5
|
||||
// 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
|
||||
):
|
||||
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):
|
||||
add_script += await utils.parseExtensionSource(extension, ext_prefix);
|
||||
return;
|
||||
// match 7.4relay...8.5relay
|
||||
// match 7.4relay...8.6relay
|
||||
// match 5.3blackfire...8.5blackfire
|
||||
// match 5.3blackfire-(semver)...8.5blackfire-(semver)
|
||||
// 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 7.0phalcon3...7.3phalcon3, 7.2phalcon4...7.4phalcon4, 7.4phalcon5...8.4phalcon5
|
||||
// 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
|
||||
):
|
||||
case /^(5\.[3-6]|7\.[0-4]|8\.[0-5])blackfire(-\d+\.\d+\.\d+)?$/.test(
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ export async function fetch(
|
||||
redirect_count = 5
|
||||
): Promise<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) {
|
||||
headers['Authorization'] = 'Bearer ' + auth_token;
|
||||
|
||||
@@ -124,7 +124,11 @@ add_devtools() {
|
||||
|
||||
# Function to setup PHP from the shivammathur/php-builder builds.
|
||||
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.
|
||||
@@ -237,7 +241,7 @@ update_php() {
|
||||
# Function to install PHP.
|
||||
add_php() {
|
||||
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
|
||||
else
|
||||
add_packaged_php
|
||||
|
||||
@@ -304,9 +304,10 @@ Function Add-Tool() {
|
||||
} else {
|
||||
$backup_path = "$tool_path.bak"
|
||||
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){
|
||||
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 {
|
||||
$status_code = 0
|
||||
if($url -match '^https://github\.com/[^/]+/[^/]+/releases/latest/download/[^/?#]+$') {
|
||||
@@ -314,7 +315,7 @@ Function Add-Tool() {
|
||||
$release_url = Get-LastRelease $url
|
||||
if ($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 {
|
||||
$status_code = 0
|
||||
|
||||
@@ -224,6 +224,12 @@ get_last_release() {
|
||||
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.
|
||||
add_tool() {
|
||||
url=$1
|
||||
@@ -263,12 +269,15 @@ add_tool() {
|
||||
fi
|
||||
else
|
||||
[ -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
|
||||
local release_url
|
||||
if release_url=$(get_last_release "${url[0]}"); then
|
||||
url[0]="$release_url"
|
||||
status_code=$(get -v -e "$tool_path" "${url[0]}")
|
||||
status_code=$(download_tool "$tool_path" "${url[0]}")
|
||||
fi
|
||||
fi
|
||||
if [ "$status_code" = "200" ]; then
|
||||
|
||||
@@ -7,6 +7,7 @@ export jit_versions="8.[0-9]"
|
||||
export php_builder_versions="8.[3-9]"
|
||||
export nightly_versions="8.[7-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 github="https://github.com/shivammathur"
|
||||
export jsdeliver="https://cdn.jsdelivr.net/gh/shivammathur"
|
||||
@@ -84,6 +85,7 @@ read_env() {
|
||||
update="${update:-${UPDATE:-false}}"
|
||||
[ "${debug:-${DEBUG:-false}}" = "true" ] && debug=debug && update=true || debug=release
|
||||
[[ "${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}}"
|
||||
use_builds_cache="${use_builds_cache:-${use_package_cache:-}}"
|
||||
[[ ( -z "$ImageOS" && -z "$ImageVersion" ) ||
|
||||
@@ -120,6 +122,7 @@ read_env() {
|
||||
export runner
|
||||
export update
|
||||
export ts
|
||||
export asan
|
||||
export tool_path_dir
|
||||
export tool_cache_path_dir
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user