mirror of
https://github.com/shivammathur/setup-php.git
synced 2024-11-23 04:11: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.
|
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
|
```yaml
|
||||||
- name: Setup PHP with tools
|
- name: Setup PHP with tools
|
||||||
|
@ -410,7 +410,7 @@ describe('Tools tests', () => {
|
|||||||
'phpspec',
|
'phpspec',
|
||||||
'protoc:v1.2.3',
|
'protoc:v1.2.3',
|
||||||
'psalm',
|
'psalm',
|
||||||
'symfony',
|
'symfony-cli',
|
||||||
'symfony:1.2.3',
|
'symfony:1.2.3',
|
||||||
'vapor-cli',
|
'vapor-cli',
|
||||||
'wp-cli'
|
'wp-cli'
|
||||||
@ -504,7 +504,7 @@ describe('Tools tests', () => {
|
|||||||
'phpize',
|
'phpize',
|
||||||
'phpmd',
|
'phpmd',
|
||||||
'symfony',
|
'symfony',
|
||||||
'wp-cli'
|
'wp'
|
||||||
];
|
];
|
||||||
|
|
||||||
const script: string = await tools.addTools(
|
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);
|
script += await utils.customPackage(tool, 'tools', version, os_version);
|
||||||
break;
|
break;
|
||||||
case 'behat':
|
case 'behat':
|
||||||
|
case 'codeception':
|
||||||
case 'phpspec':
|
case 'phpspec':
|
||||||
script += await addPackage(tool, release, tool + '/', os_version);
|
script += await addPackage(tool, release, tool + '/', os_version);
|
||||||
break;
|
break;
|
||||||
@ -2113,9 +2114,6 @@ async function addTools(tools_csv, php_version, os_version) {
|
|||||||
url = await getBlackfirePlayerUrl(version, php_version);
|
url = await getBlackfirePlayerUrl(version, php_version);
|
||||||
script += await addArchive(tool, url, os_version, '"-V"');
|
script += await addArchive(tool, url, os_version, '"-V"');
|
||||||
break;
|
break;
|
||||||
case 'codeception':
|
|
||||||
script += await addPackage(tool, release, 'codeception/', os_version);
|
|
||||||
break;
|
|
||||||
case 'composer':
|
case 'composer':
|
||||||
url = await getComposerUrl(version);
|
url = await getComposerUrl(version);
|
||||||
script += await addArchive('composer', url, os_version, 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');
|
script += await addArchive('symfony', url, os_version, 'version');
|
||||||
break;
|
break;
|
||||||
case 'vapor-cli':
|
case 'vapor-cli':
|
||||||
script += await addPackage(tool, release, 'laravel/', os_version);
|
case 'vapor':
|
||||||
|
script += await addPackage('vapor-cli', release, 'laravel/', os_version);
|
||||||
break;
|
break;
|
||||||
|
case 'wp':
|
||||||
case 'wp-cli':
|
case 'wp-cli':
|
||||||
url = github + (await getWpCliUrl(version));
|
url = github + (await getWpCliUrl(version));
|
||||||
script += await addArchive(tool, url, os_version, '"--version"');
|
script += await addArchive('wp-cli', url, os_version, '"--version"');
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
script += await utils.addLog('$cross', tool, 'Tool ' + tool + ' is not supported', os_version);
|
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]}")
|
status_code=$(get -v -e "$tool_path" "${url[0]}")
|
||||||
fi
|
fi
|
||||||
if [ "$status_code" = "200" ]; then
|
if [ "$status_code" = "200" ]; then
|
||||||
if [ "$tool" = "composer" ]; then
|
add_tools_helper "$tool"
|
||||||
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
|
|
||||||
tool_version=$(get_tool_version "$tool" "$ver_param")
|
tool_version=$(get_tool_version "$tool" "$ver_param")
|
||||||
add_log "$tick" "$tool" "Added $tool $tool_version"
|
add_log "$tick" "$tool" "Added $tool $tool_version"
|
||||||
else
|
else
|
||||||
@ -259,6 +245,7 @@ add_composertool() {
|
|||||||
tool_version=$(get_tool_version 'echo' "$json") &&
|
tool_version=$(get_tool_version 'echo' "$json") &&
|
||||||
add_log "$tick" "$tool" "Added $tool $tool_version"
|
add_log "$tick" "$tool" "Added $tool $tool_version"
|
||||||
) || add_log "$cross" "$tool" "Could not setup $tool"
|
) || add_log "$cross" "$tool" "Could not setup $tool"
|
||||||
|
add_tools_helper "$tool"
|
||||||
if [ -e "$composer_bin/composer" ]; then
|
if [ -e "$composer_bin/composer" ]; then
|
||||||
sudo cp -p "$tool_path_dir/composer" "$composer_bin"
|
sudo cp -p "$tool_path_dir/composer" "$composer_bin"
|
||||||
fi
|
fi
|
||||||
|
@ -172,12 +172,14 @@ dist=$2
|
|||||||
brew_prefix="$(brew --prefix)"
|
brew_prefix="$(brew --prefix)"
|
||||||
brew_repo="$(brew --repository)"
|
brew_repo="$(brew --repository)"
|
||||||
tap_dir="$brew_repo"/Library/Taps
|
tap_dir="$brew_repo"/Library/Taps
|
||||||
|
scripts="${dist}"/../src/scripts
|
||||||
export HOMEBREW_CHANGE_ARCH_TO_ARM=1
|
export HOMEBREW_CHANGE_ARCH_TO_ARM=1
|
||||||
export HOMEBREW_NO_INSTALL_CLEANUP=1
|
export HOMEBREW_NO_INSTALL_CLEANUP=1
|
||||||
export HOMEBREW_NO_AUTO_UPDATE=1
|
export HOMEBREW_NO_AUTO_UPDATE=1
|
||||||
|
|
||||||
# shellcheck source=.
|
# shellcheck source=.
|
||||||
. "${dist}"/../src/scripts/common.sh
|
. "${scripts:?}"/tools/add_tools.sh
|
||||||
|
. "${scripts:?}"/common.sh
|
||||||
read_env
|
read_env
|
||||||
self_hosted_setup
|
self_hosted_setup
|
||||||
setup_php
|
setup_php
|
||||||
|
@ -285,9 +285,11 @@ dist=$2
|
|||||||
debconf_fix="DEBIAN_FRONTEND=noninteractive"
|
debconf_fix="DEBIAN_FRONTEND=noninteractive"
|
||||||
apt_install="sudo $debconf_fix apt-fast install -y"
|
apt_install="sudo $debconf_fix apt-fast install -y"
|
||||||
apt_remove="sudo $debconf_fix apt-fast remove -y"
|
apt_remove="sudo $debconf_fix apt-fast remove -y"
|
||||||
|
scripts="${dist}"/../src/scripts
|
||||||
|
|
||||||
# shellcheck source=.
|
# shellcheck source=.
|
||||||
. "${dist}"/../src/scripts/common.sh
|
. "${scripts:?}"/tools/add_tools.sh
|
||||||
|
. "${scripts:?}"/common.sh
|
||||||
. /etc/lsb-release
|
. /etc/lsb-release
|
||||||
read_env
|
read_env
|
||||||
self_hosted_setup
|
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,22 +245,23 @@ Function Add-Tool() {
|
|||||||
if (Test-Path $bin_dir\$tool) {
|
if (Test-Path $bin_dir\$tool) {
|
||||||
Remove-Item $bin_dir\$tool
|
Remove-Item $bin_dir\$tool
|
||||||
}
|
}
|
||||||
if($url.Count -gt 1) { $url = $url[0] }
|
if($url.Count -gt 1) {
|
||||||
if ($tool -eq "symfony") {
|
$url = $url[0]
|
||||||
Invoke-WebRequest -Uri $url -OutFile $bin_dir\$tool.exe
|
}
|
||||||
Add-ToProfile $current_profile $tool "New-Alias $tool $bin_dir\$tool.exe" >$null 2>&1
|
$tool_path = "$bin_dir\$tool"
|
||||||
} else {
|
if (($url | Split-Path -Extension) -eq ".exe") {
|
||||||
|
$tool_path = "$tool_path.exe"
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
Invoke-WebRequest -Uri $url -OutFile $bin_dir\$tool
|
Invoke-WebRequest -Uri $url -OutFile $tool_path
|
||||||
} catch {
|
} catch {
|
||||||
if($url -match '.*github.com.*releases.*latest.*') {
|
if($url -match '.*github.com.*releases.*latest.*') {
|
||||||
try {
|
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])
|
$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
|
Invoke-WebRequest -Uri $url -OutFile $tool_path
|
||||||
} catch { }
|
} catch { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (((Get-ChildItem -Path $bin_dir/* | Where-Object Name -Match "^$tool(.exe|.phar)*$").Count -gt 0)) {
|
if (((Get-ChildItem -Path $bin_dir/* | Where-Object Name -Match "^$tool(.exe|.phar)*$").Count -gt 0)) {
|
||||||
$bat_content = @()
|
$bat_content = @()
|
||||||
$bat_content += "@ECHO off"
|
$bat_content += "@ECHO off"
|
||||||
@ -269,18 +270,7 @@ Function Add-Tool() {
|
|||||||
$bat_content += "php %BIN_TARGET% %*"
|
$bat_content += "php %BIN_TARGET% %*"
|
||||||
Set-Content -Path $bin_dir\$tool.bat -Value $bat_content
|
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
|
Add-ToProfile $current_profile $tool "New-Alias $tool $bin_dir\$tool.bat" >$null 2>&1
|
||||||
if($tool -eq "phan") {
|
Add-ToolsHelper $tool
|
||||||
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
|
|
||||||
}
|
|
||||||
$tool_version = Get-ToolVersion $tool $ver_param
|
$tool_version = Get-ToolVersion $tool $ver_param
|
||||||
Add-Log $tick $tool "Added $tool $tool_version"
|
Add-Log $tick $tool "Added $tool $tool_version"
|
||||||
} else {
|
} else {
|
||||||
@ -317,6 +307,7 @@ Function Add-Composertool() {
|
|||||||
if(Test-Path $composer_bin\composer) {
|
if(Test-Path $composer_bin\composer) {
|
||||||
Copy-Item -Path "$bin_dir\composer" -Destination "$composer_bin\composer" -Force
|
Copy-Item -Path "$bin_dir\composer" -Destination "$composer_bin\composer" -Force
|
||||||
}
|
}
|
||||||
|
Add-ToolsHelper $tool
|
||||||
if($json) {
|
if($json) {
|
||||||
$tool_version = Get-ToolVersion "Write-Output" "$json"
|
$tool_version = Get-ToolVersion "Write-Output" "$json"
|
||||||
Add-Log $tick $tool "Added $tool $tool_version"
|
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
|
Add-Printf >$null 2>&1
|
||||||
Step-Log "Setup PhpManager"
|
Step-Log "Setup PhpManager"
|
||||||
Install-PSPackage PhpManager PhpManager\PhpManager "$github/mlocati/powershell-phpmanager/releases/latest/download/PhpManager.zip" >$null 2>&1
|
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);
|
script += await utils.customPackage(tool, 'tools', version, os_version);
|
||||||
break;
|
break;
|
||||||
case 'behat':
|
case 'behat':
|
||||||
|
case 'codeception':
|
||||||
case 'phpspec':
|
case 'phpspec':
|
||||||
script += await addPackage(tool, release, tool + '/', os_version);
|
script += await addPackage(tool, release, tool + '/', os_version);
|
||||||
break;
|
break;
|
||||||
@ -417,9 +418,6 @@ export async function addTools(
|
|||||||
url = await getBlackfirePlayerUrl(version, php_version);
|
url = await getBlackfirePlayerUrl(version, php_version);
|
||||||
script += await addArchive(tool, url, os_version, '"-V"');
|
script += await addArchive(tool, url, os_version, '"-V"');
|
||||||
break;
|
break;
|
||||||
case 'codeception':
|
|
||||||
script += await addPackage(tool, release, 'codeception/', os_version);
|
|
||||||
break;
|
|
||||||
case 'composer':
|
case 'composer':
|
||||||
url = await getComposerUrl(version);
|
url = await getComposerUrl(version);
|
||||||
script += await addArchive('composer', url, os_version, 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');
|
script += await addArchive('symfony', url, os_version, 'version');
|
||||||
break;
|
break;
|
||||||
case 'vapor-cli':
|
case 'vapor-cli':
|
||||||
script += await addPackage(tool, release, 'laravel/', os_version);
|
case 'vapor':
|
||||||
|
script += await addPackage(
|
||||||
|
'vapor-cli',
|
||||||
|
release,
|
||||||
|
'laravel/',
|
||||||
|
os_version
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
|
case 'wp':
|
||||||
case 'wp-cli':
|
case 'wp-cli':
|
||||||
url = github + (await getWpCliUrl(version));
|
url = github + (await getWpCliUrl(version));
|
||||||
script += await addArchive(tool, url, os_version, '"--version"');
|
script += await addArchive('wp-cli', url, os_version, '"--version"');
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
script += await utils.addLog(
|
script += await utils.addLog(
|
||||||
|
Loading…
Reference in New Issue
Block a user