From 6e0d9d0fdd20e399a0dd5b98601467951776a803 Mon Sep 17 00:00:00 2001 From: Mikael Hoegqvist Tabor Date: Wed, 11 Oct 2023 12:03:39 +0200 Subject: [PATCH] improvement: using a new release endpoint for self-update --- core/src/cli/cli.ts | 4 ++-- core/src/cli/helpers.ts | 4 ++-- core/src/commands/self-update.ts | 7 ++++--- core/src/constants.ts | 11 ++++++++++- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/core/src/cli/cli.ts b/core/src/cli/cli.ts index 2a7d486dd2..6df2f702ea 100644 --- a/core/src/cli/cli.ts +++ b/core/src/cli/cli.ts @@ -345,8 +345,8 @@ ${renderCommands(commands)} // Note: No reason to await the check checkForUpdates(garden.globalConfigStore, log).catch((err) => { - log.verbose("Something went wrong while checking for the latest Garden version.") - log.verbose(err) + log.verbose(`Something went wrong while checking for the latest Garden version.`) + log.verbose(err.toString()) }) await checkForStaticDir() diff --git a/core/src/cli/helpers.ts b/core/src/cli/helpers.ts index 36f736cc60..6fff15c0dd 100644 --- a/core/src/cli/helpers.ts +++ b/core/src/cli/helpers.ts @@ -22,7 +22,7 @@ import { ParameterValues, Parameter, ParameterObject, globalDisplayOptions } fro import { GardenError, ParameterError, RuntimeError, toGardenError } from "../exceptions" import { getPackageVersion, removeSlice } from "../util/util" import { Log } from "../logger/log-entry" -import { STATIC_DIR, VERSION_CHECK_URL, gardenEnv, ERROR_LOG_FILENAME } from "../constants" +import { STATIC_DIR, gardenEnv, ERROR_LOG_FILENAME } from "../constants" import { printWarningMessage } from "../logger/util" import { GlobalConfigStore } from "../config-store/global" import { got } from "../util/http" @@ -95,7 +95,7 @@ export async function checkForUpdates(config: GlobalConfigStore, logger: Log) { headers["X-ci-name"] = ci.name } - const res = await got(`${VERSION_CHECK_URL}?${qs.stringify(query)}`, { headers }).json() + const res = await got(`${gardenEnv.GARDEN_VERSION_CHECK_ENDPOINT}?${qs.stringify(query)}`, { headers }).json() const versionCheck = await config.get("versionCheck") const showMessage = versionCheck && moment().subtract(1, "days").isAfter(moment(versionCheck.lastRun)) diff --git a/core/src/commands/self-update.ts b/core/src/commands/self-update.ts index 74eeae5fb0..b94042dc11 100644 --- a/core/src/commands/self-update.ts +++ b/core/src/commands/self-update.ts @@ -20,6 +20,7 @@ import { createReadStream, createWriteStream } from "fs" import { copy, mkdirp, move, readdir, remove } from "fs-extra" import { GotHttpError, got } from "../util/http" import { promisify } from "node:util" +import { gardenEnv } from "../constants" import semver from "semver" import stream from "stream" @@ -97,7 +98,7 @@ export type Pagination = { pageNumber: number; pageSize: number } export async function fetchReleases({ pageNumber, pageSize }: Pagination) { const results: any[] = await got( - `https://api.github.com/repos/garden-io/garden/releases?page=${pageNumber}&per_page=${[pageSize]}` + `${gardenEnv.GARDEN_RELEASES_ENDPOINT}?page=${pageNumber}&per_page=${[pageSize]}` ).json() return results } @@ -159,7 +160,7 @@ export async function findRelease({ * @throws {RuntimeError} if the latest version cannot be detected */ export async function getLatestVersion(): Promise { - const latestVersionRes: any = await got("https://api.github.com/repos/garden-io/garden/releases/latest").json() + const latestVersionRes: any = await got(`${gardenEnv.GARDEN_RELEASES_ENDPOINT}/latest`).json() const latestVersion = latestVersionRes.tag_name if (!latestVersion) { throw new RuntimeError({ @@ -171,7 +172,7 @@ export async function getLatestVersion(): Promise { } export async function getLatestVersions(numOfStableVersions: number) { - const res: any = await got("https://api.github.com/repos/garden-io/garden/releases?per_page=100").json() + const res: any = await got(`${gardenEnv.GARDEN_RELEASES_ENDPOINT}?per_page=100`).json() return [ chalk.cyan("edge-acorn"), diff --git a/core/src/constants.ts b/core/src/constants.ts index 98a5d807f8..39ccd7a445 100644 --- a/core/src/constants.ts +++ b/core/src/constants.ts @@ -45,7 +45,6 @@ export const SEGMENT_DEV_API_KEY = "D3DUZ3lBSDO3krnuIO7eYDdtlDAjooKW" // ggignor export const SEGMENT_PROD_API_KEY = "b6ovUD9A0YjQqT3ZWetWUbuZ9OmGxKMa" // ggignore export const DOCS_BASE_URL = "https://docs.garden.io" -export const VERSION_CHECK_URL = "https://get.garden.io/version" export const DEFAULT_GARDEN_CLOUD_DOMAIN = "https://app.garden.io" @@ -78,4 +77,14 @@ export const gardenEnv = { GARDEN_WORKFLOW_RUN_UID: env.get("GARDEN_WORKFLOW_RUN_UID").required(false).asString(), GARDEN_CLOUD_DOMAIN: env.get("GARDEN_CLOUD_DOMAIN").required(false).asUrlString(), GARDEN_ENABLE_TRACING: env.get("GARDEN_ENABLE_TRACING").required(false).default("true").asBool(), + GARDEN_VERSION_CHECK_ENDPOINT: env + .get("GARDEN_VERSION_CHECK_ENDPOINT") + .required(false) + .default("https://get.garden.io/version") + .asUrlString(), + GARDEN_RELEASES_ENDPOINT: env + .get("GARDEN_RELEASES_ENDPOINT") + .required(false) + .default("https://get.garden.io/releases") + .asUrlString(), }