From dd96d8fb33992a21a7f6f70678ff1bde165197b4 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Tue, 20 Aug 2024 18:19:13 -0400 Subject: [PATCH] feat(upgrade): support LTS release channel --- cli/tools/upgrade.rs | 164 +++++++++++++++---------------------------- 1 file changed, 56 insertions(+), 108 deletions(-) diff --git a/cli/tools/upgrade.rs b/cli/tools/upgrade.rs index db43b8be17..633e0b0461 100644 --- a/cli/tools/upgrade.rs +++ b/cli/tools/upgrade.rs @@ -35,7 +35,7 @@ use std::time::Duration; const RELEASE_URL: &str = "https://github.com/denoland/deno/releases"; const CANARY_URL: &str = "https://dl.deno.land/canary"; -const RC_URL: &str = "https://dl.deno.land/release"; +const DL_RELEASE_URL: &str = "https://dl.deno.land/release"; pub static ARCHIVE_NAME: Lazy = Lazy::new(|| format!("deno-{}.zip", env!("TARGET"))); @@ -330,8 +330,15 @@ pub fn check_for_upgrades( colors::italic_gray("Run `deno upgrade --rc` to install it.") ); } - // TODO(bartlomieju) - ReleaseChannel::Lts => unreachable!(), + ReleaseChannel::Lts => { + log::info!( + "{} {} → {} {}", + colors::green("A new LTS release of Deno is available:"), + colors::cyan(version::DENO_VERSION_INFO.deno), + colors::cyan(&upgrade_version), + colors::italic_gray("Run `deno upgrade` to install it.") + ); + } } update_checker.store_prompted(); @@ -369,7 +376,7 @@ async fn check_for_upgrades_for_lsp_with_provider( } match release_channel { - ReleaseChannel::Stable | ReleaseChannel::Rc => { + ReleaseChannel::Stable | ReleaseChannel::Rc | ReleaseChannel::Lts => { if let Ok(current) = Version::parse_standard(¤t_version) { if let Ok(latest) = Version::parse_standard(&latest_version.version_or_hash) @@ -389,9 +396,6 @@ async fn check_for_upgrades_for_lsp_with_provider( latest_version: latest_version.version_or_hash, is_canary: true, })), - - // TODO(bartlomieju) - ReleaseChannel::Lts => unreachable!(), } } @@ -623,65 +627,30 @@ fn select_specific_version_for_upgrade( version: String, force: bool, ) -> Result, AnyError> { - match release_channel { - ReleaseChannel::Stable => { - let current_is_passed = if version::DENO_VERSION_INFO.release_channel - != ReleaseChannel::Canary - { - version::DENO_VERSION_INFO.deno == version - } else { - false - }; - - if !force && current_is_passed { - log::info!( - "Version {} is already installed", - version::DENO_VERSION_INFO.deno - ); - return Ok(None); - } - - Ok(Some(AvailableVersion { - version_or_hash: version, - release_channel, - })) - } - ReleaseChannel::Canary => { - let current_is_passed = version::DENO_VERSION_INFO.git_hash == version; - if !force && current_is_passed { - log::info!( - "Version {} is already installed", - version::DENO_VERSION_INFO.deno - ); - return Ok(None); - } - - Ok(Some(AvailableVersion { - version_or_hash: version, - release_channel, - })) + let current_is_passed = match release_channel { + ReleaseChannel::Stable | ReleaseChannel::Lts => { + version::DENO_VERSION_INFO.release_channel != ReleaseChannel::Canary + && version::DENO_VERSION_INFO.deno == version } + ReleaseChannel::Canary => version::DENO_VERSION_INFO.git_hash == version, ReleaseChannel::Rc => { - let current_is_passed = version::DENO_VERSION_INFO.release_channel - == ReleaseChannel::Rc - && version::DENO_VERSION_INFO.deno == version; - - if !force && current_is_passed { - log::info!( - "Version {} is already installed", - version::DENO_VERSION_INFO.deno - ); - return Ok(None); - } - - Ok(Some(AvailableVersion { - version_or_hash: version, - release_channel, - })) + version::DENO_VERSION_INFO.release_channel == ReleaseChannel::Rc + && version::DENO_VERSION_INFO.deno == version } - // TODO(bartlomieju) - ReleaseChannel::Lts => unreachable!(), + }; + + if !force && current_is_passed { + log::info!( + "Version {} is already installed", + version::DENO_VERSION_INFO.deno + ); + return Ok(None); } + + Ok(Some(AvailableVersion { + version_or_hash: version, + release_channel, + })) } async fn find_latest_version_to_upgrade( @@ -700,47 +669,6 @@ async fn find_latest_version_to_upgrade( .await?; let (maybe_newer_latest_version, current_version) = match release_channel { - ReleaseChannel::Stable => { - let current_version = version::DENO_VERSION_INFO.deno; - - // If the current binary is not a stable channel, we can skip - // computation if we're on a newer release - we're not. - if version::DENO_VERSION_INFO.release_channel != ReleaseChannel::Stable { - (Some(latest_version_found), current_version) - } else { - let current = Version::parse_standard(current_version).unwrap(); - let latest = - Version::parse_standard(&latest_version_found.version_or_hash) - .unwrap(); - let current_is_most_recent = current >= latest; - - if !force && current_is_most_recent { - (None, current_version) - } else { - (Some(latest_version_found), current_version) - } - } - } - ReleaseChannel::Rc => { - let current_version = version::DENO_VERSION_INFO.deno; - - // If the current binary is not an rc channel, we can skip - // computation if we're on a newer release - we're not. - if version::DENO_VERSION_INFO.release_channel != ReleaseChannel::Rc { - (Some(latest_version_found), current_version) - } else { - let current = Version::parse_standard(current_version).unwrap(); - let latest = - Version::parse_standard(&latest_version_found.version_or_hash) - .unwrap(); - let current_is_most_recent = current >= latest; - if !force && current_is_most_recent { - (None, current_version) - } else { - (Some(latest_version_found), current_version) - } - } - } ReleaseChannel::Canary => { let current_version = version::DENO_VERSION_INFO.git_hash; let current_is_most_recent = @@ -752,8 +680,26 @@ async fn find_latest_version_to_upgrade( (Some(latest_version_found), current_version) } } - // TODO(bartlomieju) - ReleaseChannel::Lts => unreachable!(), + ReleaseChannel::Stable | ReleaseChannel::Lts | ReleaseChannel::Rc => { + let current_version = version::DENO_VERSION_INFO.deno; + + // If the current binary is not the same channel, we can skip + // computation if we're on a newer release - we're not. + if version::DENO_VERSION_INFO.release_channel != release_channel { + (Some(latest_version_found), current_version) + } else { + let current = Version::parse_standard(current_version)?; + let latest = + Version::parse_standard(&latest_version_found.version_or_hash)?; + let current_is_most_recent = current >= latest; + + if !force && current_is_most_recent { + (None, current_version) + } else { + (Some(latest_version_found), current_version) + } + } + } }; log::info!(""); @@ -833,7 +779,7 @@ fn get_latest_version_url( Cow::Owned(format!("canary-{target_tuple}-latest.txt")) } ReleaseChannel::Rc => Cow::Borrowed("release-rc-latest.txt"), - _ => unreachable!(), + ReleaseChannel::Lts => Cow::Borrowed("release-lts-latest.txt"), }; let query_param = match check_kind { UpgradeCheckKind::Execution => "", @@ -860,12 +806,14 @@ fn get_download_url( format!("{}/download/v{}/{}", RELEASE_URL, version, *ARCHIVE_NAME) } ReleaseChannel::Rc => { - format!("{}/v{}/{}", RC_URL, version, *ARCHIVE_NAME) + format!("{}/v{}/{}", DL_RELEASE_URL, version, *ARCHIVE_NAME) } ReleaseChannel::Canary => { format!("{}/{}/{}", CANARY_URL, version, *ARCHIVE_NAME) } - ReleaseChannel::Lts => unreachable!(), + ReleaseChannel::Lts => { + format!("{}/v{}/{}", DL_RELEASE_URL, version, *ARCHIVE_NAME) + } }; Url::parse(&download_url).with_context(|| {