Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improvement: using a new release endpoint for self-update #5229

Merged
merged 6 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
17 changes: 12 additions & 5 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 All @@ -43,6 +44,10 @@ const selfUpdateOpts = {
choices: ["macos", "linux", "windows"],
help: `Override the platform, instead of detecting it automatically.`,
}),
"architecture": new ChoicesParameter({
choices: ["arm64", "amd64"],
help: `Override the architecture, instead of detecting it automatically.`,
}),
"major": new BooleanParameter({
defaultValue: false,
// TODO Core 1.0 major release: add these notes:
Expand Down Expand Up @@ -97,7 +102,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
}
Expand Down Expand Up @@ -159,7 +164,7 @@ export async function findRelease({
* @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 @@ -171,7 +176,7 @@ export async function getLatestVersion(): Promise<string> {
}

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 Expand Up @@ -305,7 +310,7 @@ export class SelfUpdateCommand extends Command<SelfUpdateArgs, SelfUpdateOpts> {
platform = getPlatform() === "darwin" ? "macos" : getPlatform()
}

let architecture = getArchitecture()
let architecture: Architecture = opts.architecture ? (opts.architecture as Architecture) : getArchitecture()
const isArmInRosetta = isDarwinARM()

// When running under Rosetta,
Expand All @@ -314,13 +319,15 @@ export class SelfUpdateCommand extends Command<SelfUpdateArgs, SelfUpdateOpts> {
// so we override the architecture here
// and then check if the version is supported or not
// potentially reverting it back to amd64 again
if (isArmInRosetta) {
if (!opts.architecture && isArmInRosetta) {
architecture = "arm64"
}

if (
!opts.architecture &&
architecture === "arm64" &&
desiredVersion !== "edge-bonsai" &&
semver.valid(desiredVersion) !== null &&
semver.lt(desiredVersion, ARM64_INTRODUCTION_VERSION)
) {
if (platform === "macos") {
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(),
}
Binary file not shown.
Loading