A new version of Supabase CLI is available:
If you'd like to try, we recommend doing so via npm:
-+ Latest Beta version: {data.beta} +
+ }Current version:
-{data.current}
+{currentCliVersion}
Available version:
{data.latest}
diff --git a/apps/studio/components/layouts/ProjectLayout/LayoutHeader/LocalVersionPopover.utils.ts b/apps/studio/components/layouts/ProjectLayout/LayoutHeader/LocalVersionPopover.utils.ts new file mode 100644 index 0000000000..31a872961e --- /dev/null +++ b/apps/studio/components/layouts/ProjectLayout/LayoutHeader/LocalVersionPopover.utils.ts @@ -0,0 +1,28 @@ +type CLIVersionSemver = { major: number; minor: number; patch: number } + +// [Joshen] Specifically in the syntax of `v0.0.0` +export const getSemver = (version?: string) => { + if (!version) return undefined + const [major, minor, patch] = version.slice(1).split('.') + return { major: Number(major), minor: Number(minor), patch: Number(patch) } +} + +export const semverLte = (a: CLIVersionSemver, b: CLIVersionSemver) => { + if ( + a.major > b.major || + (a.major === b.major && a.minor > b.minor) || + (a.major === b.major && a.minor === b.minor && a.patch > b.patch) + ) + return false + return true +} + +export const semverGte = (a: CLIVersionSemver, b: CLIVersionSemver) => { + if ( + a.major < b.major || + (a.major === b.major && a.minor < b.minor) || + (a.major === b.major && a.minor === b.minor && a.patch < b.patch) + ) + return false + return true +} diff --git a/apps/studio/data/misc/cli-release-version-query.ts b/apps/studio/data/misc/cli-release-version-query.ts index c28f0c0694..3394ca3405 100644 --- a/apps/studio/data/misc/cli-release-version-query.ts +++ b/apps/studio/data/misc/cli-release-version-query.ts @@ -7,7 +7,7 @@ import { miscKeys } from './keys' export async function getCLIReleaseVersion() { try { const data = await fetch(`${BASE_PATH}/api/cli-release-version`).then((res) => res.json()) - return data as { current: string | null; latest: string | null; published_at: string | null } + return data as { current?: string; latest?: string; beta?: string; published_at?: string } } catch (error) { throw error } diff --git a/apps/studio/pages/api/cli-release-version.ts b/apps/studio/pages/api/cli-release-version.ts index c57941fd45..0c67461cb3 100644 --- a/apps/studio/pages/api/cli-release-version.ts +++ b/apps/studio/pages/api/cli-release-version.ts @@ -8,23 +8,25 @@ type GitHubRepositoryRelease = { published_at: string } +const current = process.env.CURRENT_CLI_VERSION + const handler = async (req: NextApiRequest, res: NextApiResponse) => { - // [Joshen] Added under supabase/turbo.json, but not sure why it's still warning - // eslint-disable-next-line turbo/no-undeclared-env-vars - const version = process.env.CURRENT_CLI_VERSION - const fallback = { current: version, latest: null, published_at: null } try { - const data: GitHubRepositoryRelease[] = await fetch( - 'https://api.github.com/repos/supabase/cli/releases?per_page=1' + const { tag_name: latest, published_at }: GitHubRepositoryRelease = await fetch( + 'https://api.github.com/repos/supabase/cli/releases/latest' ).then((res) => res.json()) - if (data.length === 0) return res.status(200).json(fallback) + const data: GitHubRepositoryRelease[] = await fetch( + 'https://api.github.com/repos/supabase/cli/releases?per_page=1' + ) + .then((res) => res.json()) + // Ignore errors fetching beta release version + .catch(() => []) + const beta = data[0]?.tag_name - return res - .status(200) - .json({ current: version, latest: data[0].tag_name, published_at: data[0].published_at }) + return res.status(200).json({ current, latest, beta, published_at }) } catch { - return res.status(200).json(fallback) + return res.status(200).json({ current }) } } diff --git a/turbo.json b/turbo.json index cc99f10f52..d2d085b1a6 100644 --- a/turbo.json +++ b/turbo.json @@ -71,9 +71,9 @@ "FORCE_ASSET_CDN", "ASSET_CDN_S3_ENDPOINT", "SITE_NAME", - "VERCEL_URL", - "CURRENT_CLI_VERSION" + "VERCEL_URL" ], + "passThroughEnv": ["CURRENT_CLI_VERSION"], "outputs": [".next/**", "!.next/cache/**"] }, "www#build": {