Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[package]
name = "deno"
version = "1.45.5"
version = "2.0.0-rc.0"
authors.workspace = true
default-run = "deno"
edition.workspace = true
Expand Down
39 changes: 39 additions & 0 deletions cli/args/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ pub struct TestFlags {
pub struct UpgradeFlags {
pub dry_run: bool,
pub force: bool,
pub release_candidate: bool,
pub canary: bool,
pub version: Option<String>,
pub output: Option<String>,
Expand Down Expand Up @@ -2845,6 +2846,13 @@ update to a different location, use the --output flag
.help("Upgrade to canary builds")
.action(ArgAction::SetTrue),
)
.arg(
Arg::new("release_candidate")
.long("rc")
.help("Upgrade to Deno 2 release candidate")
.conflicts_with_all(["canary", "version"])
.action(ArgAction::SetTrue),
)
.arg(ca_file_arg())
})
}
Expand Down Expand Up @@ -4572,11 +4580,13 @@ fn upgrade_parse(flags: &mut Flags, matches: &mut ArgMatches) {
let dry_run = matches.get_flag("dry-run");
let force = matches.get_flag("force");
let canary = matches.get_flag("canary");
let release_candidate = matches.get_flag("release_candidate");
let version = matches.remove_one::<String>("version");
let output = matches.remove_one::<String>("output");
flags.subcommand = DenoSubcommand::Upgrade(UpgradeFlags {
dry_run,
force,
release_candidate,
canary,
version,
output,
Expand Down Expand Up @@ -5063,6 +5073,7 @@ mod tests {
force: true,
dry_run: true,
canary: false,
release_candidate: false,
version: None,
output: None,
}),
Expand All @@ -5081,6 +5092,7 @@ mod tests {
force: false,
dry_run: false,
canary: false,
release_candidate: false,
version: None,
output: Some(String::from("example.txt")),
}),
Expand Down Expand Up @@ -8935,13 +8947,40 @@ mod tests {
force: false,
dry_run: false,
canary: false,
release_candidate: false,
version: None,
output: None,
}),
ca_data: Some(CaData::File("example.crt".to_owned())),
..Flags::default()
}
);
}

#[test]
fn upgrade_release_candidate() {
let r = flags_from_vec(svec!["deno", "upgrade", "--rc"]);
assert_eq!(
r.unwrap(),
Flags {
subcommand: DenoSubcommand::Upgrade(UpgradeFlags {
force: false,
dry_run: false,
canary: false,
release_candidate: true,
version: None,
output: None,
}),
ca_data: Some(CaData::File("example.crt".to_owned())),
..Flags::default()
}
);

let r = flags_from_vec(svec!["deno", "upgrade", "--rc", "--canary"]);
assert!(r.is_err());

let r = flags_from_vec(svec!["deno", "upgrade", "--rc", "--version"]);
assert!(r.is_err());
}

