From 002287894718d9dfbdffa87854de1434b9517db4 Mon Sep 17 00:00:00 2001 From: Shivam Mathur Date: Sat, 29 Jan 2022 12:14:42 +0530 Subject: [PATCH] Remove unnecessary dist parameter --- __tests__/install.test.ts | 27 +++++++++++------------ dist/index.js | 2 +- src/install.ts | 4 +--- src/scripts/darwin.sh | 8 +++---- src/scripts/extensions/add_extensions.ps1 | 2 +- src/scripts/extensions/add_extensions.sh | 2 +- src/scripts/linux.sh | 8 +++---- src/scripts/tools/add_tools.ps1 | 2 +- src/scripts/tools/add_tools.sh | 2 +- src/scripts/unix.sh | 2 +- src/scripts/win32.ps1 | 16 +++++--------- 11 files changed, 34 insertions(+), 41 deletions(-) diff --git a/__tests__/install.test.ts b/__tests__/install.test.ts index 3a7ecbbc1..2ab4cb3e5 100644 --- a/__tests__/install.test.ts +++ b/__tests__/install.test.ts @@ -32,8 +32,7 @@ jest.mock('../src/install', () => ({ tool, filename, version, - ini_file, - __dirname + ini_file ].join(' '); }) })); @@ -69,18 +68,18 @@ function setEnv( describe('Install', () => { it.each` version | os | extension_csv | ini_file | ini_values_csv | coverage_driver | tools | output - ${'7.3'} | ${'darwin'} | ${''} | ${'production'} | ${''} | ${''} | ${''} | ${'initial script bash darwin.sh 7.3 production ' + __dirname} - ${'7.3'} | ${'darwin'} | ${'a, b'} | ${'development'} | ${'a=b'} | ${'x'} | ${''} | ${'initial script install extensions set coverage driver edit php.ini bash darwin.sh 7.3 development ' + __dirname} - ${'7.4.1'} | ${'darwin'} | ${''} | ${'none'} | ${''} | ${''} | ${''} | ${'initial script bash darwin.sh 7.4 none ' + __dirname} - ${'8'} | ${'darwin'} | ${''} | ${''} | ${''} | ${''} | ${''} | ${'initial script bash darwin.sh 8.0 production ' + __dirname} - ${'8.0'} | ${'darwin'} | ${''} | ${'development'} | ${''} | ${''} | ${''} | ${'initial script bash darwin.sh 8.0 development ' + __dirname} - ${'8.1'} | ${'darwin'} | ${''} | ${'none'} | ${''} | ${''} | ${''} | ${'initial script bash darwin.sh 8.1 none ' + __dirname} - ${'7.3'} | ${'linux'} | ${''} | ${'invalid'} | ${''} | ${''} | ${''} | ${'initial script bash linux.sh 7.3 production ' + __dirname} - ${'7.3'} | ${'linux'} | ${'a, b'} | ${'development'} | ${'a=b'} | ${'x'} | ${'phpunit'} | ${'initial script install extensions add_tool set coverage driver edit php.ini bash linux.sh 7.3 development ' + __dirname} - ${'latest'} | ${'linux'} | ${''} | ${'none'} | ${''} | ${''} | ${''} | ${'initial script bash linux.sh 8.1 none ' + __dirname} - ${'7.0'} | ${'win32'} | ${''} | ${'production'} | ${''} | ${''} | ${''} | ${'initial script pwsh win32.ps1 7.0 production ' + __dirname} - ${'7.3'} | ${'win32'} | ${''} | ${'development'} | ${''} | ${''} | ${''} | ${'initial script pwsh win32.ps1 7.3 development ' + __dirname} - ${'7.3'} | ${'win32'} | ${'a, b'} | ${'none'} | ${'a=b'} | ${'x'} | ${''} | ${'initial script install extensions set coverage driver edit php.ini pwsh win32.ps1 7.3 none ' + __dirname} + ${'7.3'} | ${'darwin'} | ${''} | ${'production'} | ${''} | ${''} | ${''} | ${'initial script bash darwin.sh 7.3 production'} + ${'7.3'} | ${'darwin'} | ${'a, b'} | ${'development'} | ${'a=b'} | ${'x'} | ${''} | ${'initial script install extensions set coverage driver edit php.ini bash darwin.sh 7.3 development'} + ${'7.4.1'} | ${'darwin'} | ${''} | ${'none'} | ${''} | ${''} | ${''} | ${'initial script bash darwin.sh 7.4 none'} + ${'8'} | ${'darwin'} | ${''} | ${''} | ${''} | ${''} | ${''} | ${'initial script bash darwin.sh 8.0 production'} + ${'8.0'} | ${'darwin'} | ${''} | ${'development'} | ${''} | ${''} | ${''} | ${'initial script bash darwin.sh 8.0 development'} + ${'8.1'} | ${'darwin'} | ${''} | ${'none'} | ${''} | ${''} | ${''} | ${'initial script bash darwin.sh 8.1 none'} + ${'7.3'} | ${'linux'} | ${''} | ${'invalid'} | ${''} | ${''} | ${''} | ${'initial script bash linux.sh 7.3 production'} + ${'7.3'} | ${'linux'} | ${'a, b'} | ${'development'} | ${'a=b'} | ${'x'} | ${'phpunit'} | ${'initial script install extensions add_tool set coverage driver edit php.ini bash linux.sh 7.3 development'} + ${'latest'} | ${'linux'} | ${''} | ${'none'} | ${''} | ${''} | ${''} | ${'initial script bash linux.sh 8.1 none'} + ${'7.0'} | ${'win32'} | ${''} | ${'production'} | ${''} | ${''} | ${''} | ${'initial script pwsh win32.ps1 7.0 production'} + ${'7.3'} | ${'win32'} | ${''} | ${'development'} | ${''} | ${''} | ${''} | ${'initial script pwsh win32.ps1 7.3 development'} + ${'7.3'} | ${'win32'} | ${'a, b'} | ${'none'} | ${'a=b'} | ${'x'} | ${''} | ${'initial script install extensions set coverage driver edit php.ini pwsh win32.ps1 7.3 none'} `( 'Test install on $os for $version with extensions=$extension_csv, ini_values=$ini_values_csv, coverage_driver=$coverage_driver, tools=$tools', async ({ diff --git a/dist/index.js b/dist/index.js index 001eb54ba..0446df381 100644 --- a/dist/index.js +++ b/dist/index.js @@ -481,7 +481,7 @@ async function run() { const tool = await utils.scriptTool(os); const script = os + (await utils.scriptExtension(os)); const location = await getScript(script, version, os); - await (0, exec_1.exec)(await utils.joins(tool, location, version, ini_file, __dirname)); + await (0, exec_1.exec)(await utils.joins(tool, location, version, ini_file)); } else { core.setFailed('Unable to get the PHP version'); diff --git a/src/install.ts b/src/install.ts index 9a041f2cd..69e59f007 100644 --- a/src/install.ts +++ b/src/install.ts @@ -69,9 +69,7 @@ export async function run(): Promise { const tool = await utils.scriptTool(os); const script = os + (await utils.scriptExtension(os)); const location = await getScript(script, version, os); - await exec( - await utils.joins(tool, location, version, ini_file, __dirname) - ); + await exec(await utils.joins(tool, location, version, ini_file)); } else { core.setFailed('Unable to get the PHP version'); } diff --git a/src/scripts/darwin.sh b/src/scripts/darwin.sh index 8dc624a7d..72505d707 100644 --- a/src/scripts/darwin.sh +++ b/src/scripts/darwin.sh @@ -64,7 +64,7 @@ add_brew_tap() { add_brew_extension() { formula=$1 prefix=$2 - extension=$(grep "$formula=" "$dist"/../src/configs/brew_extensions | cut -d '=' -f 2) + extension=$(grep "$formula=" "$src"/configs/brew_extensions | cut -d '=' -f 2) [[ -z "$extension" ]] && extension="$(echo "$formula" | sed -E "s/pecl_|[0-9]//g")" enable_extension "$extension" "$prefix" if check_extension "$extension"; then @@ -240,7 +240,7 @@ setup_php() { exit 1 fi - sudo cp "$dist"/../src/configs/pm/*.json "$RUNNER_TOOL_CACHE/" + sudo cp "$src"/configs/pm/*.json "$RUNNER_TOOL_CACHE/" echo "::set-output name=php-version::$semver" add_log "$tick" "PHP" "$status PHP $semver$extra_version" } @@ -248,7 +248,7 @@ setup_php() { # Variables version=${1:-'8.1'} ini=${2:-'production'} -dist=$3 +src=${0%/*}/.. php_formula=shivammathur/php/php@"$version" brew_path="$(command -v brew)" brew_path_dir="$(dirname "$brew_path")" @@ -256,7 +256,7 @@ brew_prefix="$brew_path_dir"/.. brew_repo="$brew_path_dir/$(dirname "$(readlink "$brew_path")")"/.. tap_dir="$brew_repo"/Library/Taps core_repo="$tap_dir"/homebrew/homebrew-core -scripts="${dist}"/../src/scripts +scripts="$src"/scripts ext_tap=shivammathur/homebrew-extensions php_tap=shivammathur/homebrew-php export HOMEBREW_CHANGE_ARCH_TO_ARM=1 diff --git a/src/scripts/extensions/add_extensions.ps1 b/src/scripts/extensions/add_extensions.ps1 index 2b66d6845..96c2090bf 100644 --- a/src/scripts/extensions/add_extensions.ps1 +++ b/src/scripts/extensions/add_extensions.ps1 @@ -82,7 +82,7 @@ Function Add-Extension { # Function to get a map of extensions and their dependent shared extensions. Function Get-ExtensionMap { - php -d'error_reporting=0' $dist\..\src\scripts\extensions\extension_map.php $env:TEMP\map$version.orig + php -d'error_reporting=0' $src\scripts\extensions\extension_map.php $env:TEMP\map$version.orig } # Function to enable extension dependencies which are also extensions. diff --git a/src/scripts/extensions/add_extensions.sh b/src/scripts/extensions/add_extensions.sh index 54a950748..539f36f2c 100644 --- a/src/scripts/extensions/add_extensions.sh +++ b/src/scripts/extensions/add_extensions.sh @@ -49,7 +49,7 @@ enable_extension() { # Function to get a map of extensions and their dependent shared extensions. get_extension_map() { - php -d'error_reporting=0' "${dist:?}"/../src/scripts/extensions/extension_map.php /tmp/map"$version".orig + php -d'error_reporting=0' "${src:?}"/scripts/extensions/extension_map.php /tmp/map"$version".orig } # Function to enable extension dependencies which are also extensions. diff --git a/src/scripts/linux.sh b/src/scripts/linux.sh index 82e91e1df..3b74268fe 100644 --- a/src/scripts/linux.sh +++ b/src/scripts/linux.sh @@ -130,7 +130,7 @@ switch_version() { add_packaged_php() { if [ "$runner" = "self-hosted" ] || [ "${use_package_cache:-true}" = "false" ]; then add_ppa ondrej/php >/dev/null 2>&1 || update_ppa ondrej/php - IFS=' ' read -r -a packages <<<"$(sed "s/[^ ]*/php$version-&/g" "$dist"/../src/configs/php_packages | tr '\n' ' ')" + IFS=' ' read -r -a packages <<<"$(sed "s/[^ ]*/php$version-&/g" "$src"/configs/php_packages | tr '\n' ' ')" install_packages "${packages[@]}" else run_script "php-ubuntu" "$version" @@ -241,7 +241,7 @@ setup_php() { configure_php sudo rm -rf /usr/local/bin/phpunit >/dev/null 2>&1 sudo chmod 777 "${ini_file[@]}" "$pecl_file" "${tool_path_dir:?}" - sudo cp "$dist"/../src/configs/pm/*.json "$RUNNER_TOOL_CACHE/" + sudo cp "$src"/configs/pm/*.json "$RUNNER_TOOL_CACHE/" echo "::set-output name=php-version::$semver" add_log "${tick:?}" "PHP" "$status PHP $semver$extra_version" } @@ -249,10 +249,10 @@ setup_php() { # Variables version=${1:-'8.1'} ini=${2:-'production'} -dist=$3 +src=${0%/*}/.. debconf_fix="DEBIAN_FRONTEND=noninteractive" apt_install="sudo $debconf_fix apt-fast install -y --no-install-recommends" -scripts="${dist}"/../src/scripts +scripts="$src"/scripts add_sudo diff --git a/src/scripts/tools/add_tools.ps1 b/src/scripts/tools/add_tools.ps1 index 4968c7bc0..6c653e9f7 100644 --- a/src/scripts/tools/add_tools.ps1 +++ b/src/scripts/tools/add_tools.ps1 @@ -22,7 +22,7 @@ Function Edit-ComposerConfig() { if (-not(Test-Path $composer_json)) { Set-Content -Path $composer_json -Value "{}" } - Add-EnvPATH $dist\..\src\configs\composer.env + Add-EnvPATH $src\configs\composer.env Add-Path $composer_bin if (Test-Path env:COMPOSER_TOKEN) { Add-Env COMPOSER_AUTH ('{"github-oauth": {"github.com": "' + $env:COMPOSER_TOKEN + '"}}') diff --git a/src/scripts/tools/add_tools.sh b/src/scripts/tools/add_tools.sh index fef1a773e..5df6e6cea 100644 --- a/src/scripts/tools/add_tools.sh +++ b/src/scripts/tools/add_tools.sh @@ -42,7 +42,7 @@ configure_composer() { echo '{}' | tee "$composer_json" >/dev/null chmod 644 "$composer_json" fi - add_env_path "${dist:?}"/../src/configs/composer.env + add_env_path "${src:?}"/configs/composer.env add_path "$composer_bin" if [ -n "$COMPOSER_TOKEN" ]; then add_env COMPOSER_AUTH '{"github-oauth": {"github.com": "'"$COMPOSER_TOKEN"'"}}' diff --git a/src/scripts/unix.sh b/src/scripts/unix.sh index dbee14e0d..a53d92afc 100644 --- a/src/scripts/unix.sh +++ b/src/scripts/unix.sh @@ -136,7 +136,7 @@ self_hosted_setup() { # Function to configure PHP configure_php() { add_php_config - ini_config_dir="${dist:?}"/../src/configs/ini + ini_config_dir="${src:?}"/configs/ini ini_files=("$ini_config_dir"/php.ini) [[ "$version" =~ $jit_versions ]] && ini_files+=("$ini_config_dir"/jit.ini) [[ "$version" =~ $xdebug3_versions ]] && ini_files+=("$ini_config_dir"/xdebug.ini) diff --git a/src/scripts/win32.ps1 b/src/scripts/win32.ps1 index 0db6999d0..b556cc440 100644 --- a/src/scripts/win32.ps1 +++ b/src/scripts/win32.ps1 @@ -8,12 +8,7 @@ param ( [ValidateNotNull()] [ValidateLength(1, [int]::MaxValue)] [string] - $ini = 'production', - [Parameter(Position = 2, Mandatory = $true)] - [ValidateNotNull()] - [ValidateLength(1, [int]::MaxValue)] - [string] - $dist + $ini = 'production' ) # Function to log start of a operation. @@ -178,7 +173,7 @@ Function Add-PhpConfig { 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_config_dir = "$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 @@ -261,8 +256,9 @@ if($env:RUNNER -eq 'self-hosted' -or (-not($env:ImageOS) -and -not($env:ImageVer } } -. $dist\..\src\scripts\tools\add_tools.ps1 -. $dist\..\src\scripts\extensions\add_extensions.ps1 +$src = Join-Path -Path $PSScriptRoot -ChildPath \.. +. $src\scripts\tools\add_tools.ps1 +. $src\scripts\extensions\add_extensions.ps1 Add-Printf >$null 2>&1 Step-Log "Setup PhpManager" @@ -319,6 +315,6 @@ if($version -lt "5.5") { } Enable-PhpExtension -Extension $enable_extensions -Path $php_dir Add-PhpCAInfo -Copy-Item -Path $dist\..\src\configs\pm\*.json -Destination $env:RUNNER_TOOL_CACHE +Copy-Item -Path $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"