mirror of
https://github.com/shivammathur/setup-php.git
synced 2024-11-22 20:01:06 +07:00
Refactor tools
Improve support for tool aliases
This commit is contained in:
parent
cff0bdeaa3
commit
739ccacdc4
@ -208,7 +208,7 @@ The version can be a branch name or tag as supported by `git clone -b <name>`. T
|
||||
|
||||
These tools can be setup globally using the `tools` input. It accepts a string in csv-format.
|
||||
|
||||
`behat`, `blackfire`, `blackfire-player`, `codeception`, `composer`, `composer-normalize`, `composer-prefetcher`, `composer-require-checker`, `composer-unused`, `cs2pr`, `deployer`, `flex`, `grpc_php_plugin`, `infection`, `pecl`, `phan`, `phing`, `phinx`, `phive`, `php-config`, `php-cs-fixer`, `phpcbf`, `phpcpd`, `phpcs`, `phpize`, `phplint`, `phpmd`, `phpspec`, `phpstan`, `phpunit`, `prestissimo`, `protoc`, `psalm`, `symfony`, `symfony-cli`, `vapor-cli`, `wp-cli`
|
||||
`behat`, `blackfire`, `blackfire-player`, `codeception`, `composer`, `composer-normalize`, `composer-prefetcher`, `composer-require-checker`, `composer-unused`, `cs2pr`, `deployer`, `flex`, `grpc_php_plugin`, `infection`, `pecl`, `phan`, `phing`, `phinx`, `phive`, `php-config`, `php-cs-fixer`, `phpcbf`, `phpcpd`, `phpcs`, `phpize`, `phplint`, `phpmd`, `phpspec`, `phpstan`, `phpunit`, `prestissimo`, `protoc`, `psalm`, `symfony` or `symfony-cli`, `vapor` or `vapor-cli`, `wp` or `wp-cli`
|
||||
|
||||
```yaml
|
||||
- name: Setup PHP with tools
|
||||
|
@ -410,7 +410,7 @@ describe('Tools tests', () => {
|
||||
'phpspec',
|
||||
'protoc:v1.2.3',
|
||||
'psalm',
|
||||
'symfony',
|
||||
'symfony-cli',
|
||||
'symfony:1.2.3',
|
||||
'vapor-cli',
|
||||
'wp-cli'
|
||||
@ -504,7 +504,7 @@ describe('Tools tests', () => {
|
||||
'phpize',
|
||||
'phpmd',
|
||||
'symfony',
|
||||
'wp-cli'
|
||||
'wp'
|
||||
];
|
||||
|
||||
const script: string = await tools.addTools(
|
||||
|
10
dist/index.js
vendored
10
dist/index.js
vendored
@ -2106,6 +2106,7 @@ async function addTools(tools_csv, php_version, os_version) {
|
||||
script += await utils.customPackage(tool, 'tools', version, os_version);
|
||||
break;
|
||||
case 'behat':
|
||||
case 'codeception':
|
||||
case 'phpspec':
|
||||
script += await addPackage(tool, release, tool + '/', os_version);
|
||||
break;
|
||||
@ -2113,9 +2114,6 @@ async function addTools(tools_csv, php_version, os_version) {
|
||||
url = await getBlackfirePlayerUrl(version, php_version);
|
||||
script += await addArchive(tool, url, os_version, '"-V"');
|
||||
break;
|
||||
case 'codeception':
|
||||
script += await addPackage(tool, release, 'codeception/', os_version);
|
||||
break;
|
||||
case 'composer':
|
||||
url = await getComposerUrl(version);
|
||||
script += await addArchive('composer', url, os_version, version);
|
||||
@ -2213,11 +2211,13 @@ async function addTools(tools_csv, php_version, os_version) {
|
||||
script += await addArchive('symfony', url, os_version, 'version');
|
||||
break;
|
||||
case 'vapor-cli':
|
||||
script += await addPackage(tool, release, 'laravel/', os_version);
|
||||
case 'vapor':
|
||||
script += await addPackage('vapor-cli', release, 'laravel/', os_version);
|
||||
break;
|
||||
case 'wp':
|
||||
case 'wp-cli':
|
||||
url = github + (await getWpCliUrl(version));
|
||||
script += await addArchive(tool, url, os_version, '"--version"');
|
||||
script += await addArchive('wp-cli', url, os_version, '"--version"');
|
||||
break;
|
||||
default:
|
||||
script += await utils.addLog('$cross', tool, 'Tool ' + tool + ' is not supported', os_version);
|
||||
|
7705
package-lock.json
generated
7705
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -218,21 +218,7 @@ add_tool() {
|
||||
status_code=$(get -v -e "$tool_path" "${url[0]}")
|
||||
fi
|
||||
if [ "$status_code" = "200" ]; then
|
||||
if [ "$tool" = "composer" ]; then
|
||||
configure_composer "$tool_path"
|
||||
elif [ "$tool" = "cs2pr" ]; then
|
||||
sudo sed -i 's/\r$//; s/exit(9)/exit(0)/' "$tool_path" 2>/dev/null ||
|
||||
sudo sed -i '' 's/\r$//; s/exit(9)/exit(0)/' "$tool_path"
|
||||
elif [ "$tool" = "phan" ]; then
|
||||
add_extension fileinfo extension >/dev/null 2>&1
|
||||
add_extension ast extension >/dev/null 2>&1
|
||||
elif [ "$tool" = "phive" ]; then
|
||||
add_extension curl extension >/dev/null 2>&1
|
||||
add_extension mbstring extension >/dev/null 2>&1
|
||||
add_extension xml extension >/dev/null 2>&1
|
||||
elif [ "$tool" = "wp-cli" ]; then
|
||||
sudo cp -p "$tool_path" "$tool_path_dir"/wp
|
||||
fi
|
||||
add_tools_helper "$tool"
|
||||
tool_version=$(get_tool_version "$tool" "$ver_param")
|
||||
add_log "$tick" "$tool" "Added $tool $tool_version"
|
||||
else
|
||||
@ -259,6 +245,7 @@ add_composertool() {
|
||||
tool_version=$(get_tool_version 'echo' "$json") &&
|
||||
add_log "$tick" "$tool" "Added $tool $tool_version"
|
||||
) || add_log "$cross" "$tool" "Could not setup $tool"
|
||||
add_tools_helper "$tool"
|
||||
if [ -e "$composer_bin/composer" ]; then
|
||||
sudo cp -p "$tool_path_dir/composer" "$composer_bin"
|
||||
fi
|
||||
|
@ -172,12 +172,14 @@ dist=$2
|
||||
brew_prefix="$(brew --prefix)"
|
||||
brew_repo="$(brew --repository)"
|
||||
tap_dir="$brew_repo"/Library/Taps
|
||||
scripts="${dist}"/../src/scripts
|
||||
export HOMEBREW_CHANGE_ARCH_TO_ARM=1
|
||||
export HOMEBREW_NO_INSTALL_CLEANUP=1
|
||||
export HOMEBREW_NO_AUTO_UPDATE=1
|
||||
|
||||
# shellcheck source=.
|
||||
. "${dist}"/../src/scripts/common.sh
|
||||
. "${scripts:?}"/tools/add_tools.sh
|
||||
. "${scripts:?}"/common.sh
|
||||
read_env
|
||||
self_hosted_setup
|
||||
setup_php
|
||||
|
@ -285,9 +285,11 @@ dist=$2
|
||||
debconf_fix="DEBIAN_FRONTEND=noninteractive"
|
||||
apt_install="sudo $debconf_fix apt-fast install -y"
|
||||
apt_remove="sudo $debconf_fix apt-fast remove -y"
|
||||
scripts="${dist}"/../src/scripts
|
||||
|
||||
# shellcheck source=.
|
||||
. "${dist}"/../src/scripts/common.sh
|
||||
. "${scripts:?}"/tools/add_tools.sh
|
||||
. "${scripts:?}"/common.sh
|
||||
. /etc/lsb-release
|
||||
read_env
|
||||
self_hosted_setup
|
||||
|
26
src/scripts/tools/add_tools.ps1
Normal file
26
src/scripts/tools/add_tools.ps1
Normal file
@ -0,0 +1,26 @@
|
||||
Function Add-ToolsHelper() {
|
||||
Param (
|
||||
[Parameter(Position = 0, Mandatory = $true)]
|
||||
[ValidateNotNull()]
|
||||
$tool
|
||||
)
|
||||
if($tool -eq "codeception") {
|
||||
Copy-Item $composer_bin\codecept.bat -Destination $composer_bin\codeception.bat
|
||||
} elseif($tool -eq "composer") {
|
||||
Edit-ComposerConfig $bin_dir\$tool
|
||||
} elseif($tool -eq "cs2pr") {
|
||||
(Get-Content $bin_dir/cs2pr).replace('exit(9)', 'exit(0)') | Set-Content $bin_dir/cs2pr
|
||||
} elseif($tool -eq "phan") {
|
||||
Add-Extension fileinfo >$null 2>&1
|
||||
Add-Extension ast >$null 2>&1
|
||||
} elseif($tool -eq "phive") {
|
||||
Add-Extension xml >$null 2>&1
|
||||
} elseif($tool -eq "symfony") {
|
||||
Add-ToProfile $current_profile "symfony" "New-Alias symfony $bin_dir\$tool.exe"
|
||||
Add-ToProfile $current_profile "symfony-cli" "New-Alias symfony-cli $bin_dir\$tool.exe"
|
||||
} elseif($tool -eq "vapor-cli") {
|
||||
Copy-Item $composer_bin\vapor.bat -Destination $composer_bin\vapor-cli.bat
|
||||
} elseif($tool -eq "wp-cli") {
|
||||
Copy-Item $bin_dir\wp-cli.bat -Destination $bin_dir\wp.bat
|
||||
}
|
||||
}
|
24
src/scripts/tools/add_tools.sh
Normal file
24
src/scripts/tools/add_tools.sh
Normal file
@ -0,0 +1,24 @@
|
||||
add_tools_helper() {
|
||||
tool=$1
|
||||
if [ "$tool" = "codeception" ]; then
|
||||
sudo ln -s "${composer_bin:?}"/codecept "${composer_bin:?}"/codeception
|
||||
elif [ "$tool" = "composer" ]; then
|
||||
configure_composer "${tool_path:?}"
|
||||
elif [ "$tool" = "cs2pr" ]; then
|
||||
sudo sed -i 's/\r$//; s/exit(9)/exit(0)/' "${tool_path:?}" 2>/dev/null ||
|
||||
sudo sed -i '' 's/\r$//; s/exit(9)/exit(0)/' "${tool_path:?}"
|
||||
elif [ "$tool" = "phan" ]; then
|
||||
add_extension fileinfo extension >/dev/null 2>&1
|
||||
add_extension ast extension >/dev/null 2>&1
|
||||
elif [ "$tool" = "phive" ]; then
|
||||
add_extension curl extension >/dev/null 2>&1
|
||||
add_extension mbstring extension >/dev/null 2>&1
|
||||
add_extension xml extension >/dev/null 2>&1
|
||||
elif [ "$tool" = "symfony" ]; then
|
||||
sudo ln -s "${tool_path:?}" "${tool_path_dir:?}"/symfony-cli
|
||||
elif [ "$tool" = "vapor-cli" ]; then
|
||||
sudo ln -s "${tool_path:?}" "${tool_path_dir:?}"/vapor-cli
|
||||
elif [ "$tool" = "wp-cli" ]; then
|
||||
sudo ln -s "${tool_path:?}" "${tool_path_dir:?}"/wp
|
||||
fi
|
||||
}
|
@ -245,20 +245,21 @@ Function Add-Tool() {
|
||||
if (Test-Path $bin_dir\$tool) {
|
||||
Remove-Item $bin_dir\$tool
|
||||
}
|
||||
if($url.Count -gt 1) { $url = $url[0] }
|
||||
if ($tool -eq "symfony") {
|
||||
Invoke-WebRequest -Uri $url -OutFile $bin_dir\$tool.exe
|
||||
Add-ToProfile $current_profile $tool "New-Alias $tool $bin_dir\$tool.exe" >$null 2>&1
|
||||
} else {
|
||||
try {
|
||||
Invoke-WebRequest -Uri $url -OutFile $bin_dir\$tool
|
||||
} catch {
|
||||
if($url -match '.*github.com.*releases.*latest.*') {
|
||||
try {
|
||||
$url = $url.replace("releases/latest/download", "releases/download/" + ([regex]::match((Invoke-WebRequest -Uri ($url.split('/release')[0] + "/releases")).Content, "([0-9]+\.[0-9]+\.[0-9]+)/" + ($url.Substring($url.LastIndexOf("/") + 1))).Groups[0].Value).split('/')[0])
|
||||
Invoke-WebRequest -Uri $url -OutFile $bin_dir\$tool
|
||||
} catch { }
|
||||
}
|
||||
if($url.Count -gt 1) {
|
||||
$url = $url[0]
|
||||
}
|
||||
$tool_path = "$bin_dir\$tool"
|
||||
if (($url | Split-Path -Extension) -eq ".exe") {
|
||||
$tool_path = "$tool_path.exe"
|
||||
}
|
||||
try {
|
||||
Invoke-WebRequest -Uri $url -OutFile $tool_path
|
||||
} catch {
|
||||
if($url -match '.*github.com.*releases.*latest.*') {
|
||||
try {
|
||||
$url = $url.replace("releases/latest/download", "releases/download/" + ([regex]::match((Invoke-WebRequest -Uri ($url.split('/release')[0] + "/releases")).Content, "([0-9]+\.[0-9]+\.[0-9]+)/" + ($url.Substring($url.LastIndexOf("/") + 1))).Groups[0].Value).split('/')[0])
|
||||
Invoke-WebRequest -Uri $url -OutFile $tool_path
|
||||
} catch { }
|
||||
}
|
||||
}
|
||||
if (((Get-ChildItem -Path $bin_dir/* | Where-Object Name -Match "^$tool(.exe|.phar)*$").Count -gt 0)) {
|
||||
@ -269,18 +270,7 @@ Function Add-Tool() {
|
||||
$bat_content += "php %BIN_TARGET% %*"
|
||||
Set-Content -Path $bin_dir\$tool.bat -Value $bat_content
|
||||
Add-ToProfile $current_profile $tool "New-Alias $tool $bin_dir\$tool.bat" >$null 2>&1
|
||||
if($tool -eq "phan") {
|
||||
Add-Extension fileinfo >$null 2>&1
|
||||
Add-Extension ast >$null 2>&1
|
||||
} elseif($tool -eq "phive") {
|
||||
Add-Extension xml >$null 2>&1
|
||||
} elseif($tool -eq "cs2pr") {
|
||||
(Get-Content $bin_dir/cs2pr).replace('exit(9)', 'exit(0)') | Set-Content $bin_dir/cs2pr
|
||||
} elseif($tool -eq "composer") {
|
||||
Edit-ComposerConfig $bin_dir\$tool
|
||||
} elseif($tool -eq "wp-cli") {
|
||||
Copy-Item $bin_dir\wp-cli.bat -Destination $bin_dir\wp.bat
|
||||
}
|
||||
Add-ToolsHelper $tool
|
||||
$tool_version = Get-ToolVersion $tool $ver_param
|
||||
Add-Log $tick $tool "Added $tool $tool_version"
|
||||
} else {
|
||||
@ -317,6 +307,7 @@ Function Add-Composertool() {
|
||||
if(Test-Path $composer_bin\composer) {
|
||||
Copy-Item -Path "$bin_dir\composer" -Destination "$composer_bin\composer" -Force
|
||||
}
|
||||
Add-ToolsHelper $tool
|
||||
if($json) {
|
||||
$tool_version = Get-ToolVersion "Write-Output" "$json"
|
||||
Add-Log $tick $tool "Added $tool $tool_version"
|
||||
@ -380,6 +371,8 @@ if($env:RUNNER -eq 'self-hosted') {
|
||||
}
|
||||
}
|
||||
|
||||
. $dist\..\src\scripts\tools\add_tools.ps1
|
||||
|
||||
Add-Printf >$null 2>&1
|
||||
Step-Log "Setup PhpManager"
|
||||
Install-PSPackage PhpManager PhpManager\PhpManager "$github/mlocati/powershell-phpmanager/releases/latest/download/PhpManager.zip" >$null 2>&1
|
||||
|
15
src/tools.ts
15
src/tools.ts
@ -410,6 +410,7 @@ export async function addTools(
|
||||
script += await utils.customPackage(tool, 'tools', version, os_version);
|
||||
break;
|
||||
case 'behat':
|
||||
case 'codeception':
|
||||
case 'phpspec':
|
||||
script += await addPackage(tool, release, tool + '/', os_version);
|
||||
break;
|
||||
@ -417,9 +418,6 @@ export async function addTools(
|
||||
url = await getBlackfirePlayerUrl(version, php_version);
|
||||
script += await addArchive(tool, url, os_version, '"-V"');
|
||||
break;
|
||||
case 'codeception':
|
||||
script += await addPackage(tool, release, 'codeception/', os_version);
|
||||
break;
|
||||
case 'composer':
|
||||
url = await getComposerUrl(version);
|
||||
script += await addArchive('composer', url, os_version, version);
|
||||
@ -522,11 +520,18 @@ export async function addTools(
|
||||
script += await addArchive('symfony', url, os_version, 'version');
|
||||
break;
|
||||
case 'vapor-cli':
|
||||
script += await addPackage(tool, release, 'laravel/', os_version);
|
||||
case 'vapor':
|
||||
script += await addPackage(
|
||||
'vapor-cli',
|
||||
release,
|
||||
'laravel/',
|
||||
os_version
|
||||
);
|
||||
break;
|
||||
case 'wp':
|
||||
case 'wp-cli':
|
||||
url = github + (await getWpCliUrl(version));
|
||||
script += await addArchive(tool, url, os_version, '"--version"');
|
||||
script += await addArchive('wp-cli', url, os_version, '"--version"');
|
||||
break;
|
||||
default:
|
||||
script += await utils.addLog(
|
||||
|
Loading…
Reference in New Issue
Block a user