#[test]
Expand Down
59 changes: 57 additions & 2 deletions cli/tools/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,15 @@ enum UpgradeCheckKind {
#[async_trait(?Send)]
trait VersionProvider: Clone {
fn is_canary(&self) -> bool;
fn is_release_candidate(&self) -> bool;
async fn latest_version(&self) -> Result<String, AnyError>;
fn current_version(&self) -> Cow<str>;

fn release_kind(&self) -> UpgradeReleaseKind {
if self.is_canary() {
UpgradeReleaseKind::Canary
} else if self.is_release_candidate() {
UpgradeReleaseKind::ReleaseCandidate
} else {
UpgradeReleaseKind::Stable
}
Expand All @@ -120,6 +123,10 @@ impl RealVersionProvider {

#[async_trait(?Send)]
impl VersionProvider for RealVersionProvider {
fn is_release_candidate(&self) -> bool {
version::is_release_candidate()
}

fn is_canary(&self) -> bool {
version::is_canary()
}
Expand Down Expand Up @@ -449,6 +456,9 @@ pub async fn upgrade(
let release_kind = if upgrade_flags.canary {
log::info!("Looking up latest canary version");
UpgradeReleaseKind::Canary
} else if upgrade_flags.release_candidate {
log::info!("Looking up latest release candidate version");
UpgradeReleaseKind::ReleaseCandidate
} else {
log::info!("Looking up latest version");
UpgradeReleaseKind::Stable
Expand Down Expand Up @@ -568,6 +578,7 @@ pub async fn upgrade(
enum UpgradeReleaseKind {
Stable,
Canary,
ReleaseCandidate,
}

async fn get_latest_version(
Expand All @@ -588,6 +599,7 @@ fn normalize_version_from_server(
match release_kind {
UpgradeReleaseKind::Stable => text.trim_start_matches('v').to_string(),
UpgradeReleaseKind::Canary => text.to_string(),
UpgradeReleaseKind::ReleaseCandidate => todo!(),
}
}

Expand All @@ -601,6 +613,7 @@ fn get_url(
UpgradeReleaseKind::Canary => {
Cow::Owned(format!("canary-{target_tuple}-latest.txt"))
}
UpgradeReleaseKind::ReleaseCandidate => Cow::Borrowed("release-2-rc.txt"),
};
let query_param = match check_kind {
UpgradeCheckKind::Execution => "",
Expand Down Expand Up @@ -782,6 +795,7 @@ mod test {
struct TestUpdateCheckerEnvironment {
file_text: Rc<RefCell<String>>,
is_canary: Rc<RefCell<bool>>,
is_release_candidate: Rc<RefCell<bool>>,
current_version: Rc<RefCell<String>>,
latest_version: Rc<RefCell<Result<String, String>>>,
time: Rc<RefCell<chrono::DateTime<chrono::Utc>>>,
Expand All @@ -793,6 +807,7 @@ mod test {
file_text: Default::default(),
current_version: Default::default(),
is_canary: Default::default(),
is_release_candidate: Default::default(),
latest_version: Rc::new(RefCell::new(Ok("".to_string()))),
time: Rc::new(RefCell::new(chrono::Utc::now())),
}
Expand Down Expand Up @@ -824,10 +839,18 @@ mod test {
pub fn set_is_canary(&self, is_canary: bool) {
*self.is_canary.borrow_mut() = is_canary;
}

pub fn set_is_release_candidate(&self, is_release_candidate: bool) {
*self.is_release_candidate.borrow_mut() = is_release_candidate;
}
}

#[async_trait(?Send)]
impl VersionProvider for TestUpdateCheckerEnvironment {
fn is_release_candidate(&self) -> bool {
*self.is_release_candidate.borrow()
}

fn is_canary(&self) -> bool {
*self.is_canary.borrow()
}
Expand Down Expand Up @@ -1026,11 +1049,43 @@ mod test {
);
assert_eq!(
get_url(
UpgradeReleaseKind::Stable,
UpgradeReleaseKind::ReleaseCandidate,
"x86_64-pc-windows-msvc",
UpgradeCheckKind::Lsp
),
"https://dl.deno.land/release-latest.txt?lsp"
"https://dl.deno.land/release-2-rc.txt?lsp"
);
assert_eq!(
get_url(
UpgradeReleaseKind::ReleaseCandidate,
"aarch64-apple-darwin",
UpgradeCheckKind::Execution
),
"https://dl.deno.land/release-2-rc.txt"
);
assert_eq!(
get_url(
UpgradeReleaseKind::ReleaseCandidate,
"aarch64-apple-darwin",
UpgradeCheckKind::Lsp
),
"https://dl.deno.land/release-2-rc.txt?lsp"
);
assert_eq!(
get_url(
UpgradeReleaseKind::ReleaseCandidate,
"x86_64-pc-windows-msvc",
UpgradeCheckKind::Execution
),
"https://dl.deno.land/release-2-rc.txt"
);
assert_eq!(
get_url(
UpgradeReleaseKind::ReleaseCandidate,
"x86_64-pc-windows-msvc",
UpgradeCheckKind::Lsp
),
"https://dl.deno.land/release-2-rc.txt?lsp"
);
}

Expand Down
Loading