Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

fix(cli): resolve install scripts downloading wrong release

[email protected]92086a619b86
diff --git a/scripts/install-cli.ps1 b/scripts/install-cli.ps1
index d1c6e9eca3..0aa3b26f61 100644
--- a/scripts/install-cli.ps1
+++ b/scripts/install-cli.ps1
@@ -1,6 +1,34 @@
# CUA CLI Installation Script for Windows
$ErrorActionPreference = "Stop"
+function Get-LatestCuaTag {
+ $page = 1
+ $perPage = 100
+ $maxPages = 10
+
+ while ($page -le $maxPages) {
+ try {
+ $response = Invoke-RestMethod -Uri "https://api.github.com/repos/trycua/cua/tags?per_page=$perPage&page=$page" -ErrorAction Stop
+
+ if (-not $response -or $response.Count -eq 0) {
+ return $null
+ }
+
+ $cuaTag = $response | Where-Object { $_.name -like "cua-*" } | Select-Object -First 1
+
+ if ($cuaTag) {
+ return $cuaTag.name
+ }
+
+ $page++
+ } catch {
+ return $null
+ }
+ }
+
+ return $null
+}
+
function Install-WithBun {
Write-Host "Installing CUA CLI using Bun..." -ForegroundColor Yellow
@@ -78,20 +106,10 @@ if (-not $is64Bit) {
}
}
-# Get the latest release version
-try {
- $release = Invoke-RestMethod -Uri "https://api.github.com/repos/trycua/cua/releases/latest" -ErrorAction Stop
- $version = $release.tag_name -replace '^cua-v', ''
- # Look for the windows binary in the release assets
- $windowsAsset = $release.assets | Where-Object { $_.name -eq 'cua-windows-x64.exe' }
-
- if (-not $windowsAsset) {
- throw "Windows binary not found in release assets"
- }
-
- $binaryUrl = $windowsAsset.browser_download_url
-} catch {
- Write-Host "Warning: Could not fetch latest release, falling back to Bun installation" -ForegroundColor Yellow
+# Get the latest cua release tag
+$tagName = Get-LatestCuaTag
+if (-not $tagName) {
+ Write-Host "Warning: Could not find latest cua release, falling back to Bun installation" -ForegroundColor Yellow
if (Install-WithBun) {
exit 0
} else {
@@ -101,6 +119,12 @@ try {
}
}
+# Extract version number (remove 'cua-v' prefix)
+$version = $tagName -replace '^cua-v', ''
+
+# Construct download URL using the specific cua release tag
+$binaryUrl = "https://github.com/trycua/cua/releases/download/$tagName/cua-windows-x64.exe"
+
# Create installation directory
$installDir = "$env:USERPROFILE\.cua\bin"
if (-not (Test-Path $installDir)) {
diff --git a/scripts/install-cli.sh b/scripts/install-cli.sh
index 5edf06ee7f..5305d2fd9d 100755
--- a/scripts/install-cli.sh
+++ b/scripts/install-cli.sh
@@ -92,6 +92,33 @@ case "$ARCH" in
*) ARCH="$ARCH" ;;
esac
+# Function to get the latest cua release tag
+get_latest_cua_tag() {
+ local page=1
+ local per_page=100
+ local max_pages=10
+ local CUA_TAG=""
+
+ while [ $page -le $max_pages ]; do
+ local response=$(curl -s "https://api.github.com/repos/trycua/cua/tags?per_page=$per_page&page=$page")
+
+ if [ -z "$response" ] || [ "$(echo "$response" | grep -c '"name":')" -eq 0 ]; then
+ return 1
+ fi
+
+ CUA_TAG=$(echo "$response" | grep '"name": "cua-' | head -n 1 | cut -d '"' -f 4)
+
+ if [ -n "$CUA_TAG" ]; then
+ echo "$CUA_TAG"
+ return 0
+ fi
+
+ page=$((page + 1))
+ done
+
+ return 1
+}
+
# Determine the binary name
BINARY_NAME="cua-${OS}-${ARCH}"
if [ "$OS" = "darwin" ] && [ "$ARCH" = "arm64" ]; then
@@ -106,29 +133,21 @@ else
exit 0
fi
-# Get the latest release version
-LATEST_RELEASE=$(curl -s https://api.github.com/repos/trycua/cua/releases/latest)
-if [ -z "$LATEST_RELEASE" ]; then
- echo "⚠️ Could not fetch latest release, falling back to Bun installation"
+# Get the latest cua release tag
+TAG_NAME=$(get_latest_cua_tag)
+if [ -z "$TAG_NAME" ]; then
+ echo "⚠️ Could not find latest cua release, falling back to Bun installation"
install_with_bun
exit 0
fi
# Extract version number (remove 'cua-v' prefix)
-TAG_NAME=$(echo "$LATEST_RELEASE" | grep 'tag_name' | cut -d '"' -f 4)
VERSION=${TAG_NAME#cua-v}
-# Find the binary URL in the release assets
-BINARY_URL=$(echo "$LATEST_RELEASE" | grep -o 'https://.*/download/[^"]*/'${BINARY_NAME}'"' | head -1)
-BINARY_URL="${BINARY_URL%\"}"
+# Construct download URL using the specific cua release tag
+BINARY_URL="https://github.com/trycua/cua/releases/download/${TAG_NAME}/${BINARY_NAME}"
printf "\033[90mBINARY_URL: %s\033[0m\n" "$BINARY_URL"
-if [ -z "$BINARY_URL" ]; then
- echo "⚠️ Could not find ${BINARY_NAME} in release assets, falling back to Bun installation"
- install_with_bun
- exit 0
-fi
-
# Create ~/.cua/bin directory if it doesn't exist
INSTALL_DIR="$HOME/.cua/bin"
mkdir -p "$INSTALL_DIR"