( channel: ReleaseChannel, )
| 392 | * This is used by installations that don't have npm (e.g. package manager installs). |
| 393 | */ |
| 394 | export async function getLatestVersionFromGcs( |
| 395 | channel: ReleaseChannel, |
| 396 | ): Promise<string | null> { |
| 397 | const publicBinaryUrl = getPublicBinaryUrl() |
| 398 | if (publicBinaryUrl) { |
| 399 | try { |
| 400 | const response = await axios.get(`${publicBinaryUrl}/${channel}`, { |
| 401 | timeout: 5000, |
| 402 | responseType: 'text', |
| 403 | }) |
| 404 | return response.data.trim() |
| 405 | } catch (error) { |
| 406 | logForDebugging(`Failed to fetch ${channel} from binary repo: ${error}`) |
| 407 | return null |
| 408 | } |
| 409 | } |
| 410 | |
| 411 | try { |
| 412 | const response = await axios.get(GITHUB_RELEASES_API_URL, { |
| 413 | timeout: 5000, |
| 414 | responseType: 'json', |
| 415 | headers: { |
| 416 | Accept: 'application/vnd.github+json', |
| 417 | 'X-GitHub-Api-Version': '2022-11-28', |
| 418 | }, |
| 419 | params: { per_page: 25 }, |
| 420 | }) |
| 421 | const release = (response.data as Array<{ |
| 422 | draft?: boolean |
| 423 | prerelease?: boolean |
| 424 | tag_name?: string |
| 425 | }>).find(candidate => { |
| 426 | if (candidate.draft) return false |
| 427 | if (channel === 'stable' && candidate.prerelease) return false |
| 428 | return Boolean(candidate.tag_name) |
| 429 | }) |
| 430 | return release?.tag_name ? githubReleaseVersionFromTag(release.tag_name) : null |
| 431 | } catch (error) { |
| 432 | logForDebugging(`Failed to fetch ${channel} from GitHub releases: ${error}`) |
| 433 | return null |
| 434 | } |
| 435 | } |
| 436 | |
| 437 | /** |
| 438 | * Get available versions from GCS bucket (for native installations). |
no test coverage detected