Skip to content

Commit

Permalink
Add support to use existing COMPOSER_PROCESS_TIMEOUT
Browse files Browse the repository at this point in the history
  • Loading branch information
shivammathur committed Feb 22, 2024
1 parent 1a5ac4a commit a6ce3f5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,16 @@ These tools can be set up globally using the `tools` input. It accepts a string
- If you do not want to use all your dev-dependencies in workflow, you can run composer with `--no-dev` and install required tools using `tools` input to speed up your workflow.
- By default, `COMPOSER_NO_INTERACTION` is set to `1` and `COMPOSER_PROCESS_TIMEOUT` is set to `0`. In effect, this means that Composer commands in your scripts do not need to specify `--no-interaction`.
- Also, `COMPOSER_NO_AUDIT` is set to `1`. So if you want to audit your dependencies for security vulnerabilities, it is recommended to add a `composer audit` step before you install them.
- If you want to set a different `COMPOSER_PROCESS_TIMEOUT`, you can set it in your workflow file using the `env` keyword.

```yaml
- name: Setup PHP with composer and custom process timeout
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
env:
COMPOSER_PROCESS_TIMEOUT: 300
```

## :signal_strength: Coverage Support

Expand Down
10 changes: 9 additions & 1 deletion src/scripts/tools/add_tools.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Function Edit-ComposerConfig() {
if (-not(Test-Path $composer_json)) {
Set-Content -Path $composer_json -Value "{}"
}
Add-EnvPATH $src\configs\composer.env
Set-ComposerEnv
Add-Path $composer_bin
Set-ComposerAuth
}
Expand Down Expand Up @@ -52,6 +52,14 @@ Function Set-ComposerAuth() {
}
}

# Function to set composer environment variables.
Function Set-ComposerEnv() {
if ($env:COMPOSER_PROCESS_TIMEOUT) {
(Get-Content $src\configs\composer.env -Raw) -replace '(?m)^COMPOSER_PROCESS_TIMEOUT=.*$', "COMPOSER_PROCESS_TIMEOUT=$env:COMPOSER_PROCESS_TIMEOUT" | Set-Content $src\configs\composer.env
}
Add-EnvPATH $src\configs\composer.env
}

# Function to extract tool version.
Function Get-ToolVersion() {
Param (
Expand Down
12 changes: 11 additions & 1 deletion src/scripts/tools/add_tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ configure_composer() {
echo '{}' | tee "$composer_json" >/dev/null
chmod 644 "$composer_json"
fi
add_env_path "${src:?}"/configs/composer.env
set_composer_env
add_path "$composer_bin"
set_composer_auth
}
Expand All @@ -68,6 +68,16 @@ set_composer_auth() {
fi
}

# Function to set composer environment variables.
set_composer_env() {
composer_env="${src:?}"/configs/composer.env
if [ -n "$COMPOSER_PROCESS_TIMEOUT" ]; then
sed_arg="s/COMPOSER_PROCESS_TIMEOUT.*/COMPOSER_PROCESS_TIMEOUT=$COMPOSER_PROCESS_TIMEOUT/"
sed -i "$sed_arg" "$composer_env" 2>/dev/null || sed -i '' "$sed_arg" "$composer_env"
fi
add_env_path "$composer_env"
}

# Helper function to configure tools.
add_tools_helper() {
tool=$1
Expand Down

0 comments on commit a6ce3f5

Please sign in to comment.