Refactor tools

Improve support for tool aliases
This commit is contained in:
Shivam Mathur 2021-02-20 10:15:25 +05:30
parent cff0bdeaa3
commit 739ccacdc4
No known key found for this signature in database
GPG Key ID: 3E13E4C8591ACC2A
11 changed files with 96 additions and 7760 deletions

View File

@ -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

View File

@ -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
View File

@ -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

File diff suppressed because it is too large Load Diff

View File

@ -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

View File

@ -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

View File

@ -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

View 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
}
}

View 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
}

View File

@ -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

View File

@ -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(