Add ini_file input to set base php.ini

This commit is contained in:
Shivam Mathur
2022-01-25 13:43:49 +05:30
parent 147905fd60
commit a0a791cada
11 changed files with 132 additions and 23 deletions

View File

@ -57,12 +57,17 @@ export async function run(): Promise<void> {
const version: string = await utils.parseVersion(
await utils.getInput('php-version', true)
);
const ini_file: string = await utils.parseIniFile(
await utils.getInput('ini-file', false)
);
if (version) {
const os_version: string = process.platform;
const tool = await utils.scriptTool(os_version);
const script = os_version + (await utils.scriptExtension(os_version));
const location = await getScript(script, version, os_version);
await exec(await utils.joins(tool, location, version, __dirname));
await exec(
await utils.joins(tool, location, version, ini_file, __dirname)
);
} else {
core.setFailed('Unable to get the PHP version');
}

View File

@ -195,6 +195,18 @@ php_extra_version() {
fi
}
# Function to set php.ini
add_php_config() {
if ! [ -e "$ini_dir"/php.ini-development ]; then
sudo cp "$ini_dir"/php.ini "$ini_dir"/php.ini-development
fi
if [[ "$ini" = "production" || "$ini" = "development" ]]; then
sudo cp "$ini_dir"/php.ini-"$ini" "$ini_dir"/php.ini
elif [ "$ini" = "none" ]; then
echo '' | sudo tee "${ini_file[@]}" >/dev/null 2>&1
fi
}
# Function to Setup PHP.
setup_php() {
step_log "Setup PHP"
@ -234,8 +246,9 @@ setup_php() {
}
# Variables
version=$1
dist=$2
version=${1:-'8.1'}
ini=${2:-'production'}
dist=$3
php_formula=shivammathur/php/php@"$version"
brew_path="$(command -v brew)"
brew_path_dir="$(dirname "$brew_path")"

View File

@ -178,6 +178,27 @@ php_extra_version() {
fi
}
# Function to set php.ini
add_php_config() {
php_lib_dir=/usr/lib/php/"$version"
current_ini="$php_lib_dir"/php.ini-current
current=$(cat "$current_ini" 2>/dev/null)
if [ "$current" = "$ini" ]; then
return;
fi
if [[ "$ini" = "production" && "x$current" != "xproduction" ]]; then
echo "${ini_file[@]}" | xargs -n 1 -P 6 sudo cp "$php_lib_dir"/php.ini-production
if [ -e "$php_lib_dir"/php.ini-production.cli ]; then
sudo cp "$php_lib_dir"/php.ini-production.cli "$ini_dir"/php.ini
fi
elif [ "$ini" = "development" ]; then
echo "${ini_file[@]}" | xargs -n 1 -P 6 sudo cp "$php_lib_dir"/php.ini-development
elif [ "$ini" = "none" ]; then
echo '' | sudo tee "${ini_file[@]}" >/dev/null 2>&1
fi
echo "$ini" | sudo tee "$current_ini" >/dev/null 2>&1
}
# Function to Setup PHP
setup_php() {
step_log "Setup PHP"
@ -226,8 +247,9 @@ setup_php() {
}
# Variables
version=$1
dist=$2
version=${1:-'8.1'}
ini=${2:-'production'}
dist=$3
debconf_fix="DEBIAN_FRONTEND=noninteractive"
apt_install="sudo $debconf_fix apt-fast install -y --no-install-recommends"
scripts="${dist}"/../src/scripts

View File

@ -135,6 +135,7 @@ self_hosted_setup() {
# Function to configure PHP
configure_php() {
add_php_config
ini_config_dir="${dist:?}"/../src/configs/ini
ini_files=("$ini_config_dir"/php.ini)
[[ "$version" =~ $jit_versions ]] && ini_files+=("$ini_config_dir"/jit.ini)

View File

@ -8,6 +8,11 @@ param (
[ValidateNotNull()]
[ValidateLength(1, [int]::MaxValue)]
[string]
$ini = 'production',
[Parameter(Position = 2, Mandatory = $true)]
[ValidateNotNull()]
[ValidateLength(1, [int]::MaxValue)]
[string]
$dist
)
@ -166,10 +171,18 @@ Function Add-PhpCAInfo {
# Function to set PHP config.
Function Add-PhpConfig {
$current = Get-Content -Path $php_dir\php.ini-current -ErrorAction SilentlyContinue
if($ini -eq 'development' -or ($ini -eq 'production' -and $current -and $current -ne 'production')) {
Copy-Item -Path $php_dir\php.ini-$ini -Destination $php_dir\php.ini -Force
} elseif ($ini -eq 'none') {
Set-Content -Path $php_dir\php.ini -Value ''
}
Set-Content -Path $php_dir\php.ini-current -Value $ini
$ini_config_dir = "$dist\..\src\configs\ini"
$ini_files = @("$ini_config_dir\php.ini")
$version -match $jit_versions -and ($ini_files += ("$ini_config_dir\jit.ini")) > $null 2>&1
$version -match $xdebug3_versions -and ($ini_files += ("$ini_config_dir\xdebug.ini")) > $null 2>&1
Add-Content -Path $ini_config_dir\php.ini -Value extension_dir=$ext_dir
Get-Content -Path $ini_files | Add-Content -Path $php_dir\php.ini
}
@ -257,17 +270,18 @@ if ($null -eq $installed -or -not("$($installed.Version).".StartsWith(($version
$extra_version = " ($( Get-Content $php_dir\COMMIT ))"
}
} else {
Install-Php -Version $version -Architecture $arch -ThreadSafe $ts -InstallVC -Path $php_dir -TimeZone UTC -InitialPhpIni Production -Force > $null 2>&1
Install-Php -Version $version -Architecture $arch -ThreadSafe $ts -InstallVC -Path $php_dir -TimeZone UTC -InitialPhpIni production -Force > $null 2>&1
}
Add-PhpConfig
} catch { }
} else {
Set-PhpIniKey -Key 'extension_dir' -Value $ext_dir -Path $php_dir
if($env:update -eq 'true') {
Update-Php $php_dir >$null 2>&1
$status = "Updated to"
} else {
$status = "Found"
}
Add-PhpConfig
}
$installed = Get-Php -Path $php_dir
@ -282,7 +296,6 @@ if($version -lt "5.5") {
}
Enable-PhpExtension -Extension $enable_extensions -Path $php_dir
Add-PhpCAInfo
Add-PhpConfig
Copy-Item -Path $dist\..\src\configs\pm\*.json -Destination $env:RUNNER_TOOL_CACHE
Write-Output "::set-output name=php-version::$($installed.FullVersion)"
Add-Log $tick "PHP" "$status PHP $($installed.FullVersion)$extra_version"

View File

@ -114,6 +114,22 @@ export async function parseVersion(version: string): Promise<string> {
}
}
/**
* Function to parse ini file.
*
* @param ini_file
*/
export async function parseIniFile(ini_file: string): Promise<string> {
switch (true) {
case /^(production|development|none)$/.test(ini_file):
return ini_file;
case /php\.ini-(production|development)$/.test(ini_file):
return ini_file.split('-')[1];
default:
return 'production';
}
}
/**
* Async foreach loop
*