Skip to content

Commit

Permalink
feat: provide node-launchpad command
Browse files Browse the repository at this point in the history
BREAKING CHANGE: the new settings file will have additional entries for keeping track of the
node-launchpad installation. Previously serialised settings files will be incompatible with this
change. Users will need to clear their previous settings file when they upgrade.
  • Loading branch information
jacderida committed May 24, 2024
1 parent 9dbde92 commit e2e04f7
Show file tree
Hide file tree
Showing 6 changed files with 196 additions and 5 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ env:
CLIENT_VERSION: 0.77.27
NODE_VERSION: 0.83.25
NODE_MANAGER_VERSION: 0.1.8
NODE_LAUNCHPAD_VERSION: 0.2.0

jobs:
# The code in this crate uses lots of conditional compilation for cross-platform capabilities.
Expand Down Expand Up @@ -141,6 +142,7 @@ jobs:
cargo run -- client --version $env:CLIENT_VERSION
cargo run -- node --version $env:NODE_VERSION
cargo run -- node-manager --version $env:NODE_MANAGER_VERSION
cargo run -- node-launchpad --version $env:NODE_LAUNCHPAD_VERSION
- name: Check if binaries are available in new shell session
shell: pwsh
run: |
Expand All @@ -156,6 +158,10 @@ jobs:
Write-Host "safenode-manager.exe does not exist"
exit 1
}
if (!(Test-Path "$env:USERPROFILE\safe\node-launchpad.exe")) {
Write-Host "node-launchpad.exe does not exist"
exit 1
}
# For security reasons, the GHA infrastructure prevents environment variables
# being modified easily, so we need to refer to the binaries with their full paths.
Expand Down Expand Up @@ -197,6 +203,18 @@ jobs:
exit 1
}
$output = & "${env:USERPROFILE}\safe\node-launchpad.exe" --version
$version = $output | Select-String -Pattern "node-launchpad (\d+\.\d+\.\d+)"
$versionNumber = $version.Matches.Groups[1].Value
if ($versionNumber -eq "$env:NODE_LAUNCHPAD_VERSION") {
Write-Host "The correct version of safenode-manager has been installed"
} else {
Write-Host "The correct version of safenode-manager has not been installed"
Write-Host "We expected version $env:NODE_LAUNCHPAD_VERSION"
Write-Host "The downloaded binary has $versionNumber"
exit 1
}
test-install-linux:
if: "!startsWith(github.event.pull_request.title, 'Automated version bump')"
name: Install test (Linux)
Expand All @@ -214,6 +232,7 @@ jobs:
cargo run -- client --version $CLIENT_VERSION
cargo run -- node --version $NODE_VERSION
cargo run -- node-manager --version $NODE_MANAGER_VERSION
cargo run -- node-launchpad --version $NODE_LAUNCHPAD_VERSION
- name: Check if binaries are available in new shell session
shell: bash
run: |
Expand All @@ -229,6 +248,7 @@ jobs:
[[ -f "$HOME/.local/bin/safe" ]] || { echo "safe not in expected location"; exit 1; }
[[ -f "$HOME/.local/bin/safenode" ]] || { echo "safenode not in expected location"; exit 1; }
[[ -f "$HOME/.local/bin/safenode-manager" ]] || { echo "safenode-manager not in expected location"; exit 1; }
[[ -f "$HOME/.local/bin/node-launchpad" ]] || { echo "node-launchpad not in expected location"; exit 1; }
version=$(safe --version | awk '{ print $2 }')
if [[ "$version" == "$CLIENT_VERSION" ]]; then
Expand Down Expand Up @@ -260,6 +280,16 @@ jobs:
exit 1
fi
version=$(node-launchpad --version | awk '{ print $2 }')
if [[ "$version" == "$NODE_LAUNCHPAD_VERSION" ]]; then
echo "The correct version of node-launchpad has been installed"
else
echo "The correct version of node-launchpad has not been installed"
echo "We expected $NODE_LAUNCHPAD_VERSION"
echo "The downloaded binary has $version"
exit 1
fi
test-install-macos:
if: "!startsWith(github.event.pull_request.title, 'Automated version bump')"
name: Install test (macOS)
Expand All @@ -276,6 +306,7 @@ jobs:
cargo run -- client --version $CLIENT_VERSION
cargo run -- node --version $NODE_VERSION
cargo run -- node-manager --version $NODE_MANAGER_VERSION
cargo run -- node-launchpad --version $NODE_LAUNCHPAD_VERSION
- name: Check if binaries are available in new shell session
run: |
# As with the Ubuntu test, we need to source the env file to get the binaries on PATH.
Expand All @@ -284,6 +315,7 @@ jobs:
[[ -f "$HOME/.local/bin/safe" ]] || { echo "safe not in expected location"; exit 1; }
[[ -f "$HOME/.local/bin/safenode" ]] || { echo "safenode not in expected location"; exit 1; }
[[ -f "$HOME/.local/bin/safenode-manager" ]] || { echo "safenode-manager not in expected location"; exit 1; }
[[ -f "$HOME/.local/bin/node-launchpad" ]] || { echo "node-launchpad not in expected location"; exit 1; }
version=$(safe --version | awk '{ print $2 }')
if [[ "$version" == "$CLIENT_VERSION" ]]; then
Expand Down Expand Up @@ -315,6 +347,16 @@ jobs:
exit 1
fi
version=$(node-launchpad --version | awk '{ print $2 }')
if [[ "$version" == "$NODE_LAUNCHPAD_VERSION" ]]; then
echo "The correct version of node-launchpad has been installed"
else
echo "The correct version of node-launchpad has not been installed"
echo "We expected $NODE_LAUNCHPAD_VERSION"
echo "The downloaded binary has $version"
exit 1
fi
test-publish:
if: "!startsWith(github.event.pull_request.title, 'Automated version bump')"
name: Test Publish
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ semver = "1.0.4"
serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"
sn-releases = "0.2.0"
sn-releases = "0.2.5"
tempfile = "3.8.1"
textwrap = "0.16.0"
tokio = { version = "1.26", features = ["full"] }
Expand Down
4 changes: 4 additions & 0 deletions src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ async fn do_install_binary(
settings.safenode_path = Some(bin_path);
settings.safenode_version = Some(installed_version);
}
AssetType::NodeLaunchpad => {
settings.node_launchpad_path = Some(bin_path);
settings.node_launchpad_version = Some(installed_version);
}
AssetType::NodeManager => {
settings.safenode_manager_path = Some(bin_path);
settings.safenode_manager_version = Some(installed_version);
Expand Down
39 changes: 35 additions & 4 deletions src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const SET_PATH_FILE_CONTENT: &str = indoc! {r#"
pub enum AssetType {
Client,
Node,
NodeLaunchpad,
NodeManager,
}

Expand All @@ -65,6 +66,7 @@ impl AssetType {
match self {
AssetType::Client => ReleaseType::Safe,
AssetType::Node => ReleaseType::Safenode,
AssetType::NodeLaunchpad => ReleaseType::NodeLaunchpad,
AssetType::NodeManager => ReleaseType::SafenodeManager,
}
}
Expand All @@ -75,13 +77,20 @@ impl std::fmt::Display for AssetType {
match *self {
AssetType::Client => write!(f, "safe"),
AssetType::Node => write!(f, "safenode"),
AssetType::NodeLaunchpad => write!(f, "node-launchpad"),
AssetType::NodeManager => write!(f, "safenode-manager"),
}
}
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Settings {
pub node_launchpad_path: Option<PathBuf>,
#[serde(
serialize_with = "serialize_version",
deserialize_with = "deserialize_version"
)]
pub node_launchpad_version: Option<Version>,
pub safe_path: Option<PathBuf>,
#[serde(
serialize_with = "serialize_version",
Expand Down Expand Up @@ -166,6 +175,8 @@ impl Settings {
let mut contents = String::new();
file.read_to_string(&mut contents)?;
serde_json::from_str(&contents).unwrap_or_else(|_| Settings {
node_launchpad_path: None,
node_launchpad_version: None,
safe_path: None,
safe_version: None,
safenode_path: None,
Expand All @@ -175,6 +186,8 @@ impl Settings {
})
} else {
Settings {
node_launchpad_path: None,
node_launchpad_version: None,
safe_path: None,
safe_version: None,
safenode_path: None,
Expand Down Expand Up @@ -206,6 +219,14 @@ impl Settings {
}
None
}
AssetType::NodeLaunchpad => {
if self.node_launchpad_path.is_some() {
let path = self.node_launchpad_path.as_ref().unwrap();
let version = self.node_launchpad_version.as_ref().unwrap();
return Some((path.clone(), version.clone()));
}
None
}
AssetType::NodeManager => {
if self.safenode_manager_path.is_some() {
let path = self.safenode_manager_path.as_ref().unwrap();
Expand Down Expand Up @@ -422,6 +443,7 @@ fn get_bin_name(asset_type: &AssetType) -> String {
let mut bin_name = match asset_type {
AssetType::Client => "safe".to_string(),
AssetType::Node => "safenode".to_string(),
AssetType::NodeLaunchpad => "node-launchpad".to_string(),
AssetType::NodeManager => "safenode-manager".to_string(),
};
if OS == "windows" {
Expand Down Expand Up @@ -788,10 +810,12 @@ mod test {
safenode_bin_file.write_binary(b"fake safenode code")?;
let safenode_manager_bin_file = tmp_data_path.child("safenode-manager");
safenode_manager_bin_file.write_binary(b"fake safenode-manager code")?;
let testnet_bin_file = tmp_data_path.child("testnet");
testnet_bin_file.write_binary(b"fake testnet code")?;
let node_launchpad_bin_file = tmp_data_path.child("node-launchpad");
node_launchpad_bin_file.write_binary(b"fake launchpad code")?;

let settings = Settings {
node_launchpad_path: Some(node_launchpad_bin_file.to_path_buf()),
node_launchpad_version: Some(Version::new(0, 2, 0)),
safe_path: Some(safe_bin_file.to_path_buf()),
safe_version: Some(Version::new(0, 75, 1)),
safenode_path: Some(safenode_bin_file.to_path_buf()),
Expand All @@ -804,6 +828,11 @@ mod test {

settings_file.assert(predicates::path::is_file());
let settings = Settings::read(&settings_file.to_path_buf())?;
assert_eq!(
settings.node_launchpad_path,
Some(node_launchpad_bin_file.to_path_buf())
);
assert_eq!(settings.node_launchpad_version, Some(Version::new(0, 2, 0)));
assert_eq!(settings.safe_path, Some(safe_bin_file.to_path_buf()));
assert_eq!(settings.safe_version, Some(Version::new(0, 75, 1)));
assert_eq!(
Expand Down Expand Up @@ -837,10 +866,12 @@ mod test {
safenode_bin_file.write_binary(b"fake safenode code")?;
let safenode_manager_bin_file = tmp_data_path.child("safenode-manager");
safenode_manager_bin_file.write_binary(b"fake safenode-manager code")?;
let testnet_bin_file = tmp_data_path.child("testnet");
testnet_bin_file.write_binary(b"fake testnet code")?;
let node_launchpad_bin_file = tmp_data_path.child("node-launchpad");
node_launchpad_bin_file.write_binary(b"fake launchpad code")?;

let settings = Settings {
node_launchpad_path: Some(node_launchpad_bin_file.to_path_buf()),
node_launchpad_version: Some(Version::new(0, 2, 0)),
safe_path: Some(safe_bin_file.to_path_buf()),
safe_version: Some(Version::new(0, 75, 1)),
safenode_path: Some(safenode_bin_file.to_path_buf()),
Expand Down
43 changes: 43 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,30 @@ enum Commands {
#[arg(short = 'v', long)]
version: Option<String>,
},
/// Install the node-launchpad binary.
///
/// The location is platform specific:
/// - Linux/macOS: $HOME/.local/bin
/// - Windows: C:\Users\<username>\safe
///
/// On Linux/macOS, the Bash shell profile will be modified to add $HOME/.local/bin to the PATH
/// variable. On Windows, the user Path variable will be modified to add C:\Users\<username>\safe.
#[clap(verbatim_doc_comment)]
NodeLaunchpad {
/// Override the default installation path.
///
/// Any directories that don't exist will be created.
#[arg(short = 'p', long, value_name = "DIRECTORY")]
path: Option<PathBuf>,

/// Disable modification of the shell profile.
#[arg(short = 'n', long)]
no_modify_shell_profile: bool,

/// Install a specific version rather than the latest.
#[arg(short = 'v', long)]
version: Option<String>,
},
/// Install the safenode-manager binary.
///
/// The location is platform specific:
Expand Down Expand Up @@ -139,6 +163,25 @@ async fn main() -> Result<()> {
install::check_prerequisites()?;
process_install_cmd(AssetType::Node, path, version, no_modify_shell_profile).await
}
Some(Commands::NodeLaunchpad {
path,
no_modify_shell_profile,
version,
}) => {
println!("**************************************");
println!("* *");
println!("* Installing node-launchpad *");
println!("* *");
println!("**************************************");
install::check_prerequisites()?;
process_install_cmd(
AssetType::NodeLaunchpad,
path,
version,
no_modify_shell_profile,
)
.await
}
Some(Commands::NodeManager {
path,
no_modify_shell_profile,
Expand Down
Loading

0 comments on commit e2e04f7

Please sign in to comment.