Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .github/workflows/cube-cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,18 @@ jobs:
run: cargo test --locked --target ${{ matrix.target }}
- name: Build (release)
run: cargo build --release --locked --target ${{ matrix.target }}

installers:
name: Installers ${{ matrix.os }}
runs-on: ${{ matrix.os }}
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
# Both images ship pwsh, so install-cli.ps1 runs here too. The fake
# binaries the test serves are shell scripts, which Windows can't run.
os: [ubuntu-24.04, macos-14]
steps:
- uses: actions/checkout@v7
- name: Test installers
run: rust/cube-cli/tests/installers.sh
11 changes: 7 additions & 4 deletions docs-mintlify/reference/cli.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,16 @@ Windows (PowerShell):
irm https://raw.githubusercontent.com/cube-js/cube/master/install-cli.ps1 | iex
```

The installer downloads the release binary for your platform and adds it to
your `PATH`. Set `CUBE_VERSION` to pin a release tag, or `CUBE_INSTALL_DIR`
to change the install location.
The installer downloads the binary of the newest release that ships one for
your platform and adds it to your `PATH`. Set `CUBE_VERSION` to pin a release
tag, or `CUBE_INSTALL_DIR` to change the install location. In CI, set
`GITHUB_TOKEN` to avoid GitHub's rate limit on release lookups.

The CLI checks for new releases in the background and prints a notice when
one is available. Update in place at any time:

```bash
cube update # install the latest release
cube update # install the newest release for your platform
cube update --check # only report what's available
```

Expand Down Expand Up @@ -961,6 +962,8 @@ cube ossie cancel DEPLOYMENT_ID CONVERSION_ID
| `CUBEJS_TELEMETRY=false` | Legacy alias for `CUBE_NO_TELEMETRY`, kept for compatibility with the previous `cubejs` CLI |
| `CUBE_VERSION` | Installer only: release tag to install |
| `CUBE_INSTALL_DIR` | Installer only: install directory |
| `CUBE_RELEASES_URL` | Installer only: GitHub releases API endpoint to pick the release from (for mirrors and tests) |
| `GITHUB_TOKEN` | Installer only: sent to `api.github.com` (never to a `CUBE_RELEASES_URL` mirror) to avoid its unauthenticated rate limit |

## Telemetry

Expand Down
59 changes: 52 additions & 7 deletions install-cli.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,52 @@
#
# Environment overrides:
# CUBE_INSTALL_DIR install directory (default: %LOCALAPPDATA%\cube\bin)
# CUBE_VERSION release tag to install, e.g. v1.7.5 (default: latest)
# CUBE_VERSION release tag to install, e.g. v1.7.5 (default: the newest
# release that ships a Windows binary)
# CUBE_RELEASES_URL GitHub releases API endpoint to pick the version from
# (default: the cube-js/cube releases, used by tests)
# GITHUB_TOKEN sent to api.github.com only, to avoid its
# unauthenticated rate limit on shared CI runners
$ErrorActionPreference = "Stop"

$Repo = "cube-js/cube"
$Target = "x86_64-pc-windows-msvc"

$Version = if ($env:CUBE_VERSION) { $env:CUBE_VERSION } else { "latest" }
$Url = if ($Version -eq "latest") {
"https://github.com/$Repo/releases/latest/download/cube-$Target.tar.gz"
$Asset = "cube-$Target.tar.gz"
$ReleasesUrl = if ($env:CUBE_RELEASES_URL) { $env:CUBE_RELEASES_URL } else { "https://api.github.com/repos/$Repo/releases?per_page=30" }
# How many releases to try before giving up when downloads keep failing.
$MaxAttempts = 3

# The download URL of our asset for every stable release that lists it,
# highest version first. Releases from older maintenance lines are interleaved
# by publish date, so order by version.
function Get-ReleaseUrls {
$Headers = @{}
# Only GitHub gets the token, never a CUBE_RELEASES_URL mirror.
if ($env:GITHUB_TOKEN -and $ReleasesUrl -like 'https://api.github.com/*') { $Headers.Authorization = "Bearer $env:GITHUB_TOKEN" }
# Assign before piping: Windows PowerShell 5.1 would otherwise pass the
# whole JSON array down the pipeline as a single object.
$Releases = Invoke-RestMethod -Uri $ReleasesUrl -Headers $Headers -UseBasicParsing
$Releases | Where-Object { -not $_.prerelease -and -not $_.draft } | ForEach-Object {
$Version = $null
$Match = $_.assets | Where-Object { $_.name -eq $Asset } | Select-Object -First 1
if ($Match -and [version]::TryParse(($_.tag_name -replace '^v', ''), [ref]$Version)) {
[pscustomobject]@{ Version = $Version; Url = $Match.browser_download_url }
}
} | Sort-Object Version -Descending | Select-Object -First $MaxAttempts -ExpandProperty Url
}

$Urls = if ($env:CUBE_VERSION -and $env:CUBE_VERSION -ne "latest") {
@("https://github.com/$Repo/releases/download/$($env:CUBE_VERSION)/$Asset")
} else {
"https://github.com/$Repo/releases/download/$Version/cube-$Target.tar.gz"
# Not releases/latest: its binaries upload after publishing and can be
# missing (v1.7.14).
$Found = @(try { Get-ReleaseUrls } catch { })
if ($Found.Count -eq 0) {
Write-Warning "could not list releases, falling back to the latest one"
$Found = @("https://github.com/$Repo/releases/latest/download/$Asset")
}
$Found
}

$Dir = if ($env:CUBE_INSTALL_DIR) { $env:CUBE_INSTALL_DIR } else { Join-Path $env:LOCALAPPDATA "cube\bin" }
Expand All @@ -23,9 +58,19 @@ New-Item -ItemType Directory -Force -Path $Dir | Out-Null
$Tmp = Join-Path ([System.IO.Path]::GetTempPath()) ([System.Guid]::NewGuid().ToString())
New-Item -ItemType Directory -Force -Path $Tmp | Out-Null
try {
Write-Host "Downloading cube ($Target) from $Url…"
$Archive = Join-Path $Tmp "cube.tar.gz"
Invoke-WebRequest -Uri $Url -OutFile $Archive -UseBasicParsing
$Downloaded = $false
foreach ($Url in $Urls) {
Write-Host "Downloading cube ($Target) from $Url…"
try {
Invoke-WebRequest -Uri $Url -OutFile $Archive -UseBasicParsing
$Downloaded = $true
break
} catch {
Write-Warning "download failed, trying an older release"
}
}
if (-not $Downloaded) { throw "could not download $Asset" }

# tar ships with Windows 10 1803+.
tar -xzf $Archive -C $Tmp
Expand Down
94 changes: 82 additions & 12 deletions install-cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,37 @@
# Environment overrides:
# CUBE_INSTALL_DIR install directory (default: /usr/local/bin if
# writable, else ~/.local/bin)
# CUBE_VERSION release tag to install, e.g. v1.7.5 (default: latest)
# CUBE_VERSION release tag to install, e.g. v1.7.5 (default: the
# newest release that ships a binary for this platform)
# CUBE_RELEASES_URL GitHub releases API endpoint to pick the version from
Comment thread
paveltiunov marked this conversation as resolved.
Resolved
# (default: the cube-js/cube releases, used by tests)
# GITHUB_TOKEN sent to api.github.com only, to avoid its
# unauthenticated rate limit on shared CI runners
set -eu

REPO="cube-js/cube"
RELEASES_URL="${CUBE_RELEASES_URL:-https://api.github.com/repos/${REPO}/releases?per_page=30}"
# How many releases to try before giving up when downloads keep failing.
MAX_ATTEMPTS=3

main() {
os=$(uname -s)
arch=$(uname -m)
case "$os" in
Linux) os_part="unknown-linux-musl" ;;
Darwin) os_part="apple-darwin" ;;
*) err "unsupported OS: $os (use install.ps1 on Windows)" ;;
*) err "unsupported OS: $os (use install-cli.ps1 on Windows)" ;;
esac
case "$arch" in
x86_64|amd64) arch_part="x86_64" ;;
arm64|aarch64) arch_part="aarch64" ;;
*) err "unsupported architecture: $arch" ;;
esac
target="${arch_part}-${os_part}"
asset="cube-${target}.tar.gz"

if [ "${CUBE_VERSION:-latest}" = "latest" ]; then
url="https://github.com/${REPO}/releases/latest/download/cube-${target}.tar.gz"
else
url="https://github.com/${REPO}/releases/download/${CUBE_VERSION}/cube-${target}.tar.gz"
if ! command -v curl >/dev/null 2>&1 && ! command -v wget >/dev/null 2>&1; then
err "neither curl nor wget is available"
fi

dir="${CUBE_INSTALL_DIR:-}"
Expand All @@ -45,15 +52,31 @@ main() {
tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' EXIT

echo "Downloading cube (${target}) from ${url}…"
if command -v curl >/dev/null 2>&1; then
curl -fsSL "$url" -o "$tmp/cube.tar.gz"
elif command -v wget >/dev/null 2>&1; then
wget -qO "$tmp/cube.tar.gz" "$url"
if [ -n "${CUBE_VERSION:-}" ] && [ "$CUBE_VERSION" != "latest" ]; then
echo "https://github.com/${REPO}/releases/download/${CUBE_VERSION}/${asset}" > "$tmp/urls"
else
err "neither curl nor wget is available"
# Not releases/latest: its binaries upload after publishing and can be
# missing (v1.7.14).
if fetch_api "$RELEASES_URL" "$tmp/releases.json" 2>/dev/null; then
release_urls "$tmp/releases.json" "$asset" | head -n "$MAX_ATTEMPTS" > "$tmp/urls"
fi
if [ ! -s "$tmp/urls" ]; then
echo "warning: could not list releases, falling back to the latest one" >&2
echo "https://github.com/${REPO}/releases/latest/download/${asset}" > "$tmp/urls"
fi
fi

downloaded=""
while read -r url; do
echo "Downloading cube (${target}) from ${url}…"
if download "$url" "$tmp/cube.tar.gz"; then
downloaded=1
break
fi
echo "warning: download failed, trying an older release" >&2
done < "$tmp/urls"
[ -n "$downloaded" ] || err "could not download ${asset}"

tar -xzf "$tmp/cube.tar.gz" -C "$tmp"
install -m 755 "$tmp/cube" "$dir/cube"

Expand All @@ -65,6 +88,53 @@ main() {
esac
}

# Prints the download URL of $2 for every stable release in the GitHub
# releases API response $1 that lists it, highest version first. Releases from
# older maintenance lines are interleaved by publish date, so order by version.
release_urls() {
# tag_name, draft and prerelease precede the assets array in each release.
# Drafts are only listed to a GITHUB_TOKEN with push access.
grep -oE '"(tag_name|draft|prerelease|browser_download_url)": *("[^"]*"|true|false)' "$1" |
awk -v asset="$2" '
{ v = $0; sub(/^"[a-z_]*": */, "", v); gsub(/"/, "", v) }
/^"tag_name"/ { tag = v; draft = 1; stable = 0; next }
/^"draft"/ { draft = (v == "true"); next }
/^"prerelease"/ { stable = (v == "false") && !draft; next }
stable && substr(v, length(v) - length(asset)) == "/" asset {
ver = tag; sub(/^v/, "", ver); print ver, v
}
' |
sort -t. -k1,1nr -k2,2nr -k3,3nr |
cut -d' ' -f2
}

fetch_api() {
# Only GitHub gets the token, never a CUBE_RELEASES_URL mirror.
token=""
case "$1" in
https://api.github.com/*) token="${GITHUB_TOKEN:-}" ;;
esac
if command -v curl >/dev/null 2>&1; then
if [ -n "$token" ]; then
curl -fsSL --compressed -H "Authorization: Bearer ${token}" "$1" -o "$2"
else
curl -fsSL --compressed "$1" -o "$2"
fi
Comment thread
paveltiunov marked this conversation as resolved.
Resolved
elif [ -n "$token" ]; then
wget -qO "$2" --header "Authorization: Bearer ${token}" "$1"
else
wget -qO "$2" "$1"
fi
}

download() {
if command -v curl >/dev/null 2>&1; then
curl -fsSL "$1" -o "$2"
else
wget -qO "$2" "$1"
fi
}

err() {
echo "error: $1" >&2
exit 1
Expand Down
53 changes: 53 additions & 0 deletions rust/cube-cli/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rust/cube-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ owo-colors = "4"
# Native root store (honors SSL_CERT_FILE and OS-installed CAs, e.g. behind
# corporate TLS-inspecting proxies) with rustls — still no OpenSSL, still
# fully static on musl.
reqwest = { version = "0.12", default-features = false, features = ["rustls-tls-native-roots", "json", "multipart"] }
reqwest = { version = "0.12", default-features = false, features = ["rustls-tls-native-roots", "json", "multipart", "gzip"] }
sha1 = "0.10"
sha2 = "0.10"
flate2 = "1"
Expand Down
Loading
Loading