diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2024-08-15 20:59:16 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-15 21:59:16 +0200 |
commit | e8d57cd3feb169c6a8e9cb11d96c0f2d0b7d50f8 (patch) | |
tree | aaaa9aa09a41888d2b09167c30eda3e0b07d4036 /cli/tools | |
parent | 8749d651fb5e0964cdb8e62be7a59a603cbc3c7c (diff) |
refactor: remove version::is_canary(), use ReleaseChannel instead (#25053)
In preparation for https://github.com/denoland/deno/pull/25014, this
commit removes public `is_canary()` method and instead uses an enum
`ReleaseChannel` to be able to designate more "kinds" of builds.
Diffstat (limited to 'cli/tools')
-rw-r--r-- | cli/tools/upgrade.rs | 81 |
1 files changed, 19 insertions, 62 deletions
diff --git a/cli/tools/upgrade.rs b/cli/tools/upgrade.rs index 925a033fe..01239964c 100644 --- a/cli/tools/upgrade.rs +++ b/cli/tools/upgrade.rs @@ -8,6 +8,7 @@ use crate::colors; use crate::factory::CliFactory; use crate::http_util::HttpClient; use crate::http_util::HttpClientProvider; +use crate::shared::ReleaseChannel; use crate::util::archive; use crate::util::progress_bar::ProgressBar; use crate::util::progress_bar::ProgressBarStyle; @@ -146,7 +147,8 @@ impl VersionProvider for RealVersionProvider { async fn get_current_exe_release_channel( &self, ) -> Result<ReleaseChannel, AnyError> { - if version::is_canary() { + // TODO(bartlomieju): remove hitting a remote server + if matches!(version::RELEASE_CHANNEL, ReleaseChannel::Canary) { // If this fails for whatever reason, just return an empty vector. // It's better to miss that than throw error here. let rc_versions = get_rc_versions( @@ -636,11 +638,12 @@ fn select_specific_version_for_upgrade( ) -> Result<Option<AvailableVersion>, AnyError> { match release_channel { ReleaseChannel::Stable => { - let current_is_passed = if !version::is_canary() { - version::deno() == version - } else { - false - }; + let current_is_passed = + if !matches!(version::RELEASE_CHANNEL, ReleaseChannel::Canary) { + version::deno() == version + } else { + false + }; if !force && current_is_passed { log::info!("Version {} is already installed", version::deno()); @@ -691,15 +694,16 @@ async fn find_latest_version_to_upgrade( let (maybe_newer_latest_version, current_version) = match release_channel { ReleaseChannel::Stable => { let current_version = version::deno(); - let current_is_most_recent = if !version::is_canary() { - let current = Version::parse_standard(current_version).unwrap(); - let latest = - Version::parse_standard(&latest_version_found.version_or_hash) - .unwrap(); - current >= latest - } else { - false - }; + let current_is_most_recent = + if !matches!(version::RELEASE_CHANNEL, ReleaseChannel::Canary) { + let current = Version::parse_standard(current_version).unwrap(); + let latest = + Version::parse_standard(&latest_version_found.version_or_hash) + .unwrap(); + current >= latest + } else { + false + }; if !force && current_is_most_recent { (None, current_version) @@ -751,53 +755,6 @@ async fn find_latest_version_to_upgrade( Ok(maybe_newer_latest_version) } -#[derive(Debug, Clone, Copy, PartialEq)] -enum ReleaseChannel { - /// Stable version, eg. 1.45.4, 2.0.0, 2.1.0 - Stable, - - /// Pointing to a git hash - Canary, - - /// Long term support release - #[allow(unused)] - Lts, - - /// Release candidate, poiting to a git hash - Rc, -} - -impl ReleaseChannel { - fn name(&self) -> &str { - match self { - Self::Stable => "latest", - Self::Canary => "canary", - Self::Rc => "release candidate", - Self::Lts => "LTS (long term support)", - } - } - - fn serialize(&self) -> String { - match self { - Self::Stable => "stable", - Self::Canary => "canary", - Self::Rc => "rc", - Self::Lts => "lts", - } - .to_string() - } - - fn deserialize(str_: &str) -> Result<Self, AnyError> { - Ok(match str_ { - "stable" => Self::Stable, - "canary" => Self::Canary, - "rc" => Self::Rc, - "lts" => Self::Lts, - unknown => bail!("Unrecognized release channel: {}", unknown), - }) - } -} - // Return a list of available RC release in format of (<commit_hash>, <version_name>) fn parse_rc_versions_text( text: &str, |