Add Upsun CLI tool (#1157)

* Add Upsun CLI tool

* Revert unrelated README TOC changes
This commit is contained in:
Mickael Gaillard
2026-11-20 21:06:37 +05:30
committed by GitHub
parent 2001cd3148
commit e8d43d139f
5 changed files with 96 additions and 4 deletions
+8
View File
@@ -288,6 +288,14 @@
"version_prefix": "v",
"version_parameter": "-V"
},
"upsun-cli": {
"alias": "upsun",
"type": "custom-package",
"repository": "upsun/cli",
"domain": "https://github.com",
"version_prefix": "v",
"version_parameter": "--version"
},
"blackfire-player": {
"type": "custom-function",
"domain": "https://get.blackfire.io",
+30
View File
@@ -0,0 +1,30 @@
Function Add-Upsun() {
param(
[Parameter(Mandatory = $true, Position = 0, HelpMessage = 'Upsun CLI version to be installed')]
[string] $upsun_tag
)
$upsun_tag = $upsun_tag.replace('v', '')
if($upsun_tag -ne 'latest' -and $upsun_tag -notmatch '^\d+(\.\d+)*$') {
Add-Log $cross "upsun-cli" "Invalid upsun-cli version: $upsun_tag"
} elseif(-not([Environment]::Is64BitOperatingSystem)) {
Add-Log $cross "upsun-cli" "upsun-cli is only available for 64-bit Windows"
} else {
$upsun_releases = "https://github.com/upsun/cli/releases"
if ($upsun_tag -eq 'latest') {
$upsun_tag = (Get-File -Url $upsun_releases/latest).BaseResponse.RequestMessage.RequestUri.Segments[-1].replace('v', '')
}
$url = "$upsun_releases/download/v$upsun_tag/upsun_${upsun_tag}_windows_amd64.zip"
Get-File -Url $url -OutFile $bin_dir\upsun.zip > $null 2>&1
Expand-Archive -Path $bin_dir\upsun.zip -DestinationPath $bin_dir\upsun -Force > $null 2>&1
if (Test-Path $bin_dir\upsun\upsun.exe) {
Move-Item -Path $bin_dir\upsun\upsun.exe -Destination $bin_dir\upsun.exe -Force
Copy-Item -Path $bin_dir\upsun.exe -Destination $bin_dir\upsun-cli.exe > $null 2>&1
Add-ToProfile $current_profile 'upsun' "New-Alias upsun $bin_dir\upsun.exe"
Add-ToProfile $current_profile 'upsun_cli' "New-Alias upsun-cli $bin_dir\upsun-cli.exe"
$tool_version = Get-ToolVersion upsun "--version"
Add-Log $tick "upsun-cli" "Added upsun-cli $tool_version"
} else {
Add-Log $cross "upsun-cli" "Could not setup upsun-cli"
}
}
}
+49
View File
@@ -0,0 +1,49 @@
get_upsun_tag() {
local upsun_tag=$1
if [ "$upsun_tag" = "latest" ]; then
get -s -n "" https://github.com/upsun/cli/releases/latest 2<&1 | grep -m 1 -Eo "tag/v[0-9]+(\.[0-9]+)*" | head -n 1 | cut -d '/' -f 2
else
echo "v$upsun_tag"
fi
}
add_upsun_helper() {
local upsun_tag=$1
local install_dir=/usr/local/bin
local os
local arch
os="$(uname -s | tr '[:upper:]' '[:lower:]')"
arch="$(uname -m)"
case "$arch" in
aarch64*|armv8*|arm64) arch="arm64" ;;
x86_64|amd64) arch="amd64" ;;
esac
if [ "$os" = "darwin" ]; then
arch="all"
install_dir=${brew_prefix:?}/bin
fi
get -q -n /tmp/upsun.tar.gz "https://github.com/upsun/cli/releases/download/$upsun_tag/upsun_${upsun_tag#v}_${os}_${arch}.tar.gz"
mkdir -p /tmp/upsun
tar -xzf /tmp/upsun.tar.gz -C /tmp/upsun
sudo mv /tmp/upsun/upsun "$install_dir"/upsun
sudo chmod a+x "$install_dir"/upsun
rm -rf /tmp/upsun /tmp/upsun.tar.gz
}
add_upsun() {
local upsun_tag="${1/v/}"
if ! [[ "$upsun_tag" =~ ^[0-9]+(\.[0-9]+)*$ || "$upsun_tag" == 'latest' ]]; then
add_log "${cross:?}" "upsun-cli" "Version '$upsun_tag' is not valid for upsun-cli"
else
upsun_tag="$(get_upsun_tag "$upsun_tag")"
add_upsun_helper "$upsun_tag" >/dev/null 2>&1
upsun_path="$(command -v upsun)"
if [[ -n "$upsun_path" ]]; then
sudo ln -s "$upsun_path" "${tool_path_dir:?}"/upsun-cli
tool_version=$(get_tool_version "upsun" "--version")
add_log "${tick:?}" "upsun-cli" "Added upsun-cli $tool_version"
else
add_log "${cross:?}" "upsun-cli" "Could not setup upsun-cli"
fi
fi
}