mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 07:14:47 -05:00
refactor: show release channel in deno --version
(#25061)
Also simplifies handling of various release channels in `deno upgrade` subcommand.
This commit is contained in:
parent
ff4226a3cd
commit
db75462bd6
4 changed files with 30 additions and 181 deletions
|
@ -36,7 +36,6 @@ use std::path::PathBuf;
|
|||
use std::str::FromStr;
|
||||
|
||||
use crate::args::resolve_no_prompt;
|
||||
use crate::shared::ReleaseChannel;
|
||||
use crate::util::fs::canonicalize_path;
|
||||
|
||||
use super::flags_net;
|
||||
|
@ -1333,27 +1332,10 @@ static UNSTABLE_HEADING: &str = "Unstable";
|
|||
|
||||
pub fn clap_root() -> Command {
|
||||
let long_version = format!(
|
||||
"{} ({}, {})\nv8 {}\ntypescript {}",
|
||||
"{} ({}, {}, {})\nv8 {}\ntypescript {}",
|
||||
crate::version::DENO_VERSION_INFO.deno,
|
||||
// TODO(bartlomieju): alter what's printed here.
|
||||
// I think it's best if we print as follows:
|
||||
// <version>(+<short_git_hash>) (<release_channel>, <profile>, <target>)
|
||||
// For stable it would be:
|
||||
// v1.46.0 (stable, release, aarch64-apple-darwin)
|
||||
// For rc it would be:
|
||||
// v1.46.0-rc.2 (release candidate, release, aarch64-apple-darwin)
|
||||
// For lts it would be:
|
||||
// v2.1.13-lts (LTS (long term support), release, aarch64-apple-darwin)
|
||||
// For canary it would be:
|
||||
// v1.46.0+25bb59d (canary, release, aarch64-apple-darwin)
|
||||
if matches!(
|
||||
crate::version::DENO_VERSION_INFO.release_channel,
|
||||
ReleaseChannel::Canary
|
||||
) {
|
||||
"canary"
|
||||
} else {
|
||||
env!("PROFILE")
|
||||
},
|
||||
crate::version::DENO_VERSION_INFO.release_channel.name(),
|
||||
env!("PROFILE"),
|
||||
env!("TARGET"),
|
||||
deno_core::v8_version(),
|
||||
crate::version::DENO_VERSION_INFO.typescript
|
||||
|
|
|
@ -16,17 +16,17 @@ pub enum ReleaseChannel {
|
|||
#[allow(unused)]
|
||||
Lts,
|
||||
|
||||
/// Release candidate, poiting to a git hash
|
||||
/// Release candidate, eg. 1.46.0-rc.0, 2.0.0-rc.1
|
||||
Rc,
|
||||
}
|
||||
|
||||
impl ReleaseChannel {
|
||||
pub fn name(&self) -> &str {
|
||||
match self {
|
||||
Self::Stable => "latest",
|
||||
Self::Stable => "stable",
|
||||
Self::Canary => "canary",
|
||||
Self::Rc => "release candidate",
|
||||
Self::Lts => "LTS (long term support)",
|
||||
Self::Lts => "long term support",
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -101,10 +101,7 @@ trait VersionProvider: Clone {
|
|||
/// and "lts" versions use semver.
|
||||
fn current_version(&self) -> Cow<str>;
|
||||
|
||||
// TODO(bartlomieju): update to handle `Lts` channel
|
||||
async fn get_current_exe_release_channel(
|
||||
&self,
|
||||
) -> Result<ReleaseChannel, AnyError>;
|
||||
fn get_current_exe_release_channel(&self) -> ReleaseChannel;
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
|
@ -143,36 +140,8 @@ impl VersionProvider for RealVersionProvider {
|
|||
Cow::Borrowed(version::DENO_VERSION_INFO.version_or_git_hash())
|
||||
}
|
||||
|
||||
// TODO(bartlomieju): update to handle `Lts` channel
|
||||
async fn get_current_exe_release_channel(
|
||||
&self,
|
||||
) -> Result<ReleaseChannel, AnyError> {
|
||||
// TODO(bartlomieju): remove hitting a remote server
|
||||
if matches!(
|
||||
version::DENO_VERSION_INFO.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(
|
||||
&self.http_client_provider.get_or_create()?,
|
||||
self.check_kind,
|
||||
)
|
||||
.await
|
||||
.unwrap_or_else(|_| vec![]);
|
||||
|
||||
let is_current_exe_an_rc = rc_versions
|
||||
.iter()
|
||||
.any(|(hash, _)| hash == version::DENO_VERSION_INFO.git_hash);
|
||||
|
||||
if is_current_exe_an_rc {
|
||||
Ok(ReleaseChannel::Rc)
|
||||
} else {
|
||||
Ok(ReleaseChannel::Canary)
|
||||
}
|
||||
} else {
|
||||
Ok(ReleaseChannel::Stable)
|
||||
}
|
||||
fn get_current_exe_release_channel(&self) -> ReleaseChannel {
|
||||
version::DENO_VERSION_INFO.release_channel
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -389,8 +358,7 @@ pub async fn check_for_upgrades_for_lsp(
|
|||
async fn check_for_upgrades_for_lsp_with_provider(
|
||||
version_provider: &impl VersionProvider,
|
||||
) -> Result<Option<LspVersionUpgradeInfo>, AnyError> {
|
||||
let release_channel =
|
||||
version_provider.get_current_exe_release_channel().await?;
|
||||
let release_channel = version_provider.get_current_exe_release_channel();
|
||||
let latest_version = version_provider.latest_version(release_channel).await?;
|
||||
let current_version = version_provider.current_version();
|
||||
|
||||
|
@ -400,7 +368,7 @@ async fn check_for_upgrades_for_lsp_with_provider(
|
|||
}
|
||||
|
||||
match release_channel {
|
||||
ReleaseChannel::Stable => {
|
||||
ReleaseChannel::Stable | ReleaseChannel::Rc => {
|
||||
if let Ok(current) = Version::parse_standard(¤t_version) {
|
||||
if let Ok(latest) =
|
||||
Version::parse_standard(&latest_version.version_or_hash)
|
||||
|
@ -421,11 +389,6 @@ async fn check_for_upgrades_for_lsp_with_provider(
|
|||
is_canary: true,
|
||||
})),
|
||||
|
||||
ReleaseChannel::Rc => Ok(Some(LspVersionUpgradeInfo {
|
||||
latest_version: latest_version.display,
|
||||
is_canary: true,
|
||||
})),
|
||||
|
||||
// TODO(bartlomieju)
|
||||
ReleaseChannel::Lts => unreachable!(),
|
||||
}
|
||||
|
@ -438,12 +401,7 @@ async fn fetch_and_store_latest_version<
|
|||
env: &TEnvironment,
|
||||
version_provider: &TVersionProvider,
|
||||
) {
|
||||
// Fetch latest version or commit hash from server.
|
||||
let Ok(release_channel) =
|
||||
version_provider.get_current_exe_release_channel().await
|
||||
else {
|
||||
return;
|
||||
};
|
||||
let release_channel = version_provider.get_current_exe_release_channel();
|
||||
let Ok(latest_version) =
|
||||
version_provider.latest_version(release_channel).await
|
||||
else {
|
||||
|
@ -644,10 +602,9 @@ fn select_specific_version_for_upgrade(
|
|||
) -> Result<Option<AvailableVersion>, AnyError> {
|
||||
match release_channel {
|
||||
ReleaseChannel::Stable => {
|
||||
let current_is_passed = if !matches!(
|
||||
version::DENO_VERSION_INFO.release_channel,
|
||||
ReleaseChannel::Canary
|
||||
) {
|
||||
let current_is_passed = if version::DENO_VERSION_INFO.release_channel
|
||||
!= ReleaseChannel::Canary
|
||||
{
|
||||
version::DENO_VERSION_INFO.deno == version
|
||||
} else {
|
||||
false
|
||||
|
@ -708,10 +665,9 @@ async fn find_latest_version_to_upgrade(
|
|||
let (maybe_newer_latest_version, current_version) = match release_channel {
|
||||
ReleaseChannel::Stable => {
|
||||
let current_version = version::DENO_VERSION_INFO.deno;
|
||||
let current_is_most_recent = if !matches!(
|
||||
version::DENO_VERSION_INFO.release_channel,
|
||||
ReleaseChannel::Canary
|
||||
) {
|
||||
let current_is_most_recent = if version::DENO_VERSION_INFO.release_channel
|
||||
!= ReleaseChannel::Canary
|
||||
{
|
||||
let current = Version::parse_standard(current_version).unwrap();
|
||||
let latest =
|
||||
Version::parse_standard(&latest_version_found.version_or_hash)
|
||||
|
@ -771,46 +727,11 @@ async fn find_latest_version_to_upgrade(
|
|||
Ok(maybe_newer_latest_version)
|
||||
}
|
||||
|
||||
// Return a list of available RC release in format of (<commit_hash>, <version_name>)
|
||||
fn parse_rc_versions_text(
|
||||
text: &str,
|
||||
) -> Result<Vec<(String, String)>, AnyError> {
|
||||
let lines: Vec<_> = text
|
||||
.split("\n")
|
||||
.map(|s| s.to_string())
|
||||
.filter(|s| !s.is_empty())
|
||||
.collect();
|
||||
if lines.is_empty() {
|
||||
bail!("No release candidates available");
|
||||
}
|
||||
|
||||
let mut parsed = Vec::with_capacity(lines.len());
|
||||
|
||||
for line in lines {
|
||||
let v = line.split(' ').collect::<Vec<_>>();
|
||||
if v.len() != 2 {
|
||||
bail!("Malformed list of RC releases");
|
||||
}
|
||||
parsed.push((v[0].to_string(), v[1].to_string()));
|
||||
}
|
||||
|
||||
Ok(parsed)
|
||||
}
|
||||
|
||||
async fn get_rc_versions(
|
||||
client: &HttpClient,
|
||||
check_kind: UpgradeCheckKind,
|
||||
) -> Result<Vec<(String, String)>, AnyError> {
|
||||
let url =
|
||||
get_latest_version_url(ReleaseChannel::Rc, env!("TARGET"), check_kind);
|
||||
let text = client.download_text(url.parse()?).await?;
|
||||
parse_rc_versions_text(&text)
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
struct AvailableVersion {
|
||||
version_or_hash: String,
|
||||
release_channel: ReleaseChannel,
|
||||
// TODO(bartlomieju): remove this one
|
||||
display: String,
|
||||
}
|
||||
|
||||
|
@ -842,7 +763,7 @@ fn normalize_version_from_server(
|
|||
) -> Result<AvailableVersion, AnyError> {
|
||||
let text = text.trim();
|
||||
match release_channel {
|
||||
ReleaseChannel::Stable => {
|
||||
ReleaseChannel::Stable | ReleaseChannel::Rc | ReleaseChannel::Lts => {
|
||||
let v = text.trim_start_matches('v').to_string();
|
||||
Ok(AvailableVersion {
|
||||
version_or_hash: v.to_string(),
|
||||
|
@ -855,16 +776,6 @@ fn normalize_version_from_server(
|
|||
release_channel,
|
||||
display: text.to_string(),
|
||||
}),
|
||||
ReleaseChannel::Rc => {
|
||||
let lines = parse_rc_versions_text(text)?;
|
||||
let latest = lines.last().unwrap();
|
||||
Ok(AvailableVersion {
|
||||
version_or_hash: latest.0.to_string(),
|
||||
release_channel,
|
||||
display: latest.1.to_string(),
|
||||
})
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1126,43 +1037,6 @@ mod test {
|
|||
assert!(result.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_rc_versions_text() {
|
||||
let rc_versions = parse_rc_versions_text(
|
||||
r#"qwerw3452gbxcvbarwett234 v1.46.0-rc.0
|
||||
cvbnfhuertt23523452345 v1.46.0-rc.1
|
||||
sdfq3452345egasdfgsdgf v2.0.0-rc.0
|
||||
asdf456yegfncbvjwe4523 v2.0.0-rc.1
|
||||
hjr6562w34rgzcvh56734a v2.0.0-rc.2
|
||||
bdfgtd6wergsdg3243234v v2.0.0-rc.3
|
||||
"#,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(rc_versions.len(), 6);
|
||||
assert_eq!(rc_versions[3].0, "asdf456yegfncbvjwe4523");
|
||||
assert_eq!(rc_versions[3].1, "v2.0.0-rc.1");
|
||||
|
||||
let rc_versions = parse_rc_versions_text(
|
||||
r#"qwerw3452gbxcvbarwett234 v1.46.0-rc.0
|
||||
|
||||
cvbnfhuertt23523452345 v1.46.0-rc.1
|
||||
"#,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(rc_versions.len(), 2);
|
||||
assert_eq!(rc_versions[1].0, "cvbnfhuertt23523452345");
|
||||
assert_eq!(rc_versions[1].1, "v1.46.0-rc.1");
|
||||
|
||||
let err =
|
||||
parse_rc_versions_text(r#"qwerw3452gbxcvbarwett234 v1.46.0-rc.0"#)
|
||||
.unwrap_err();
|
||||
assert_eq!(err.to_string(), "Malformed list of RC releases");
|
||||
let err = parse_rc_versions_text("").unwrap_err();
|
||||
assert_eq!(err.to_string(), "No release candidates available");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_serialize_upgrade_check_file() {
|
||||
let mut file = CheckVersionFile {
|
||||
|
@ -1276,10 +1150,8 @@ cvbnfhuertt23523452345 v1.46.0-rc.1
|
|||
Cow::Owned(self.current_version.borrow().clone())
|
||||
}
|
||||
|
||||
async fn get_current_exe_release_channel(
|
||||
&self,
|
||||
) -> Result<ReleaseChannel, AnyError> {
|
||||
Ok(*self.release_channel.borrow())
|
||||
fn get_current_exe_release_channel(&self) -> ReleaseChannel {
|
||||
*self.release_channel.borrow()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1575,15 +1447,12 @@ cvbnfhuertt23523452345 v1.46.0-rc.1
|
|||
}
|
||||
);
|
||||
assert_eq!(
|
||||
normalize_version_from_server(
|
||||
ReleaseChannel::Rc,
|
||||
"asdfq345wdfasdfasdf v1.46.0-rc.0\nasdfq345wdfasdfasdf v1.46.0-rc.1\n"
|
||||
)
|
||||
.unwrap(),
|
||||
normalize_version_from_server(ReleaseChannel::Rc, "v1.46.0-rc.0\n\n")
|
||||
.unwrap(),
|
||||
AvailableVersion {
|
||||
version_or_hash: "asdfq345wdfasdfasdf".to_string(),
|
||||
version_or_hash: "1.46.0-rc.0".to_string(),
|
||||
release_channel: ReleaseChannel::Rc,
|
||||
display: "v1.46.0-rc.1".to_string(),
|
||||
display: "1.46.0-rc.0".to_string(),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
@ -1668,7 +1537,7 @@ cvbnfhuertt23523452345 v1.46.0-rc.1
|
|||
maybe_info,
|
||||
Some(LspVersionUpgradeInfo {
|
||||
latest_version: "1.2.3-rc.1".to_string(),
|
||||
is_canary: true,
|
||||
is_canary: false,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
|
|
@ -23,8 +23,7 @@ pub static DENO_VERSION_INFO: Lazy<DenoVersionInfo> = Lazy::new(|| {
|
|||
});
|
||||
|
||||
DenoVersionInfo {
|
||||
// TODO(bartlomieju): fix further for RC and LTS releases
|
||||
deno: if IS_CANARY {
|
||||
deno: if release_channel == ReleaseChannel::Canary {
|
||||
concat!(
|
||||
env!("CARGO_PKG_VERSION"),
|
||||
"+",
|
||||
|
@ -39,8 +38,7 @@ pub static DENO_VERSION_INFO: Lazy<DenoVersionInfo> = Lazy::new(|| {
|
|||
git_hash: GIT_COMMIT_HASH,
|
||||
|
||||
// Keep in sync with `deno` field.
|
||||
// TODO(bartlomieju): fix further for RC and LTS releases
|
||||
user_agent: if IS_CANARY {
|
||||
user_agent: if release_channel == ReleaseChannel::Canary {
|
||||
concat!(
|
||||
"Deno/",
|
||||
env!("CARGO_PKG_VERSION"),
|
||||
|
@ -77,7 +75,7 @@ impl DenoVersionInfo {
|
|||
/// For stable release, a semver like, eg. `v1.46.2`.
|
||||
/// For canary release a full git hash, eg. `9bdab6fb6b93eb43b1930f40987fa4997287f9c8`.
|
||||
pub fn version_or_git_hash(&self) -> &'static str {
|
||||
if IS_CANARY {
|
||||
if self.release_channel == ReleaseChannel::Canary {
|
||||
self.git_hash
|
||||
} else {
|
||||
CARGO_PKG_VERSION
|
||||
|
|
Loading…
Reference in a new issue