mirror of
https://github.com/shivammathur/setup-php.git
synced 2024-11-22 20:01:06 +07:00
Improve tools setup
Log full semver of tools installed with composer Refactor adding paths to PATH
This commit is contained in:
parent
b7cdb2373c
commit
f3010adf3e
@ -23,7 +23,7 @@ Function Edit-ComposerConfig() {
|
|||||||
Set-Content -Path $composer_json -Value "{}"
|
Set-Content -Path $composer_json -Value "{}"
|
||||||
}
|
}
|
||||||
Get-Content -Path $dist\..\src\configs\composer.env | Add-Content -Path $env:GITHUB_ENV
|
Get-Content -Path $dist\..\src\configs\composer.env | Add-Content -Path $env:GITHUB_ENV
|
||||||
Write-Output $composer_bin | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8
|
Add-Path $composer_bin
|
||||||
if (Test-Path env:COMPOSER_TOKEN) {
|
if (Test-Path env:COMPOSER_TOKEN) {
|
||||||
composer -q config -g github-oauth.github.com $env:COMPOSER_TOKEN
|
composer -q config -g github-oauth.github.com $env:COMPOSER_TOKEN
|
||||||
}
|
}
|
||||||
@ -60,7 +60,7 @@ Function Add-ToolsHelper() {
|
|||||||
$tool
|
$tool
|
||||||
)
|
)
|
||||||
if($tool -eq "codeception") {
|
if($tool -eq "codeception") {
|
||||||
Copy-Item $codeception_bin\codecept.bat -Destination $codeception_bin\codeception.bat
|
Copy-Item $env:codeception_bin\codecept.bat -Destination $env:codeception_bin\codeception.bat
|
||||||
} elseif($tool -eq "composer") {
|
} elseif($tool -eq "composer") {
|
||||||
Edit-ComposerConfig $bin_dir\$tool
|
Edit-ComposerConfig $bin_dir\$tool
|
||||||
} elseif($tool -eq "cs2pr") {
|
} elseif($tool -eq "cs2pr") {
|
||||||
@ -77,7 +77,7 @@ Function Add-ToolsHelper() {
|
|||||||
Add-ToProfile $current_profile "symfony" "New-Alias symfony $bin_dir\symfony-cli.exe"
|
Add-ToProfile $current_profile "symfony" "New-Alias symfony $bin_dir\symfony-cli.exe"
|
||||||
Add-ToProfile $current_profile "symfony_cli" "New-Alias symfony-cli $bin_dir\symfony-cli.exe"
|
Add-ToProfile $current_profile "symfony_cli" "New-Alias symfony-cli $bin_dir\symfony-cli.exe"
|
||||||
} elseif($tool -match "vapor-cli") {
|
} elseif($tool -match "vapor-cli") {
|
||||||
Copy-Item $vapor_cli_bin\vapor.bat -Destination $vapor_cli_bin\vapor-cli.bat
|
Copy-Item $env:vapor_cli_bin\vapor.bat -Destination $env:vapor_cli_bin\vapor-cli.bat
|
||||||
} elseif($tool -eq "wp-cli") {
|
} elseif($tool -eq "wp-cli") {
|
||||||
Copy-Item $bin_dir\wp-cli.bat -Destination $bin_dir\wp.bat
|
Copy-Item $bin_dir\wp-cli.bat -Destination $bin_dir\wp.bat
|
||||||
}
|
}
|
||||||
@ -137,7 +137,7 @@ Function Add-Tool() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Function Add-ScopedComposertool() {
|
Function Add-ComposertoolHelper() {
|
||||||
Param (
|
Param (
|
||||||
[Parameter(Position = 0, Mandatory = $true)]
|
[Parameter(Position = 0, Mandatory = $true)]
|
||||||
[string]
|
[string]
|
||||||
@ -147,18 +147,30 @@ Function Add-ScopedComposertool() {
|
|||||||
$release,
|
$release,
|
||||||
[Parameter(Position = 2, Mandatory = $true)]
|
[Parameter(Position = 2, Mandatory = $true)]
|
||||||
[string]
|
[string]
|
||||||
$prefix
|
$prefix,
|
||||||
|
[Parameter(Position = 3, Mandatory = $true)]
|
||||||
|
[string]
|
||||||
|
$scope
|
||||||
)
|
)
|
||||||
$release_stream = [System.IO.MemoryStream]::New([System.Text.Encoding]::ASCII.GetBytes($release))
|
if($scope -eq 'global') {
|
||||||
$scoped_tool_dir_suffix = (Get-FileHash -InputStream $release_stream -Algorithm sha256).Hash
|
if(Test-Path $composer_lock) {
|
||||||
$scoped_tool_dir = "$composer_bin\_tools\$tool-$scoped_tool_dir_suffix"
|
Remove-Item -Path $composer_lock -Force
|
||||||
if(-not(Test-Path $scoped_tool_dir)) {
|
}
|
||||||
New-Item -ItemType Directory -Force -Path $scoped_tool_dir > $null 2>&1
|
composer global require $prefix$release >$null 2>&1
|
||||||
(composer global require $prefix$release -d $scoped_tool_dir.replace('\', '/') 2>&1 | Tee-Object -FilePath $env:APPDATA\Composer\composer.log) >$null 2>&1
|
return composer global show $prefix$tool 2>&1 | findstr '^versions'
|
||||||
Add-Content $scoped_tool_dir\vendor\bin -Path $env:GITHUB_PATH -Encoding utf8
|
} else {
|
||||||
New-Variable -Name ($tool.replace('-', '_') + '_bin') -Value $scoped_tool_dir\vendor\bin
|
$release_stream = [System.IO.MemoryStream]::New([System.Text.Encoding]::ASCII.GetBytes($release))
|
||||||
|
$scoped_dir_suffix = (Get-FileHash -InputStream $release_stream -Algorithm sha256).Hash
|
||||||
|
$scoped_dir = "$composer_bin\_tools\$tool-$scoped_dir_suffix"
|
||||||
|
$unix_scoped_dir = $scoped_dir.replace('\', '/')
|
||||||
|
if(-not(Test-Path $scoped_dir)) {
|
||||||
|
New-Item -ItemType Directory -Force -Path $scoped_dir > $null 2>&1
|
||||||
|
composer require $prefix$release -d $unix_scoped_dir >$null 2>&1
|
||||||
|
}
|
||||||
|
[System.Environment]::SetEnvironmentVariable(($tool.replace('-', '_') + '_bin'), "$scoped_dir\vendor\bin")
|
||||||
|
Add-Path $scoped_dir\vendor\bin
|
||||||
|
return composer show $prefix$tool -d $unix_scoped_dir 2>&1 | findstr '^versions'
|
||||||
}
|
}
|
||||||
return ((Test-Path $scoped_tool_dir\composer.json) -and (findstr $prefix$tool $scoped_tool_dir\composer.json))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to setup a tool using composer.
|
# Function to setup a tool using composer.
|
||||||
@ -190,21 +202,12 @@ Function Add-Composertool() {
|
|||||||
Add-Log $cross $tool "Skipped"
|
Add-Log $cross $tool "Skipped"
|
||||||
Return
|
Return
|
||||||
}
|
}
|
||||||
if($scope -eq 'global') {
|
$log = Add-ComposertoolHelper -tool $tool -release $release -prefix $prefix -scope $scope
|
||||||
if(Test-Path $composer_lock) {
|
|
||||||
Remove-Item -Path $composer_lock -Force
|
|
||||||
}
|
|
||||||
(composer global require $prefix$release 2>&1 | Tee-Object -FilePath $env:APPDATA\Composer\composer.log) >$null 2>&1
|
|
||||||
$json = findstr $prefix$tool $env:APPDATA\Composer\composer.json
|
|
||||||
} else {
|
|
||||||
$json = Add-ScopedComposertool -tool $tool -release $release -prefix $prefix
|
|
||||||
}
|
|
||||||
$log = findstr $prefix$tool $env:APPDATA\Composer\composer.log
|
|
||||||
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
|
Add-ToolsHelper $tool
|
||||||
if($json) {
|
if($log) {
|
||||||
$tool_version = Get-ToolVersion "Write-Output" "$log"
|
$tool_version = Get-ToolVersion "Write-Output" "$log"
|
||||||
Add-Log $tick $tool "Added $tool $tool_version"
|
Add-Log $tick $tool "Added $tool $tool_version"
|
||||||
} else {
|
} else {
|
||||||
|
@ -43,7 +43,7 @@ configure_composer() {
|
|||||||
chmod 644 "$composer_json"
|
chmod 644 "$composer_json"
|
||||||
fi
|
fi
|
||||||
cat "${dist:?}"/../src/configs/composer.env >> "$GITHUB_ENV"
|
cat "${dist:?}"/../src/configs/composer.env >> "$GITHUB_ENV"
|
||||||
echo "$composer_bin" >>"$GITHUB_PATH"
|
add_path "$composer_bin"
|
||||||
if [ -n "$COMPOSER_TOKEN" ]; then
|
if [ -n "$COMPOSER_TOKEN" ]; then
|
||||||
composer -q config -g github-oauth.github.com "$COMPOSER_TOKEN"
|
composer -q config -g github-oauth.github.com "$COMPOSER_TOKEN"
|
||||||
fi
|
fi
|
||||||
@ -53,8 +53,7 @@ configure_composer() {
|
|||||||
add_tools_helper() {
|
add_tools_helper() {
|
||||||
tool=$1
|
tool=$1
|
||||||
if [ "$tool" = "codeception" ]; then
|
if [ "$tool" = "codeception" ]; then
|
||||||
codeception_bin=$(grep codeception_bin "${GITHUB_ENV:?}" | cut -d '=' -f 2)
|
sudo ln -s "$scoped_dir"/vendor/bin/codecept "$scoped_dir"/vendor/bin/codeception
|
||||||
sudo ln -s "$codeception_bin"/codecept "$codeception_bin"/codeception
|
|
||||||
elif [ "$tool" = "composer" ]; then
|
elif [ "$tool" = "composer" ]; then
|
||||||
configure_composer "$tool_path"
|
configure_composer "$tool_path"
|
||||||
elif [ "$tool" = "cs2pr" ]; then
|
elif [ "$tool" = "cs2pr" ]; then
|
||||||
@ -75,6 +74,8 @@ add_tools_helper() {
|
|||||||
if [ -e "$tool_path_dir"/phpunit ]; then
|
if [ -e "$tool_path_dir"/phpunit ]; then
|
||||||
sudo cp "$tool_path_dir"/phpunit "$composer_bin"
|
sudo cp "$tool_path_dir"/phpunit "$composer_bin"
|
||||||
fi
|
fi
|
||||||
|
elif [[ "$tool" =~ vapor-cli ]]; then
|
||||||
|
sudo ln -s "$scoped_dir"/vendor/bin/vapor "$scoped_dir"/vendor/bin/vapor-cli
|
||||||
elif [[ "$tool" =~ (symfony|vapor|wp)-cli ]]; then
|
elif [[ "$tool" =~ (symfony|vapor|wp)-cli ]]; then
|
||||||
sudo ln -s "$tool_path" "$tool_path_dir"/"${tool%-*}"
|
sudo ln -s "$tool_path" "$tool_path_dir"/"${tool%-*}"
|
||||||
fi
|
fi
|
||||||
@ -86,10 +87,7 @@ add_tool() {
|
|||||||
tool=$2
|
tool=$2
|
||||||
ver_param=$3
|
ver_param=$3
|
||||||
tool_path="$tool_path_dir/$tool"
|
tool_path="$tool_path_dir/$tool"
|
||||||
if ! [[ "$PATH" =~ $tool_path_dir ]]; then
|
add_path "$tool_path_dir"
|
||||||
export PATH=$PATH:"$tool_path_dir"
|
|
||||||
echo "export PATH=\$PATH:$tool_path_dir" | sudo tee -a "$GITHUB_ENV" >/dev/null
|
|
||||||
fi
|
|
||||||
if [ -e "$tool_path" ]; then
|
if [ -e "$tool_path" ]; then
|
||||||
sudo cp -aL "$tool_path" /tmp/"$tool"
|
sudo cp -aL "$tool_path" /tmp/"$tool"
|
||||||
fi
|
fi
|
||||||
@ -114,17 +112,23 @@ add_tool() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Function to setup a tool using composer in a different scope.
|
# Function to setup a tool using composer in a different scope.
|
||||||
add_scoped_composertool() {
|
add_composertool_helper() {
|
||||||
tool=$1
|
tool=$1
|
||||||
release=$2
|
release=$2
|
||||||
prefix=$3
|
prefix=$3
|
||||||
|
scope=$4
|
||||||
|
if [ "$scope" = "global" ]; then
|
||||||
|
sudo rm -f "$composer_lock" >/dev/null 2>&1 || true
|
||||||
|
composer global require "$prefix$release" >/dev/null 2>&1
|
||||||
|
composer global show "$prefix$tool" 2>&1 | grep -E ^versions | sudo tee /tmp/composer.log >/dev/null 2>&1
|
||||||
|
else
|
||||||
scoped_dir="$composer_bin/_tools/$tool-$(echo -n "$release" | shasum -a 256 | cut -d ' ' -f 1)"
|
scoped_dir="$composer_bin/_tools/$tool-$(echo -n "$release" | shasum -a 256 | cut -d ' ' -f 1)"
|
||||||
if ! [ -e "$scoped_dir" ]; then
|
if ! [ -d "$scoped_dir" ]; then
|
||||||
mkdir -p "$scoped_dir"
|
mkdir -p "$scoped_dir"
|
||||||
composer require "$prefix$release" -d "$scoped_dir" 2>&1 | tee /tmp/composer.log >/dev/null 2>&1
|
composer require "$prefix$release" -d "$scoped_dir" >/dev/null 2>&1
|
||||||
export PATH=$PATH:"$scoped_dir"/vendor/bin
|
composer show "$prefix$tool" -d "$scoped_dir" 2>&1 | grep -E ^versions | sudo tee /tmp/composer.log >/dev/null 2>&1
|
||||||
echo "${tool}"_bin="$scoped_dir"/vendor/bin | sudo tee -a "$GITHUB_ENV" >/dev/null
|
fi
|
||||||
echo "$scoped_dir"/vendor/bin >>"$GITHUB_PATH"
|
add_path "$scoped_dir"/vendor/bin
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,16 +146,9 @@ add_composertool() {
|
|||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
(
|
add_composertool_helper "$tool" "$release" "$prefix" "$scope"
|
||||||
if [ "$scope" = "global" ]; then
|
tool_version=$(get_tool_version cat /tmp/composer.log)
|
||||||
sudo rm -f "$composer_lock" >/dev/null 2>&1 || true
|
([ -s /tmp/composer.log ] && add_log "$tick" "$tool" "Added $tool $tool_version"
|
||||||
composer global require "$prefix$release" 2>&1 | tee /tmp/composer.log >/dev/null 2>&1
|
|
||||||
else
|
|
||||||
add_scoped_composertool "$tool" "$release" "$prefix"
|
|
||||||
fi
|
|
||||||
log=$(grep "$prefix$tool" /tmp/composer.log) &&
|
|
||||||
tool_version=$(get_tool_version 'echo' "$log") &&
|
|
||||||
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"
|
add_tools_helper "$tool"
|
||||||
if [ -e "$composer_bin/composer" ]; then
|
if [ -e "$composer_bin/composer" ]; then
|
||||||
|
@ -11,7 +11,7 @@ Function Add-Grpc_php_plugin() {
|
|||||||
$msys_location = Add-Msys2
|
$msys_location = Add-Msys2
|
||||||
$logs = . $msys_location\usr\bin\bash -l -c "pacman -S --noconfirm mingw-w64-x86_64-grpc" >$null 2>&1
|
$logs = . $msys_location\usr\bin\bash -l -c "pacman -S --noconfirm mingw-w64-x86_64-grpc" >$null 2>&1
|
||||||
$grpc_version = Get-ToolVersion 'Write-Output' "$logs"
|
$grpc_version = Get-ToolVersion 'Write-Output' "$logs"
|
||||||
Write-Output "$msys_location\mingw64\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8
|
Add-Path $msys_location\mingw64\bin
|
||||||
Write-Output "::set-output name=grpc_php_plugin_path::$msys_location\mingw64\bin\grpc_php_plugin.exe"
|
Write-Output "::set-output name=grpc_php_plugin_path::$msys_location\mingw64\bin\grpc_php_plugin.exe"
|
||||||
Add-ToProfile $current_profile 'grpc_php_plugin' "New-Alias grpc_php_plugin $msys_location\mingw64\bin\grpc_php_plugin.exe"
|
Add-ToProfile $current_profile 'grpc_php_plugin' "New-Alias grpc_php_plugin $msys_location\mingw64\bin\grpc_php_plugin.exe"
|
||||||
Add-Log $tick "grpc_php_plugin" "Added grpc_php_plugin $grpc_version"
|
Add-Log $tick "grpc_php_plugin" "Added grpc_php_plugin $grpc_version"
|
||||||
|
@ -60,6 +60,34 @@ get() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Function to get shell profile.
|
||||||
|
get_shell_profile() {
|
||||||
|
case "$SHELL" in
|
||||||
|
*bash*)
|
||||||
|
echo "${HOME}/.bashrc"
|
||||||
|
;;
|
||||||
|
*zsh*)
|
||||||
|
echo "${HOME}/.zshrc"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "${HOME}/.profile"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to add a path to the PATH variable.
|
||||||
|
add_path() {
|
||||||
|
path_to_add=$1
|
||||||
|
[ ! -d "$path_to_add" ] && [[ ":$PATH:" == *":$path_to_add:"* ]] && return
|
||||||
|
if [[ -n "$GITHUB_PATH" ]]; then
|
||||||
|
echo "$path_to_add" | tee -a "$GITHUB_PATH" >/dev/null 2>&1
|
||||||
|
else
|
||||||
|
profile=$(get_shell_profile)
|
||||||
|
([ -e "$profile" ] && grep -q ":$path_to_add\"" "$profile" 2>/dev/null) || echo "export PATH=\"\${PATH:+\${PATH}:}\"$path_to_add" | sudo tee -a "$profile" >/dev/null 2>&1
|
||||||
|
fi
|
||||||
|
export PATH="${PATH:+${PATH}:}$path_to_add"
|
||||||
|
}
|
||||||
|
|
||||||
# Function to download and run scripts from GitHub releases with jsdeliver fallback.
|
# Function to download and run scripts from GitHub releases with jsdeliver fallback.
|
||||||
run_script() {
|
run_script() {
|
||||||
repo=$1
|
repo=$1
|
||||||
|
@ -64,11 +64,18 @@ Function Add-Path {
|
|||||||
param(
|
param(
|
||||||
[string]$PathItem
|
[string]$PathItem
|
||||||
)
|
)
|
||||||
|
if(-not(Test-Path $PathItem) -or "$env:PATH;".contains("$PathItem;")) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if ($env:GITHUB_PATH) {
|
||||||
|
Add-Content $PathItem -Path $env:GITHUB_PATH -Encoding utf8
|
||||||
|
} else {
|
||||||
$newPath = (Get-ItemProperty -Path 'hkcu:\Environment' -Name PATH).Path.replace("$PathItem;", '')
|
$newPath = (Get-ItemProperty -Path 'hkcu:\Environment' -Name PATH).Path.replace("$PathItem;", '')
|
||||||
$newPath = $PathItem + ';' + $newPath
|
$newPath = $PathItem + ';' + $newPath
|
||||||
Set-ItemProperty -Path 'hkcu:\Environment' -Name Path -Value $newPath
|
Set-ItemProperty -Path 'hkcu:\Environment' -Name Path -Value $newPath
|
||||||
Get-PathFromRegistry
|
Get-PathFromRegistry
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# Function to make sure printf is in PATH.
|
# Function to make sure printf is in PATH.
|
||||||
Function Add-Printf {
|
Function Add-Printf {
|
||||||
|
Loading…
Reference in New Issue
Block a user