Improve symfony-cli support

Fingers crossed symfony-cli keeps the artifact format in their releases
This commit is contained in:
Shivam Mathur
2025-10-15 08:46:18 +05:30
parent 38e8065d61
commit 319ac00da8
2 changed files with 62 additions and 45 deletions

View File

@ -1,18 +1,32 @@
Function Add-Symfony() { Function Add-Symfony() {
$arch_name ='amd64' param(
if(-not([Environment]::Is64BitOperatingSystem) -or $version -lt '7.0') { [Parameter(Mandatory = $true, Position = 0, HelpMessage = 'Symfony version to be installed')]
$arch_name = '386' [string] $protobuf_tag
} )
$url = "https://github.com/symfony-cli/symfony-cli/releases/latest/download/symfony-cli_windows_${arch_name}.zip" $protobuf_tag = $protobuf_tag.replace('v', '')
Get-File -Url $url -OutFile $bin_dir\symfony.zip >$null 2>&1 if($protobuf_tag -ne 'latest' -and $protobuf_tag -notmatch '^\d+(\.\d+)*$') {
Expand-Archive -Path $bin_dir\symfony.zip -DestinationPath $bin_dir -Force >$null 2>&1 Add-Log $cross "symfony-cli" "Invalid symfony version: $protobuf_tag"
if(Test-Path $bin_dir\symfony.exe) {
Copy-Item -Path $bin_dir\symfony.exe -Destination $bin_dir\symfony-cli.exe > $null 2>&1
Add-ToProfile $current_profile 'symfony' "New-Alias symfony $bin_dir\symfony.exe"
Add-ToProfile $current_profile 'symfony_cli' "New-Alias symfony-cli $bin_dir\symfony-cli.exe"
$tool_version = Get-ToolVersion symfony "-V"
Add-Log $tick "symfony-cli" "Added symfony-cli $tool_version"
} else { } else {
Add-Log $cross "symfony-cli" "Could not setup symfony-cli" $arch_name = 'amd64'
if (-not ([Environment]::Is64BitOperatingSystem) -or $version -lt '7.0') {
$arch_name = '386'
}
$symfony_releases = "https://github.com/symfony-cli/symfony-cli/releases"
if ($protobuf_tag -eq 'latest') {
$url = "$symfony_releases/latest/download/symfony-cli_windows_${arch_name}.zip"
} else {
$url = "$symfony_releases/download/v$protobuf_tag/symfony-cli_windows_${arch_name}.zip"
}
Get-File -Url $url -OutFile $bin_dir\symfony.zip > $null 2>&1
Expand-Archive -Path $bin_dir\symfony.zip -DestinationPath $bin_dir -Force > $null 2>&1
if (Test-Path $bin_dir\symfony.exe) {
Copy-Item -Path $bin_dir\symfony.exe -Destination $bin_dir\symfony-cli.exe > $null 2>&1
Add-ToProfile $current_profile 'symfony' "New-Alias symfony $bin_dir\symfony.exe"
Add-ToProfile $current_profile 'symfony_cli' "New-Alias symfony-cli $bin_dir\symfony-cli.exe"
$tool_version = Get-ToolVersion symfony "-V"
Add-Log $tick "symfony-cli" "Added symfony-cli $tool_version"
} else {
Add-Log $cross "symfony-cli" "Could not setup symfony-cli"
}
} }
} }

View File

@ -1,41 +1,44 @@
add_symfony_with_brew() {
add_brew_tap symfony-cli/homebrew-tap
brew install symfony-cli/tap/symfony-cli
}
get_symfony_artifact_url() { get_symfony_artifact_url() {
arch=$(dpkg --print-architecture) local symfony_tag=$1
url=$(get -s -n "" https://raw.githubusercontent.com/symfony-cli/homebrew-tap/main/Formula/symfony-cli.rb 2<&1 | grep -m 1 "url.*linux.*${arch}" | cut -d\" -f 2) local os
if [ -z "$url" ]; then local arch
url="https://github.com/symfony-cli/symfony-cli/releases/latest/download/symfony-cli_linux_${arch}.tar.gz" os="$(uname -s | tr '[:upper:]' '[:lower:]')"
fi arch="$(uname -m)"
echo "$url" case "$arch" in
arm|armv6*|armv7*) arch="armv6" ;;
aarch64*|armv8*|arm64) arch="arm64" ;;
i[36]86) arch="386" ;;
x86_64|amd64) arch="amd64" ;;
esac
[ "$os" = "darwin" ] && arch="all"
symfony_releases="https://github.com/symfony-cli/symfony-cli/releases"
if [ "$symfony_tag" = "latest" ]; then
echo "$symfony_releases/latest/download/symfony-cli_${os}_${arch}.tar.gz"
else
echo "$symfony_releases/download/v$symfony_tag/symfony-cli_${os}_${arch}.tar.gz"
fi
} }
add_symfony_helper() { add_symfony_helper() {
if [ "$(uname -s)" = "Linux" ]; then local install_dir=/usr/local/bin
url="$(get_symfony_artifact_url)" [ "$(uname -s)" = "Darwin" ] && install_dir=${brew_prefix:?}/bin
if [ -z "$url" ]; then get -s -n "" "$(get_symfony_artifact_url "$symfony_tag")" | sudo tar -xz -C "$install_dir" 2>/dev/null
. "${0%/*}"/tools/brew.sh sudo chmod a+x "$install_dir"/symfony
configure_brew
add_symfony_with_brew
else
get -s -n "" "$url" | sudo tar -xz -C "${tool_path_dir:?}" 2>/dev/null
sudo chmod a+x /usr/local/bin/symfony
fi
elif [ "$(uname -s)" = "Darwin" ]; then
add_symfony_with_brew
fi
} }
add_symfony() { add_symfony() {
add_symfony_helper >/dev/null 2>&1 local symfony_tag="${1/v/}"
symfony_path="$(command -v symfony)" if ! [[ "$symfony_tag" =~ ^[0-9]+(\.[0-9]+)*$ || "$symfony_tag" == 'latest' ]]; then
if [[ -n "$symfony_path" ]]; then add_log "${cross:?}" "symfony-cli" "Version '$symfony_tag' is not valid for symfony-cli"
sudo ln -s "$symfony_path" "${tool_path_dir:?}"/symfony-cli
tool_version=$(get_tool_version "symfony" "-V")
add_log "${tick:?}" "symfony-cli" "Added symfony-cli $tool_version"
else else
add_log "${cross:?}" "symfony-cli" "Could not setup symfony-cli" add_symfony_helper "$symfony_tag" >/dev/null 2>&1
symfony_path="$(command -v symfony)"
if [[ -n "$symfony_path" ]]; then
sudo ln -s "$symfony_path" "${tool_path_dir:?}"/symfony-cli
tool_version=$(get_tool_version "symfony" "-V")
add_log "${tick:?}" "symfony-cli" "Added symfony-cli $tool_version"
else
add_log "${cross:?}" "symfony-cli" "Could not setup symfony-cli"
fi
fi fi
} }