Skip to content
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
11 changes: 6 additions & 5 deletions src/boot_fake_node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ use serde::Deserialize;
use tokio::sync::Mutex;
use tracing::{info, warn, instrument};

use super::build;
use super::run_tests::cleanup::{cleanup, cleanup_on_signal};
use super::run_tests::network_router;
use super::run_tests::types::*;
use crate::KIT_CACHE;
use crate::build;
use crate::run_tests::cleanup::{cleanup, cleanup_on_signal};
use crate::run_tests::network_router;
use crate::run_tests::types::*;

const KINODE_RELEASE_BASE_URL: &str = "https://github.com/kinode-dao/kinode/releases/download";
pub const KINODE_OWNER: &str = "kinode-dao";
Expand Down Expand Up @@ -165,7 +166,7 @@ pub async fn get_runtime_binary(version: &str) -> anyhow::Result<PathBuf> {

#[instrument(level = "trace", err, skip_all)]
pub async fn get_from_github(owner: &str, repo: &str, endpoint: &str) -> anyhow::Result<Vec<u8>> {
let cache_path = format!("{}/{}-{}-{}.bin", build::CACHE_DIR, owner, repo, endpoint);
let cache_path = format!("{}/{}-{}-{}.bin", KIT_CACHE, owner, repo, endpoint);
let cache_path = Path::new(&cache_path);
if cache_path.exists() {
if let Some(local_bytes) = std::fs::metadata(&cache_path).ok()
Expand Down
8 changes: 4 additions & 4 deletions src/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use serde::{Deserialize, Serialize};
use tokio::fs;
use tracing::{info, warn, instrument};

use super::setup::{
use crate::KIT_CACHE;
use crate::setup::{
check_js_deps, check_py_deps, check_rust_deps, get_deps, get_newest_valid_node_version,
REQUIRED_PY_PACKAGE,
};
Expand All @@ -18,7 +19,6 @@ const RUST_SRC_PATH: &str = "src/lib.rs";
const KINODE_WIT_URL: &str =
"https://raw.githubusercontent.com/kinode-dao/kinode-wit/master/kinode.wit";
const WASI_VERSION: &str = "17.0.1"; // TODO: un-hardcode
pub const CACHE_DIR: &str = "/tmp/kinode-kit-cache";

#[derive(Debug, Clone, Serialize, Deserialize)]
struct CargoFile {
Expand Down Expand Up @@ -54,9 +54,9 @@ pub fn run_command(cmd: &mut Command) -> anyhow::Result<(String, String)> {

#[instrument(level = "trace", err, skip_all)]
pub async fn download_file(url: &str, path: &Path) -> anyhow::Result<()> {
fs::create_dir_all(&CACHE_DIR).await?;
fs::create_dir_all(&KIT_CACHE).await?;
let hex_url = hex::encode(url);
let hex_url_path = format!("{}/{}", CACHE_DIR, hex_url);
let hex_url_path = format!("{}/{}", KIT_CACHE, hex_url);
let hex_url_path = Path::new(&hex_url_path);

let content = if hex_url_path.exists() {
Expand Down
4 changes: 2 additions & 2 deletions src/build_start_package/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::path::Path;

use tracing::instrument;

use super::build;
use super::start_package;
use crate::build;
use crate::start_package;

#[instrument(level = "trace", err, skip_all)]
pub async fn execute(
Expand Down
4 changes: 2 additions & 2 deletions src/dev_ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::process::Command;

use tracing::{info, instrument};

use super::build::run_command;
use super::setup::{check_js_deps, get_deps, get_newest_valid_node_version};
use crate::build::run_command;
use crate::setup::{check_js_deps, get_deps, get_newest_valid_node_version};

#[instrument(level = "trace", err, skip_all)]
pub fn execute(
Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ pub mod dev_ui;
pub mod inject_message;
pub mod new;
pub mod remove_package;
pub mod reset_cache;
pub mod run_tests;
pub mod setup;
pub mod start_package;
pub mod update;

pub const KIT_CACHE: &str = "/tmp/kinode-kit-cache";
81 changes: 45 additions & 36 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,20 @@ use tracing_subscriber::{
filter, fmt, layer::SubscriberExt, prelude::*, util::SubscriberInitExt, EnvFilter,
};

mod boot_fake_node;
mod build;
mod build_start_package;
mod dev_ui;
mod inject_message;
mod new;
mod remove_package;
mod run_tests;
mod setup;
mod start_package;
mod update;
use kit::{
boot_fake_node,
build,
build_start_package,
dev_ui,
inject_message,
new,
remove_package,
reset_cache,
run_tests,
setup,
start_package,
update,
};

const MAX_REMOTE_VALUES: usize = 3;
const GIT_COMMIT_HASH: &str = env!("GIT_COMMIT_SHA");
Expand Down Expand Up @@ -251,22 +254,6 @@ async fn execute(
*ui,
)
}
Some(("run-tests", run_tests_matches)) => {
let config_path = match run_tests_matches.get_one::<String>("PATH") {
Some(path) => PathBuf::from(path),
None => std::env::current_dir()?.join("tests.toml"),
};

if !config_path.exists() {
let error = format!(
"Configuration file not found: {:?}\nUsage:\n{}",
config_path, usage,
);
return Err(anyhow::anyhow!(error));
}

run_tests::execute(config_path.to_str().unwrap()).await
}
Some(("remove-package", remove_package_matches)) => {
let package_name = remove_package_matches
.get_one::<String>("PACKAGE")
Expand All @@ -285,6 +272,25 @@ async fn execute(
};
remove_package::execute(&package_dir, &url, package_name, publisher).await
}
Some(("reset-cache", _reset_cache_matches)) => {
reset_cache::execute()
}
Some(("run-tests", run_tests_matches)) => {
let config_path = match run_tests_matches.get_one::<String>("PATH") {
Some(path) => PathBuf::from(path),
None => std::env::current_dir()?.join("tests.toml"),
};

if !config_path.exists() {
let error = format!(
"Configuration file not found: {:?}\nUsage:\n{}",
config_path, usage,
);
return Err(anyhow::anyhow!(error));
}

run_tests::execute(config_path.to_str().unwrap()).await
}
Some(("setup", _setup_matches)) => setup::execute(),
Some(("start-package", start_package_matches)) => {
let package_dir =
Expand Down Expand Up @@ -642,15 +648,6 @@ async fn make_app(current_dir: &std::ffi::OsString) -> anyhow::Result<Command> {
.required(false)
)
)
.subcommand(Command::new("run-tests")
.about("Run Kinode tests")
.visible_alias("t")
.arg(Arg::new("PATH")
.action(ArgAction::Set)
.help("Path to tests configuration file")
.default_value("tests.toml")
)
)
.subcommand(Command::new("remove-package")
.about("Remove a running package from a node")
.visible_alias("r")
Expand Down Expand Up @@ -689,6 +686,18 @@ async fn make_app(current_dir: &std::ffi::OsString) -> anyhow::Result<Command> {
//.default_value("http://localhost:8080")
)
)
.subcommand(Command::new("reset-cache")
.about("Reset kit cache (Kinode core binaries, logs, etc.)")
)
.subcommand(Command::new("run-tests")
.about("Run Kinode tests")
.visible_alias("t")
.arg(Arg::new("PATH")
.action(ArgAction::Set)
.help("Path to tests configuration file")
.default_value("tests.toml")
)
)
.subcommand(Command::new("setup")
.about("Fetch & setup kit dependencies")
)
Expand Down
4 changes: 2 additions & 2 deletions src/remove_package/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use std::process;

use tracing::instrument;

use super::inject_message;
use super::start_package::interact_with_package;
use crate::inject_message;
use crate::start_package::interact_with_package;

#[instrument(level = "trace", err, skip_all)]
pub async fn execute(
Expand Down
22 changes: 22 additions & 0 deletions src/reset_cache/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use std::fs::remove_dir_all;
use std::path::PathBuf;

use tracing::{info, instrument};

use crate::KIT_CACHE;

#[instrument(level = "trace", err, skip_all)]
fn reset_cache() -> anyhow::Result<()> {
info!("Resetting cache...");
let path = PathBuf::from(KIT_CACHE);
if path.exists() {
remove_dir_all(&path)?;
}
info!("Done resetting cache.");
Ok(())
}

#[instrument(level = "trace", err, skip_all)]
pub fn execute() -> anyhow::Result<()> {
reset_cache()
}
8 changes: 4 additions & 4 deletions src/run_tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ use tokio::sync::Mutex;
use tokio::time::{sleep, Duration};
use tracing::{debug, info, instrument};

use super::boot_fake_node::{compile_runtime, get_runtime_binary, run_runtime};
use super::build;
use super::inject_message;
use super::start_package;
use crate::boot_fake_node::{compile_runtime, get_runtime_binary, run_runtime};
use crate::build;
use crate::inject_message;
use crate::start_package;

pub mod cleanup;
use cleanup::{cleanup, cleanup_on_signal};
Expand Down
2 changes: 1 addition & 1 deletion src/setup/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::str;

use tracing::{info, warn, instrument};

use super::build::run_command;
use crate::build::run_command;

const FETCH_NVM_VERSION: &str = "v0.39.7";
const REQUIRED_NODE_MAJOR: u32 = 20;
Expand Down
2 changes: 1 addition & 1 deletion src/start_package/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use zip::write::FileOptions;

use kinode_process_lib::kernel_types::Erc721Metadata;

use super::inject_message;
use crate::inject_message;

#[instrument(level = "trace", err, skip_all)]
fn new_package(
Expand Down
5 changes: 3 additions & 2 deletions src/update/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use std::process::Command;

use tracing::instrument;

use super::build;
use crate::KIT_CACHE;
use crate::build;

#[instrument(level = "trace", err, skip_all)]
pub fn execute(mut user_args: Vec<String>, branch: &str) -> anyhow::Result<()> {
Expand All @@ -17,7 +18,7 @@ pub fn execute(mut user_args: Vec<String>, branch: &str) -> anyhow::Result<()> {
args.append(&mut user_args);
build::run_command(Command::new("cargo").args(&args[..]))?;

let cache_path = format!("{}/kinode-dao-kit-commits", build::CACHE_DIR);
let cache_path = format!("{}/kinode-dao-kit-commits", KIT_CACHE);
let cache_path = std::path::Path::new(&cache_path);
if cache_path.exists() {
std::fs::remove_dir_all(&cache_path)?;
Expand Down