Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support PR Channels #980

Merged
merged 5 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ indoc = "2.0.3"
is-terminal = "0.4.9"
path-absolutize = "3.1.0"
human-sort = "0.2.2"
regex = "1.10.5"

[target.'cfg(windows)'.dependencies]
windows = { version = "0.57.0", features = ["Win32_Foundation", "Win32_UI_Shell", "Win32_System_Console", "Services_Store", "Foundation", "Foundation_Collections", "Web_Http", "Web_Http_Headers", "Storage_Streams",] }
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The installer also bundles a full Julia version manager called `juliaup`. One ca

## Status

This installer is considered production ready.
This installer is considered production ready.

## Installation

Expand Down Expand Up @@ -130,6 +130,7 @@ The available system provided channels are:
- `beta`: always points to the latest beta version if one exists. If a newer release candidate exists, it will point to that, and if there is neither a beta or rc candidate available it will point to the same version as the `release` channel.
- `rc`: same as `beta`, but only starts with release candidate versions.
- `nightly`: always points to the latest build from the `master` branch in the Julia repository.
- `pr{number}` (e.g. `pr123`): points to the latest successful build of a PR branch (https://github.com/JuliaLang/julia/pull/{number}). Only available if CI has recently and successfully built Julia on that branch.
- specific versions, e.g. `1.5.4`.
- minor version channels, e.g. `1.5`.
- major version channels, e.g. `1`.
Expand Down
19 changes: 13 additions & 6 deletions src/command_add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@ use crate::config_file::{load_mut_config_db, save_config_db, JuliaupConfigChanne
use crate::global_paths::GlobalPaths;
#[cfg(not(windows))]
use crate::operations::create_symlink;
use crate::operations::{identify_nightly, install_nightly, install_version, update_version_db};
use crate::operations::{
channel_to_name, install_non_db_version, install_version, update_version_db,
};
use crate::versions_file::load_versions_db;
use anyhow::{anyhow, Context, Result};
use regex::Regex;

pub fn run_command_add(channel: &str, paths: &GlobalPaths) -> Result<()> {
if channel == "nightly" || channel.starts_with("nightly~") {
return add_nightly(channel, paths);
// This regex is dynamically compiled, but its runtime is negligible compared to downloading Julia
if Regex::new(r"^(pr\d+|nightly)(~|$)")
.unwrap()
.is_match(channel)
{
return add_non_db(channel, paths);
}

update_version_db(paths).with_context(|| "Failed to update versions db.")?;
Expand Down Expand Up @@ -71,7 +78,7 @@ pub fn run_command_add(channel: &str, paths: &GlobalPaths) -> Result<()> {
Ok(())
}

fn add_nightly(channel: &str, paths: &GlobalPaths) -> Result<()> {
fn add_non_db(channel: &str, paths: &GlobalPaths) -> Result<()> {
let mut config_file = load_mut_config_db(paths)
.with_context(|| "`add` command failed to load configuration data.")?;

Expand All @@ -80,8 +87,8 @@ fn add_nightly(channel: &str, paths: &GlobalPaths) -> Result<()> {
return Ok(());
}

let name = identify_nightly(&channel.to_string())?;
let config_channel = install_nightly(channel, &name, paths)?;
let name = channel_to_name(&channel.to_string())?;
let config_channel = install_non_db_version(channel, &name, paths)?;

config_file
.data
Expand Down
15 changes: 8 additions & 7 deletions src/command_list.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::operations::{compatible_nightly_archs, identify_nightly};
use crate::operations::{channel_to_name, compatible_archs};
use crate::{global_paths::GlobalPaths, versions_file::load_versions_db};
use anyhow::{Context, Result};
use cli_table::{
Expand All @@ -20,20 +20,21 @@ pub fn run_command_list(paths: &GlobalPaths) -> Result<()> {
let versiondb_data =
load_versions_db(paths).with_context(|| "`list` command failed to load versions db.")?;

let nightly_channels: Vec<String> = std::iter::once("nightly".to_string())
let non_db_channels: Vec<String> = std::iter::once("nightly".to_string())
.chain(
compatible_nightly_archs()?
compatible_archs()?
.into_iter()
.map(|arch| format!("nightly~{}", arch)),
)
.chain(std::iter::once("pr{number}".to_string()))
.collect();
let nightly_rows: Vec<ChannelRow> = nightly_channels
let non_db_rows: Vec<ChannelRow> = non_db_channels
.into_iter()
.map(|channel| {
let nightly_name = identify_nightly(&channel).expect("Failed to identify nightly");
let name = channel_to_name(&channel).expect("Failed to identify version");
ChannelRow {
name: channel,
version: nightly_name,
version: name,
}
})
.collect();
Expand All @@ -48,7 +49,7 @@ pub fn run_command_list(paths: &GlobalPaths) -> Result<()> {
}
})
.sorted_by(|a, b| compare(&a.name, &b.name))
.chain(nightly_rows)
.chain(non_db_rows)
.collect();

print_stdout(
Expand Down
122 changes: 77 additions & 45 deletions src/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ pub fn download_extract_sans_parent(
.progress_chars("=> "),
);

let last_modified = response
let last_modified = match response
.headers()
.get("etag")
.unwrap()
.to_str()
.unwrap()
.to_string();
.get("etag") {
Some(etag) => Ok(etag.to_str().unwrap().to_string()),
None => Err(anyhow!(format!("Failed to get etag from `{}`.\n\
This is likely due to requesting a pull request that does not have a cached build available. You may have to build locally.", url))),
}?;

let response_with_pb = pb.wrap_read(response);

Expand Down Expand Up @@ -354,8 +354,8 @@ pub fn install_version(
Ok(())
}

// which nightly arch to default to when simply using the `nightly` channel
pub fn default_nightly_arch() -> Result<String> {
// which arch to default to when simply using the `nightly` or `pr00000` channel
pub fn default_arch() -> Result<String> {
if cfg!(target_arch = "aarch64") {
Ok("aarch64".to_string())
} else if cfg!(target_arch = "x86_64") {
Expand All @@ -367,8 +367,8 @@ pub fn default_nightly_arch() -> Result<String> {
}
}

// which nightly archs are compatible with the current system, for `juliaup list` purposes
pub fn compatible_nightly_archs() -> Result<Vec<String>> {
// which archs are compatible with the current system, for `juliaup list` purposes
pub fn compatible_archs() -> Result<Vec<String>> {
if cfg!(target_os = "macos") {
if cfg!(target_arch = "x86_64") {
Ok(vec!["x64".to_string()])
Expand All @@ -391,49 +391,53 @@ pub fn compatible_nightly_archs() -> Result<Vec<String>> {
}

// Identify the unversioned name of a nightly (e.g., `latest-macos-x86_64`) for a channel
pub fn identify_nightly(channel: &String) -> Result<String> {
let arch = if channel == "nightly" {
default_nightly_arch()?
} else {
let parts: Vec<&str> = channel.splitn(2, '~').collect();
if parts.len() != 2 {
bail!("Invalid nightly channel name '{}'.", channel)
}
parts[1].to_string()
pub fn channel_to_name(channel: &String) -> Result<String> {
let mut parts = channel.splitn(2, '~');

let channel = parts.next().expect("Failed to parse channel name.");

let version = match channel {
"nightly" => "latest",
other => other,
};

let name = {
let arch = match parts.next() {
Some(arch) => arch.to_string(),
None => default_arch()?,
};

let os_arch_suffix = {
#[cfg(target_os = "macos")]
if arch == "x64" {
"latest-macos-x86_64"
"macos-x86_64"
} else if arch == "aarch64" {
"latest-macos-aarch64"
"macos-aarch64"
} else {
bail!("Unsupported architecture for nightly channel on macOS.")
}

#[cfg(target_os = "windows")]
if arch == "x64" {
"latest-win64"
"win64"
} else if arch == "x86" {
"latest-win32"
"win32"
} else {
bail!("Unsupported architecture for nightly channel on Windows.")
}

#[cfg(target_os = "linux")]
if arch == "x64" {
"latest-linux-x86_64"
"linux-x86_64"
} else if arch == "x86" {
"latest-linux-i686"
"linux-i686"
} else if arch == "aarch64" {
"latest-linux-aarch64"
"linux-aarch64"
} else {
bail!("Unsupported architecture for nightly channel on Linux.")
}
};

Ok(name.to_string())
Ok(version.to_string() + "-" + os_arch_suffix)
}

pub fn install_from_url(
Expand All @@ -453,7 +457,7 @@ pub fn install_from_url(
Ok(last_updated) => last_updated,
Err(e) => {
std::fs::remove_dir_all(temp_dir.into_path())?;
bail!("Failed to download and extract nightly: {}", e);
bail!("Failed to download and extract pr or nightly: {}", e);
}
};

Expand Down Expand Up @@ -491,29 +495,57 @@ pub fn install_from_url(
})
}

pub fn install_nightly(
pub fn install_non_db_version(
channel: &str,
name: &String,
paths: &GlobalPaths,
) -> Result<crate::config_file::JuliaupConfigChannel> {
// Determine the download URL
let download_url_base = get_julianightlies_base_url()?;
let download_url_path = match name.as_str() {
"latest-macos-x86_64" => Ok("bin/macos/x86_64/julia-latest-macos-x86_64.tar.gz"),
"latest-macos-aarch64" => Ok("bin/macos/aarch64/julia-latest-macos-aarch64.tar.gz"),
"latest-win64" => Ok("bin/winnt/x64/julia-latest-win64.tar.gz"),
"latest-win32" => Ok("bin/winnt/x86/julia-latest-win32.tar.gz"),
"latest-linux-x86_64" => Ok("bin/linux/x86_64/julia-latest-linux-x86_64.tar.gz"),
"latest-linux-i686" => Ok("bin/linux/i686/julia-latest-linux-i686.tar.gz"),
"latest-linux-aarch64" => Ok("bin/linux/aarch64/julia-latest-linux-aarch64.tar.gz"),
_ => Err(anyhow!("Unknown nightly.")),
let mut parts = name.splitn(2, '-');
let id = parts.next().expect("Failed to parse channel name.");
let arch = parts.next().expect("Failed to parse channel name.");
let download_url_path = if id == "latest" {
match arch {
"macos-x86_64" => Ok("bin/macos/x86_64/julia-latest-macos-x86_64.tar.gz".to_owned()),
"macos-aarch64" => Ok("bin/macos/aarch64/julia-latest-macos-aarch64.tar.gz".to_owned()),
"win64" => Ok("bin/winnt/x64/julia-latest-win64.tar.gz".to_owned()),
"win32" => Ok("bin/winnt/x86/julia-latest-win32.tar.gz".to_owned()),
"linux-x86_64" => Ok("bin/linux/x86_64/julia-latest-linux-x86_64.tar.gz".to_owned()),
"linux-i686" => Ok("bin/linux/i686/julia-latest-linux-i686.tar.gz".to_owned()),
"linux-aarch64" => Ok("bin/linux/aarch64/julia-latest-linux-aarch64.tar.gz".to_owned()),
_ => Err(anyhow!("Unknown nightly.")),
}
} else if id.starts_with("pr") {
match arch {
// https://github.com/JuliaLang/juliaup/issues/903#issuecomment-2183206994
"macos-x86_64" => {
Ok("bin/macos/x86_64/julia-".to_owned() + id + "-macos-x86_64.tar.gz")
}
"macos-aarch64" => {
Ok("bin/macos/aarch64/julia-".to_owned() + id + "-macos-aarch64.tar.gz")
}
"win64" => Ok("bin/windows/x86_64/julia-".to_owned() + id + "-windows-x86_64.tar.gz"),
"linux-x86_64" => {
Ok("bin/linux/x86_64/julia-".to_owned() + id + "-linux-x86_64.tar.gz")
}
"linux-aarch64" => {
Ok("bin/linux/aarch64/julia-".to_owned() + id + "-linux-aarch64.tar.gz")
}
_ => Err(anyhow!("Unknown pr.")),
}
} else {
Err(anyhow!("Unknown non-db channel."))
}?;
let download_url = download_url_base.join(download_url_path).with_context(|| {
format!(
"Failed to construct a valid url from '{}' and '{}'.",
download_url_base, download_url_path
)
})?;

let download_url = download_url_base
.join(download_url_path.as_str())
.with_context(|| {
format!(
"Failed to construct a valid url from '{}' and '{}'.",
download_url_base, download_url_path
)
})?;

let child_target_foldername = format!("julia-{}", channel);

Expand Down
4 changes: 3 additions & 1 deletion tests/command_list_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ fn command_list() {
.env("JULIAUP_DEPOT_PATH", depot_dir.path())
.assert()
.success()
.stdout(predicate::str::starts_with(" Channel").and(predicate::str::contains("release")));
.stdout(predicate::str::starts_with(" Channel").and(predicate::str::contains("release")))
.stdout(predicate::str::contains("nightly"))
.stdout(predicate::str::contains("pr{number}"));

Command::cargo_bin("juliaup")
.unwrap()
Expand Down