1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

fix(upgrade): use proper version display (#25029)

This commit fixes output of `deno upgrade` subcommand,
by displaying proper version numbers. Before this PR we were
prepending "v" before the canary version hash, which was
obviously wrong.
This commit is contained in:
Bartek Iwańczuk 2024-08-13 23:32:20 +01:00 committed by GitHub
parent 25bb59d2ce
commit 8537c4537b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -264,14 +264,16 @@ fn print_release_notes(current_version: &str, new_version: &str) {
} }
log::info!( log::info!(
"Release notes:\n\n {}\n", "{}\n\n {}\n",
colors::gray("Release notes:"),
colors::bold(format!( colors::bold(format!(
"https://github.com/denoland/deno/releases/tag/v{}", "https://github.com/denoland/deno/releases/tag/v{}",
&new_version, &new_version,
)) ))
); );
log::info!( log::info!(
"Blog post:\n\n {}\n", "{}\n\n {}\n",
colors::gray("Blog post:"),
colors::bold(format!( colors::bold(format!(
"https://deno.com/blog/v{}", "https://deno.com/blog/v{}",
get_minor_version(new_version) get_minor_version(new_version)
@ -561,11 +563,8 @@ pub async fn upgrade(
check_windows_access_denied_error(output_result, output_exe_path)?; check_windows_access_denied_error(output_result, output_exe_path)?;
log::info!( log::info!(
"{}", "\nUpgraded successfully to Deno {}\n",
colors::green(format!( colors::green(selected_version_to_upgrade.display())
"\nUpgraded successfully to Deno v{}\n",
selected_version_to_upgrade.display
))
); );
if !requested_version.is_canary() { if !requested_version.is_canary() {
print_release_notes(version::deno(), &selected_version_to_upgrade.display); print_release_notes(version::deno(), &selected_version_to_upgrade.display);
@ -650,6 +649,7 @@ fn select_specific_version_for_upgrade(
Ok(Some(AvailableVersion { Ok(Some(AvailableVersion {
version_or_hash: version.to_string(), version_or_hash: version.to_string(),
release_channel,
display: version, display: version,
})) }))
} }
@ -662,6 +662,7 @@ fn select_specific_version_for_upgrade(
Ok(Some(AvailableVersion { Ok(Some(AvailableVersion {
version_or_hash: version.to_string(), version_or_hash: version.to_string(),
release_channel,
display: version, display: version,
})) }))
} }
@ -735,19 +736,14 @@ async fn find_latest_version_to_upgrade(
log::info!(""); log::info!("");
if let Some(newer_latest_version) = maybe_newer_latest_version.as_ref() { if let Some(newer_latest_version) = maybe_newer_latest_version.as_ref() {
log::info!( log::info!(
"{}", "Found latest {} version {}",
color_print::cformat!( newer_latest_version.release_channel.name(),
"<g>Found latest version {}</>", color_print::cformat!("<g>{}</>", newer_latest_version.display())
newer_latest_version.display
)
); );
} else { } else {
log::info!( log::info!(
"{}", "Local deno version {} is the most recent release",
color_print::cformat!( color_print::cformat!("<g>{}</>", current_version)
"<g>Local deno version {} is the most recent release</>",
current_version
)
); );
} }
log::info!(""); log::info!("");
@ -841,9 +837,21 @@ async fn get_rc_versions(
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq)]
struct AvailableVersion { struct AvailableVersion {
version_or_hash: String, version_or_hash: String,
release_channel: ReleaseChannel,
display: String, display: String,
} }
impl AvailableVersion {
/// Format display version, appending `v` before version number
/// for non-canary releases.
fn display(&self) -> Cow<str> {
match self.release_channel {
ReleaseChannel::Canary => Cow::Borrowed(&self.display),
_ => Cow::Owned(format!("v{}", self.display)),
}
}
}
async fn fetch_latest_version( async fn fetch_latest_version(
client: &HttpClient, client: &HttpClient,
release_channel: ReleaseChannel, release_channel: ReleaseChannel,
@ -865,11 +873,13 @@ fn normalize_version_from_server(
let v = text.trim_start_matches('v').to_string(); let v = text.trim_start_matches('v').to_string();
Ok(AvailableVersion { Ok(AvailableVersion {
version_or_hash: v.to_string(), version_or_hash: v.to_string(),
release_channel,
display: v.to_string(), display: v.to_string(),
}) })
} }
ReleaseChannel::Canary => Ok(AvailableVersion { ReleaseChannel::Canary => Ok(AvailableVersion {
version_or_hash: text.to_string(), version_or_hash: text.to_string(),
release_channel,
display: text.to_string(), display: text.to_string(),
}), }),
ReleaseChannel::Rc => { ReleaseChannel::Rc => {
@ -877,6 +887,7 @@ fn normalize_version_from_server(
let latest = lines.last().unwrap(); let latest = lines.last().unwrap();
Ok(AvailableVersion { Ok(AvailableVersion {
version_or_hash: latest.0.to_string(), version_or_hash: latest.0.to_string(),
release_channel,
display: latest.1.to_string(), display: latest.1.to_string(),
}) })
} }
@ -1232,6 +1243,7 @@ cvbnfhuertt23523452345 v1.46.0-rc.1
release_channel: Rc::new(RefCell::new(ReleaseChannel::Stable)), release_channel: Rc::new(RefCell::new(ReleaseChannel::Stable)),
latest_version: Rc::new(RefCell::new(Ok(AvailableVersion { latest_version: Rc::new(RefCell::new(Ok(AvailableVersion {
version_or_hash: "".to_string(), version_or_hash: "".to_string(),
release_channel: ReleaseChannel::Stable,
display: "".to_string(), display: "".to_string(),
}))), }))),
time: Rc::new(RefCell::new(chrono::Utc::now())), time: Rc::new(RefCell::new(chrono::Utc::now())),
@ -1253,9 +1265,14 @@ cvbnfhuertt23523452345 v1.46.0-rc.1
*self.current_version.borrow_mut() = version.to_string(); *self.current_version.borrow_mut() = version.to_string();
} }
pub fn set_latest_version(&self, version: &str) { pub fn set_latest_version(
&self,
version: &str,
release_channel: ReleaseChannel,
) {
*self.latest_version.borrow_mut() = Ok(AvailableVersion { *self.latest_version.borrow_mut() = Ok(AvailableVersion {
version_or_hash: version.to_string(), version_or_hash: version.to_string(),
release_channel,
display: version.to_string(), display: version.to_string(),
}); });
} }
@ -1311,7 +1328,7 @@ cvbnfhuertt23523452345 v1.46.0-rc.1
async fn test_update_checker() { async fn test_update_checker() {
let env = TestUpdateCheckerEnvironment::new(); let env = TestUpdateCheckerEnvironment::new();
env.set_current_version("1.0.0"); env.set_current_version("1.0.0");
env.set_latest_version("1.1.0"); env.set_latest_version("1.1.0", ReleaseChannel::Stable);
let checker = UpdateChecker::new(env.clone(), env.clone()); let checker = UpdateChecker::new(env.clone(), env.clone());
// no version, so we should check, but not prompt // no version, so we should check, but not prompt
@ -1334,7 +1351,7 @@ cvbnfhuertt23523452345 v1.46.0-rc.1
// fast forward an hour and bump the latest version // fast forward an hour and bump the latest version
env.add_hours(1); env.add_hours(1);
env.set_latest_version("1.2.0"); env.set_latest_version("1.2.0", ReleaseChannel::Stable);
assert!(!checker.should_check_for_new_version()); assert!(!checker.should_check_for_new_version());
assert_eq!( assert_eq!(
checker.should_prompt(), checker.should_prompt(),
@ -1381,7 +1398,7 @@ cvbnfhuertt23523452345 v1.46.0-rc.1
// now try failing when fetching the latest version // now try failing when fetching the latest version
env.add_hours(UPGRADE_CHECK_INTERVAL + 1); env.add_hours(UPGRADE_CHECK_INTERVAL + 1);
env.set_latest_version_err("Failed"); env.set_latest_version_err("Failed");
env.set_latest_version("1.3.0"); env.set_latest_version("1.3.0", ReleaseChannel::Stable);
// this will silently fail // this will silently fail
fetch_and_store_latest_version(&env, &env).await; fetch_and_store_latest_version(&env, &env).await;
@ -1391,7 +1408,7 @@ cvbnfhuertt23523452345 v1.46.0-rc.1
// now switch to RC release // now switch to RC release
env.set_release_channel(ReleaseChannel::Rc); env.set_release_channel(ReleaseChannel::Rc);
env.set_current_version("1.46.0-rc.0"); env.set_current_version("1.46.0-rc.0");
env.set_latest_version("1.46.0-rc.1"); env.set_latest_version("1.46.0-rc.1", ReleaseChannel::Rc);
fetch_and_store_latest_version(&env, &env).await; fetch_and_store_latest_version(&env, &env).await;
env.add_hours(UPGRADE_CHECK_INTERVAL + 1); env.add_hours(UPGRADE_CHECK_INTERVAL + 1);
@ -1419,7 +1436,7 @@ cvbnfhuertt23523452345 v1.46.0-rc.1
.serialize(); .serialize();
env.write_check_file(&file_content); env.write_check_file(&file_content);
env.set_current_version("1.27.0"); env.set_current_version("1.27.0");
env.set_latest_version("1.26.2"); env.set_latest_version("1.26.2", ReleaseChannel::Stable);
let checker = UpdateChecker::new(env.clone(), env); let checker = UpdateChecker::new(env.clone(), env);
// since currently running version is newer than latest available (eg. CDN // since currently running version is newer than latest available (eg. CDN
@ -1554,6 +1571,7 @@ cvbnfhuertt23523452345 v1.46.0-rc.1
normalize_version_from_server(ReleaseChannel::Stable, "v1.0.0").unwrap(), normalize_version_from_server(ReleaseChannel::Stable, "v1.0.0").unwrap(),
AvailableVersion { AvailableVersion {
version_or_hash: "1.0.0".to_string(), version_or_hash: "1.0.0".to_string(),
release_channel: ReleaseChannel::Stable,
display: "1.0.0".to_string() display: "1.0.0".to_string()
}, },
); );
@ -1566,6 +1584,7 @@ cvbnfhuertt23523452345 v1.46.0-rc.1
.unwrap(), .unwrap(),
AvailableVersion { AvailableVersion {
version_or_hash: "1.0.0-test-v".to_string(), version_or_hash: "1.0.0-test-v".to_string(),
release_channel: ReleaseChannel::Stable,
display: "1.0.0-test-v".to_string() display: "1.0.0-test-v".to_string()
} }
); );
@ -1578,6 +1597,7 @@ cvbnfhuertt23523452345 v1.46.0-rc.1
.unwrap(), .unwrap(),
AvailableVersion { AvailableVersion {
version_or_hash: "v1452345asdf".to_string(), version_or_hash: "v1452345asdf".to_string(),
release_channel: ReleaseChannel::Canary,
display: "v1452345asdf".to_string() display: "v1452345asdf".to_string()
} }
); );
@ -1589,6 +1609,7 @@ cvbnfhuertt23523452345 v1.46.0-rc.1
.unwrap(), .unwrap(),
AvailableVersion { AvailableVersion {
version_or_hash: "asdfq345wdfasdfasdf".to_string(), version_or_hash: "asdfq345wdfasdfasdf".to_string(),
release_channel: ReleaseChannel::Rc,
display: "v1.46.0-rc.1".to_string(), display: "v1.46.0-rc.1".to_string(),
}, },
); );
@ -1598,7 +1619,7 @@ cvbnfhuertt23523452345 v1.46.0-rc.1
async fn test_upgrades_lsp() { async fn test_upgrades_lsp() {
let env = TestUpdateCheckerEnvironment::new(); let env = TestUpdateCheckerEnvironment::new();
env.set_current_version("1.0.0"); env.set_current_version("1.0.0");
env.set_latest_version("2.0.0"); env.set_latest_version("2.0.0", ReleaseChannel::Stable);
// greater // greater
{ {
@ -1615,7 +1636,7 @@ cvbnfhuertt23523452345 v1.46.0-rc.1
} }
// equal // equal
{ {
env.set_latest_version("1.0.0"); env.set_latest_version("1.0.0", ReleaseChannel::Stable);
let maybe_info = check_for_upgrades_for_lsp_with_provider(&env) let maybe_info = check_for_upgrades_for_lsp_with_provider(&env)
.await .await
.unwrap(); .unwrap();
@ -1623,7 +1644,7 @@ cvbnfhuertt23523452345 v1.46.0-rc.1
} }
// less // less
{ {
env.set_latest_version("0.9.0"); env.set_latest_version("0.9.0", ReleaseChannel::Stable);
let maybe_info = check_for_upgrades_for_lsp_with_provider(&env) let maybe_info = check_for_upgrades_for_lsp_with_provider(&env)
.await .await
.unwrap(); .unwrap();
@ -1632,7 +1653,7 @@ cvbnfhuertt23523452345 v1.46.0-rc.1
// canary equal // canary equal
{ {
env.set_current_version("123"); env.set_current_version("123");
env.set_latest_version("123"); env.set_latest_version("123", ReleaseChannel::Stable);
env.set_release_channel(ReleaseChannel::Canary); env.set_release_channel(ReleaseChannel::Canary);
let maybe_info = check_for_upgrades_for_lsp_with_provider(&env) let maybe_info = check_for_upgrades_for_lsp_with_provider(&env)
.await .await
@ -1641,7 +1662,7 @@ cvbnfhuertt23523452345 v1.46.0-rc.1
} }
// canary different // canary different
{ {
env.set_latest_version("1234"); env.set_latest_version("1234", ReleaseChannel::Stable);
let maybe_info = check_for_upgrades_for_lsp_with_provider(&env) let maybe_info = check_for_upgrades_for_lsp_with_provider(&env)
.await .await
.unwrap(); .unwrap();
@ -1657,7 +1678,7 @@ cvbnfhuertt23523452345 v1.46.0-rc.1
{ {
env.set_release_channel(ReleaseChannel::Rc); env.set_release_channel(ReleaseChannel::Rc);
env.set_current_version("1.2.3-rc.0"); env.set_current_version("1.2.3-rc.0");
env.set_latest_version("1.2.3-rc.0"); env.set_latest_version("1.2.3-rc.0", ReleaseChannel::Rc);
let maybe_info = check_for_upgrades_for_lsp_with_provider(&env) let maybe_info = check_for_upgrades_for_lsp_with_provider(&env)
.await .await
.unwrap(); .unwrap();
@ -1665,8 +1686,8 @@ cvbnfhuertt23523452345 v1.46.0-rc.1
} }
// canary different // canary different
{ {
env.set_latest_version("1.2.3-rc.0"); env.set_latest_version("1.2.3-rc.0", ReleaseChannel::Rc);
env.set_latest_version("1.2.3-rc.1"); env.set_latest_version("1.2.3-rc.1", ReleaseChannel::Rc);
let maybe_info = check_for_upgrades_for_lsp_with_provider(&env) let maybe_info = check_for_upgrades_for_lsp_with_provider(&env)
.await .await
.unwrap(); .unwrap();