Skip to content

Commit

Permalink
feat: add node launchpad to release type
Browse files Browse the repository at this point in the history
A new `node-launchpad` binary is being introduced, which is a node management TUI. It therefore
needs a corresponding `ReleaseType` variant.

The crate for `node-launchpad`, `sn_node_launchpad`, does not yet have a published version, so the
`get_latest_version` function has been hard coded to return the first alpha version. This will be
removed soon.
  • Loading branch information
jacderida committed May 4, 2024
1 parent 282960a commit d71a357
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use zip::ZipArchive;

const GITHUB_API_URL: &str = "https://api.github.com";
const FAUCET_S3_BASE_URL: &str = "https://sn-faucet.s3.eu-west-2.amazonaws.com";
const NODE_LAUNCHPAD_S3_BASE_URL: &str = "https://sn-node-launchpad.s3.eu-west-2.amazonaws.com";
const SAFE_S3_BASE_URL: &str = "https://sn-cli.s3.eu-west-2.amazonaws.com";
const SAFENODE_S3_BASE_URL: &str = "https://sn-node.s3.eu-west-2.amazonaws.com";
const SAFENODE_MANAGER_S3_BASE_URL: &str = "https://sn-node-manager.s3.eu-west-2.amazonaws.com";
Expand All @@ -35,6 +36,7 @@ const SAFENODE_RPC_CLIENT_S3_BASE_URL: &str =
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub enum ReleaseType {
Faucet,
NodeLaunchpad,
Safe,
Safenode,
SafenodeManager,
Expand All @@ -49,6 +51,7 @@ impl fmt::Display for ReleaseType {
"{}",
match self {
ReleaseType::Faucet => "faucet",
ReleaseType::NodeLaunchpad => "node-launchpad",
ReleaseType::Safe => "safe",
ReleaseType::Safenode => "safenode",
ReleaseType::SafenodeManager => "safenode-manager",
Expand All @@ -63,6 +66,7 @@ lazy_static! {
static ref RELEASE_TYPE_CRATE_NAME_MAP: HashMap<ReleaseType, &'static str> = {
let mut m = HashMap::new();
m.insert(ReleaseType::Faucet, "sn_faucet");
m.insert(ReleaseType::NodeLaunchpad, "sn_node_launchpad");
m.insert(ReleaseType::Safe, "sn_cli");
m.insert(ReleaseType::Safenode, "sn_node");
m.insert(ReleaseType::SafenodeManager, "sn-node-manager");
Expand Down Expand Up @@ -139,6 +143,7 @@ impl dyn SafeReleaseRepoActions {
Box::new(SafeReleaseRepository {
github_api_base_url: GITHUB_API_URL.to_string(),
faucet_base_url: FAUCET_S3_BASE_URL.to_string(),
node_launchpad_base_url: NODE_LAUNCHPAD_S3_BASE_URL.to_string(),
safe_base_url: SAFE_S3_BASE_URL.to_string(),
safenode_base_url: SAFENODE_S3_BASE_URL.to_string(),
safenode_manager_base_url: SAFENODE_MANAGER_S3_BASE_URL.to_string(),
Expand All @@ -150,6 +155,7 @@ impl dyn SafeReleaseRepoActions {
pub struct SafeReleaseRepository {
pub github_api_base_url: String,
pub faucet_base_url: String,
pub node_launchpad_base_url: String,
pub safe_base_url: String,
pub safenode_base_url: String,
pub safenode_manager_base_url: String,
Expand All @@ -160,6 +166,7 @@ impl SafeReleaseRepository {
fn get_base_url(&self, release_type: &ReleaseType) -> String {
match release_type {
ReleaseType::Faucet => self.faucet_base_url.clone(),
ReleaseType::NodeLaunchpad => self.node_launchpad_base_url.clone(),
ReleaseType::Safe => self.safe_base_url.clone(),
ReleaseType::Safenode => self.safenode_base_url.clone(),
ReleaseType::SafenodeManager => self.safenode_manager_base_url.clone(),
Expand Down Expand Up @@ -219,6 +226,12 @@ impl SafeReleaseRepoActions for SafeReleaseRepository {
/// - The HTTP request to crates.io API fails
/// - The received JSON data does not have a `crate.newest_version` value
async fn get_latest_version(&self, release_type: &ReleaseType) -> Result<Version> {
// For the time being, the node launchpad needs to be treated as a special case, because it
// cannot be published.
if matches!(release_type, ReleaseType::NodeLaunchpad) {
return Ok(Version::parse("0.1.0-alpha.0")?);
}

let crate_name = *RELEASE_TYPE_CRATE_NAME_MAP.get(release_type).unwrap();
let url = format!("https://crates.io/api/v1/crates/{}", crate_name);

Expand Down
71 changes: 71 additions & 0 deletions tests/test_download_from_s3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use semver::Version;
use sn_releases::{ArchiveType, Platform, ReleaseType, SafeReleaseRepoActions};

const FAUCET_VERSION: &str = "0.1.98";
const NODE_LAUNCHPAD_VERSION: &str = "0.1.0-alpha.0";
const SAFE_VERSION: &str = "0.83.51";
const SAFENODE_VERSION: &str = "0.93.7";
const SAFENODE_MANAGER_VERSION: &str = "0.1.8";
Expand Down Expand Up @@ -51,6 +52,7 @@ async fn download_and_extract(

let binary_name = match release_type {
ReleaseType::Faucet => "faucet",
ReleaseType::NodeLaunchpad => "node-launchpad",
ReleaseType::Safe => "safe",
ReleaseType::Safenode => "safenode",
ReleaseType::SafenodeManager => "safenode-manager",
Expand Down Expand Up @@ -481,3 +483,72 @@ async fn should_download_and_extract_safenodemand_for_windows() {
)
.await;
}

///
/// Node Launchpad Tests
///
#[tokio::test]
async fn should_download_and_extract_node_launchpad_for_linux_musl() {
download_and_extract(
&ReleaseType::NodeLaunchpad,
NODE_LAUNCHPAD_VERSION,
&Platform::LinuxMusl,
&ArchiveType::TarGz,
)
.await;
}

#[tokio::test]
async fn should_download_and_extract_node_launchpad_for_linux_musl_aarch64() {
download_and_extract(
&ReleaseType::NodeLaunchpad,
NODE_LAUNCHPAD_VERSION,
&Platform::LinuxMuslAarch64,
&ArchiveType::TarGz,
)
.await;
}

#[tokio::test]
async fn should_download_and_extract_node_launchpad_for_linux_musl_arm() {
download_and_extract(
&ReleaseType::NodeLaunchpad,
NODE_LAUNCHPAD_VERSION,
&Platform::LinuxMuslArm,
&ArchiveType::TarGz,
)
.await;
}

#[tokio::test]
async fn should_download_and_extract_node_launchpad_for_linux_musl_arm_v7() {
download_and_extract(
&ReleaseType::NodeLaunchpad,
NODE_LAUNCHPAD_VERSION,
&Platform::LinuxMuslArmV7,
&ArchiveType::TarGz,
)
.await;
}

#[tokio::test]
async fn should_download_and_extract_node_launchpad_for_macos() {
download_and_extract(
&ReleaseType::NodeLaunchpad,
NODE_LAUNCHPAD_VERSION,
&Platform::MacOs,
&ArchiveType::TarGz,
)
.await;
}

#[tokio::test]
async fn should_download_and_extract_node_launchpad_for_windows() {
download_and_extract(
&ReleaseType::NodeLaunchpad,
NODE_LAUNCHPAD_VERSION,
&Platform::Windows,
&ArchiveType::Zip,
)
.await;
}

0 comments on commit d71a357

Please sign in to comment.