Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,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)
Expand Down Expand Up @@ -463,6 +464,13 @@ Disable coverage for these reasons:
- Accepts a `string` in csv-format. For example: `phpunit, phpcs`
- See [tools support](#wrench-tools-support) for tools supported.

#### `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.

#### `github-token` (optional)

- Specify the GitHub token to use for authentication.
Expand Down Expand Up @@ -621,6 +629,43 @@ 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 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'
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'
asan: true
env:
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.
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ inputs:
tools:
description: 'Setup popular tools globally.'
required: false
asan:
description: 'Setup PHP with Address Sanitizer (ASAN). PHP 8.0+ on Linux only.'
required: false
github-token:
description: 'GitHub token to use for authentication.'
default: ${{ github.token }}
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export async function getScript(os: string): Promise<string> {
export async function setEnv(): Promise<void> {
process.env['fail_fast'] = await utils.getInput('fail-fast', false);
process.env['GITHUB_TOKEN'] ??= await utils.getInput('github-token', false);
process.env['ASAN'] = await utils.getInput('asan', false);
}

/**
Expand Down
12 changes: 10 additions & 2 deletions src/scripts/linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ add_devtools() {

# Function to setup PHP from the shivammathur/php-builder builds.
setup_php_builder() {
run_script "php-builder" "${runner:?}" "$version" "${debug:?}" "${ts:?}"
run_script "php-builder" "${runner:?}" "$version" "${debug:?}" "${ts:?}" "${asan:-}"
}

# Function to setup PHP 5.3, PHP 5.4 and PHP 5.5.
Expand Down Expand Up @@ -186,7 +186,15 @@ update_php() {

# Function to install PHP.
add_php() {
if [ "${runner:?}" = "self-hosted" ] || [ "${use_package_cache:-true}" = "false" ]; then
# ASAN is only supported for PHP 8.0+
if [[ -n "${asan:-}" && ! "$version" =~ ^8\. ]]; then
add_log "${cross:?}" "PHP" "ASAN is only supported for PHP 8.0+"
exit 1
fi
# ASAN builds are only available from php-builder
if [[ -n "${asan:-}" ]]; then
setup_php_builder
elif [ "${runner:?}" = "self-hosted" ] || [ "${use_package_cache:-true}" = "false" ]; then
if [[ "$version" =~ ${php_builder_versions:?} || "$ts" = "zts" ]]; then
setup_php_builder
else
Expand Down
2 changes: 2 additions & 0 deletions src/scripts/unix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,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}}"
[[ ( -z "$ImageOS" && -z "$ImageVersion" ) ||
( -n "$RUNNER_ENVIRONMENT" && "$RUNNER_ENVIRONMENT" = "self-hosted" ) ||
Expand All @@ -78,6 +79,7 @@ read_env() {
export runner
export update
export ts
export asan
export tool_path_dir
}

Expand Down