From c5f40e5d2d03625ac27de0bfbc06a5c6f17e9f34 Mon Sep 17 00:00:00 2001 From: Rhuan Barreto Date: Sat, 21 Mar 2026 02:30:13 +0100 Subject: [PATCH 1/3] fix: support GITHUB_TOKEN in install scripts to avoid API rate limits Unauthenticated requests to api.github.com are limited to 60/hour per IP. When GITHUB_TOKEN is set, both install.ps1 and install.sh now pass an Authorization header, raising the limit to 5,000/hour. --- install.ps1 | 6 +++++- install.sh | 8 ++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/install.ps1 b/install.ps1 index 9d5de659..f5bec2d0 100644 --- a/install.ps1 +++ b/install.ps1 @@ -21,7 +21,11 @@ function Get-LatestVersion { return $env:ARCHGATE_VERSION } try { - $release = Invoke-RestMethod -Uri "https://api.github.com/repos/$Repo/releases/latest" -ErrorAction Stop + $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)" diff --git a/install.sh b/install.sh index d1e91904..e6d4e14e 100644 --- a/install.sh +++ b/install.sh @@ -59,11 +59,15 @@ resolve_version() { fi 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 From 043dc69693ccbe2ffe916dd078dfaff678fa55ae Mon Sep 17 00:00:00 2001 From: Rhuan Barreto Date: Sat, 21 Mar 2026 02:42:06 +0100 Subject: [PATCH 2/3] fix: serve version from static endpoint to avoid GitHub API rate limits Add a static `version.json` to the docs site (cli.archgate.dev) so install scripts can resolve the latest version without hitting the GitHub API, which rate-limits unauthenticated requests to 60/hour. - Add `docs/scripts/generate-version-json.ts` that reads the version from the root `package.json` and writes `docs/public/version.json` - Hook it into the docs build pipeline (`docs/package.json`) - Sync `version.json` in `.simple-release.js` during releases - Update `install.ps1` and `install.sh` to query `cli.archgate.dev/version.json` first, falling back to GitHub API (with optional GITHUB_TOKEN auth) if the static endpoint is unavailable --- .simple-release.js | 6 ++++++ docs/package.json | 2 +- docs/public/version.json | 1 + docs/scripts/generate-version-json.ts | 26 ++++++++++++++++++++++++++ install.ps1 | 14 +++++++++++++- install.sh | 23 +++++++++++++++++++++++ 6 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 docs/public/version.json create mode 100644 docs/scripts/generate-version-json.ts 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/package.json b/docs/package.json index 8b6897c3..31273730 100644 --- a/docs/package.json +++ b/docs/package.json @@ -3,7 +3,7 @@ "private": true, "type": "module", "scripts": { - "build": "bun run scripts/generate-llms-full.ts && astro build", + "build": "bun run scripts/generate-version-json.ts && bun run scripts/generate-llms-full.ts && astro build", "dev": "astro dev", "preview": "astro preview" }, 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/docs/scripts/generate-version-json.ts b/docs/scripts/generate-version-json.ts new file mode 100644 index 00000000..87e15e11 --- /dev/null +++ b/docs/scripts/generate-version-json.ts @@ -0,0 +1,26 @@ +/** + * Generates `public/version.json` so the install scripts can resolve the + * latest release without hitting the GitHub API (which has aggressive + * unauthenticated rate limits). + * + * The version is read from the root `package.json` — ARCH-013 already + * enforces that `docs/astro.config.mjs` stays in sync, so this is the + * single source of truth. + * + * Run automatically before `astro build` or manually: + * + * bun run docs/scripts/generate-version-json.ts + */ +import { readFileSync, writeFileSync } from "node:fs"; +import { join } from "node:path"; + +const rootPkgPath = join(import.meta.dirname, "..", "..", "package.json"); +const outputPath = join(import.meta.dirname, "..", "public", "version.json"); + +const pkg = JSON.parse(readFileSync(rootPkgPath, "utf-8")) as { + version: string; +}; + +const payload = `{ "version": "v${pkg.version}" }\n`; +writeFileSync(outputPath, payload, "utf-8"); +console.log(`Generated version.json: v${pkg.version}`); diff --git a/install.ps1 b/install.ps1 index f5bec2d0..eb093bec 100644 --- a/install.ps1 +++ b/install.ps1 @@ -20,6 +20,18 @@ function Get-LatestVersion { if ($env:ARCHGATE_VERSION) { return $env:ARCHGATE_VERSION } + + # Primary: static version endpoint (no rate limits) + try { + $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) { @@ -28,7 +40,7 @@ function Get-LatestVersion { $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 e6d4e14e..fcd30c89 100644 --- a/install.sh +++ b/install.sh @@ -58,6 +58,29 @@ 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 From 3169a81af5abcdd6788448f6cfa5112ab36c6dac Mon Sep 17 00:00:00 2001 From: Rhuan Barreto Date: Sat, 21 Mar 2026 02:54:00 +0100 Subject: [PATCH 3/3] refactor: remove generate-version-json script from docs build version.json is written by .simple-release.js on every version bump and committed to the repo, so regenerating it during docs build is redundant. --- docs/package.json | 2 +- docs/scripts/generate-version-json.ts | 26 -------------------------- 2 files changed, 1 insertion(+), 27 deletions(-) delete mode 100644 docs/scripts/generate-version-json.ts diff --git a/docs/package.json b/docs/package.json index 31273730..8b6897c3 100644 --- a/docs/package.json +++ b/docs/package.json @@ -3,7 +3,7 @@ "private": true, "type": "module", "scripts": { - "build": "bun run scripts/generate-version-json.ts && bun run scripts/generate-llms-full.ts && astro build", + "build": "bun run scripts/generate-llms-full.ts && astro build", "dev": "astro dev", "preview": "astro preview" }, diff --git a/docs/scripts/generate-version-json.ts b/docs/scripts/generate-version-json.ts deleted file mode 100644 index 87e15e11..00000000 --- a/docs/scripts/generate-version-json.ts +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Generates `public/version.json` so the install scripts can resolve the - * latest release without hitting the GitHub API (which has aggressive - * unauthenticated rate limits). - * - * The version is read from the root `package.json` — ARCH-013 already - * enforces that `docs/astro.config.mjs` stays in sync, so this is the - * single source of truth. - * - * Run automatically before `astro build` or manually: - * - * bun run docs/scripts/generate-version-json.ts - */ -import { readFileSync, writeFileSync } from "node:fs"; -import { join } from "node:path"; - -const rootPkgPath = join(import.meta.dirname, "..", "..", "package.json"); -const outputPath = join(import.meta.dirname, "..", "public", "version.json"); - -const pkg = JSON.parse(readFileSync(rootPkgPath, "utf-8")) as { - version: string; -}; - -const payload = `{ "version": "v${pkg.version}" }\n`; -writeFileSync(outputPath, payload, "utf-8"); -console.log(`Generated version.json: v${pkg.version}`);