diff --git a/.simple-release.js b/.simple-release.js index 9e6808c9..76cf41f8 100644 --- a/.simple-release.js +++ b/.simple-release.js @@ -40,6 +40,12 @@ class ArchgateProject extends NpmProject { this.changedFiles.push(astroConfigPath); } } + + // Sync docs/public/version.json (used by install scripts) + const versionJsonPath = "docs/public/version.json"; + const versionPayload = `{ "version": "v${version}" }\n`; + writeFileSync(versionJsonPath, versionPayload); + this.changedFiles.push(versionJsonPath); } return result; diff --git a/docs/public/version.json b/docs/public/version.json new file mode 100644 index 00000000..f38a1832 --- /dev/null +++ b/docs/public/version.json @@ -0,0 +1 @@ +{ "version": "v0.17.0" } diff --git a/install.ps1 b/install.ps1 index 9d5de659..eb093bec 100644 --- a/install.ps1 +++ b/install.ps1 @@ -20,11 +20,27 @@ function Get-LatestVersion { if ($env:ARCHGATE_VERSION) { return $env:ARCHGATE_VERSION } + + # Primary: static version endpoint (no rate limits) try { - $release = Invoke-RestMethod -Uri "https://api.github.com/repos/$Repo/releases/latest" -ErrorAction Stop + $versionInfo = Invoke-RestMethod -Uri "https://cli.archgate.dev/version.json" -ErrorAction Stop + if ($versionInfo.version) { + return $versionInfo.version + } + } catch { + # Fall through to GitHub API + } + + # Fallback: GitHub releases API + try { + $headers = @{ "Accept" = "application/vnd.github+json" } + if ($env:GITHUB_TOKEN) { + $headers["Authorization"] = "token $($env:GITHUB_TOKEN)" + } + $release = Invoke-RestMethod -Uri "https://api.github.com/repos/$Repo/releases/latest" -Headers $headers -ErrorAction Stop return $release.tag_name } catch { - Write-Error "Error: failed to query GitHub for latest archgate version. Details: $($_.Exception.Message)" + Write-Error "Error: failed to query latest archgate version. Details: $($_.Exception.Message)" return $null } } diff --git a/install.sh b/install.sh index d1e91904..fcd30c89 100644 --- a/install.sh +++ b/install.sh @@ -58,12 +58,39 @@ resolve_version() { return fi + # Primary: static version endpoint (no rate limits) + version_url="https://cli.archgate.dev/version.json" + static_response="" + + if command -v curl >/dev/null 2>&1; then + static_response="$(curl -fsSL "$version_url" 2>/dev/null || true)" + elif command -v wget >/dev/null 2>&1; then + static_response="$(wget -qO- "$version_url" 2>/dev/null || true)" + fi + + if [ -n "$static_response" ]; then + if command -v jq >/dev/null 2>&1; then + static_version="$(printf '%s' "$static_response" | jq -r '.version // empty')" + else + static_version="$(printf '%s' "$static_response" | grep '"version"' | sed 's/.*"version": *"//;s/".*//')" + fi + if [ -n "$static_version" ]; then + VERSION="$static_version" + return + fi + fi + + # Fallback: GitHub releases API api_url="https://api.github.com/repos/${REPO}/releases/latest" + auth_header="" + if [ -n "${GITHUB_TOKEN:-}" ]; then + auth_header="Authorization: token ${GITHUB_TOKEN}" + fi if command -v curl >/dev/null 2>&1; then - response="$(curl -fsSL "$api_url" || true)" + response="$(curl -fsSL ${auth_header:+-H "$auth_header"} "$api_url" || true)" elif command -v wget >/dev/null 2>&1; then - response="$(wget -qO- "$api_url" 2>/dev/null || true)" + response="$(wget -qO- ${auth_header:+--header="$auth_header"} "$api_url" 2>/dev/null || true)" else echo "Error: curl or wget is required." >&2 exit 1