Skip to content

Commit

Permalink
improvement: using a new release endpoint for self-update
Browse files Browse the repository at this point in the history
  • Loading branch information
mkhq committed Oct 11, 2023
1 parent c6016f4 commit 0a6b643
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
4 changes: 2 additions & 2 deletions core/src/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions core/src/cli/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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<any>()
const res = await got(`${gardenEnv.GARDEN_VERSION_CHECK_ENDPOINT}?${qs.stringify(query)}`, { headers }).json<any>()
const versionCheck = await config.get("versionCheck")
const showMessage = versionCheck && moment().subtract(1, "days").isAfter(moment(versionCheck.lastRun))

Expand Down
7 changes: 4 additions & 3 deletions core/src/commands/self-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -98,7 +99,7 @@ export namespace GitHubReleaseApi {

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
}
Expand Down Expand Up @@ -160,7 +161,7 @@ export namespace GitHubReleaseApi {
* @throws {RuntimeError} if the latest version cannot be detected
*/
export async function getLatestVersion(): Promise<string> {
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({
Expand All @@ -172,7 +173,7 @@ export namespace GitHubReleaseApi {
}

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"),
Expand Down
11 changes: 10 additions & 1 deletion core/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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(),
}

0 comments on commit 0a6b643

Please sign in to comment.