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

Generate random experiment name in guide example #25

Merged
merged 4 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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 crates/heat-sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ rmp-serde = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
log = { workspace = true }
rand = { version = "0.8.5" }
reqwest = { workspace = true, features = ["blocking", "json"] }
tungstenite = { version = "0.21.0" }
thiserror = { workspace = true }
Expand Down
9 changes: 9 additions & 0 deletions crates/heat-sdk/src/http/client.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::collections::HashMap;

use rand::Rng;
use reqwest::header::{COOKIE, SET_COOKIE};
use serde::Serialize;

Expand Down Expand Up @@ -125,11 +126,19 @@ impl HttpClient {

let url = format!("{}/projects/{}/experiments", self.base_url, project_id);

let mut body = HashMap::new();
let mut rng = rand::thread_rng();
body.insert(
"experiment_name",
format!("guide-{}", rng.gen_range(0..10000)),
);

// Create a new experiment
let exp_uuid = self
.http_client
.post(url)
.header(COOKIE, self.session_cookie.as_ref().unwrap())
.json(&body)
.send()?
.error_for_status()?
.json::<CreateExperimentResponseSchema>()?
Expand Down
82 changes: 59 additions & 23 deletions xtask/src/commands/check.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
use std::process::Command;

use anyhow::{Ok, Result, anyhow};
use anyhow::{anyhow, Ok, Result};
use clap::{Args, Subcommand};
use strum::{Display, EnumIter, EnumString, IntoEnumIterator};

use crate::{endgroup, group, utils::{cargo::ensure_cargo_crate_is_installed, prompt::ask_once, workspace::{get_workspace_members, WorkspaceMemberType}}};
use crate::{
endgroup, group,
utils::{
cargo::ensure_cargo_crate_is_installed,
prompt::ask_once,
workspace::{get_workspace_members, WorkspaceMemberType},
},
};

use super::Target;

Expand Down Expand Up @@ -36,17 +43,21 @@ pub(crate) fn handle_command(args: CheckCmdArgs, answer: Option<bool>) -> anyhow
CheckCommand::Format => run_format(&args.target, answer),
CheckCommand::Lint => run_lint(&args.target, answer),
CheckCommand::All => {
let answer = ask_once("This will run all the checks with autofix on all members of the workspace.");
let answer = ask_once(
"This will run all the checks with autofix on all members of the workspace.",
);
CheckCommand::iter()
.filter(|c| *c != CheckCommand::All)
.try_for_each(|c| handle_command(
CheckCmdArgs {
command: c,
target: args.target.clone()
},
Some(answer),
))
},
.try_for_each(|c| {
handle_command(
CheckCmdArgs {
command: c,
target: args.target.clone(),
},
Some(answer),
)
})
}
}
}

Expand All @@ -71,7 +82,7 @@ pub(crate) fn run_audit(target: &Target, mut answer: Option<bool>) -> anyhow::Re
}
endgroup!();
}
},
}
Target::All => {
let answer = ask_once("This will run audit checks on all targets.");
Target::iter()
Expand All @@ -94,7 +105,11 @@ fn run_format(target: &Target, mut answer: Option<bool>) -> Result<()> {
if answer.is_none() {
answer = Some(ask_once(&format!(
"This will run format checks on all {} of the workspace.",
if *target == Target::Crates { "crates" } else { "examples" }
if *target == Target::Crates {
"crates"
} else {
"examples"
}
)));
}

Expand All @@ -107,22 +122,27 @@ fn run_format(target: &Target, mut answer: Option<bool>) -> Result<()> {
.status()
.map_err(|e| anyhow!("Failed to execute cargo fmt: {}", e))?;
if !status.success() {
return Err(anyhow!("Format check execution failed for {}", &member.name));
return Err(anyhow!(
"Format check execution failed for {}",
&member.name
));
}
endgroup!();
}
}
},
}
Target::All => {
if answer.is_none() {
answer = Some(ask_once("This will run format check on all members of the workspace."));
answer = Some(ask_once(
"This will run format check on all members of the workspace.",
));
}
if answer.unwrap() {
Target::iter()
.filter(|t| *t != Target::All)
.try_for_each(|t| run_format(&t, answer))?;
}
},
}
}
Ok(())
}
Expand All @@ -139,16 +159,30 @@ fn run_lint(target: &Target, mut answer: Option<bool>) -> anyhow::Result<()> {
if answer.is_none() {
answer = Some(ask_once(&format!(
"This will run lint fix on all {} of the workspace.",
if *target == Target::Crates { "crates" } else { "examples" }
if *target == Target::Crates {
"crates"
} else {
"examples"
}
)));
}

if answer.unwrap() {
for member in members {
group!("Lint: {}", member.name);
info!("Command line: cargo clippy --no-deps --fix --allow-dirty -p {}", &member.name);
info!(
"Command line: cargo clippy --no-deps --fix --allow-dirty -p {}",
&member.name
);
let status = Command::new("cargo")
.args(["clippy", "--no-deps", "--fix", "--allow-dirty", "-p", &member.name])
.args([
"clippy",
"--no-deps",
"--fix",
"--allow-dirty",
"-p",
&member.name,
])
.status()
.map_err(|e| anyhow!("Failed to execute cargo clippy: {}", e))?;
if !status.success() {
Expand All @@ -157,17 +191,19 @@ fn run_lint(target: &Target, mut answer: Option<bool>) -> anyhow::Result<()> {
endgroup!();
}
}
},
}
Target::All => {
if answer.is_none() {
answer = Some(ask_once("This will run lint fix on all members of the workspace."));
answer = Some(ask_once(
"This will run lint fix on all members of the workspace.",
));
}
if answer.unwrap() {
Target::iter()
.filter(|t| *t != Target::All)
.try_for_each(|t| run_lint(&t, answer))?;
}
},
}
}
Ok(())
}
65 changes: 43 additions & 22 deletions xtask/src/commands/ci.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
use std::process::Command;

use anyhow::{Ok, Result, anyhow};
use anyhow::{anyhow, Ok, Result};
use clap::{Args, Subcommand};
use strum::{Display, EnumIter, EnumString, IntoEnumIterator};

use crate::{endgroup, group, utils::{cargo::ensure_cargo_crate_is_installed, workspace::{get_workspace_members, WorkspaceMemberType}}};
use crate::{
endgroup, group,
utils::{
cargo::ensure_cargo_crate_is_installed,
workspace::{get_workspace_members, WorkspaceMemberType},
},
};

use super::{test::{run_documentation, run_integration, run_unit}, Target};
use super::{
test::{run_documentation, run_integration, run_unit},
Target,
};

#[derive(Args)]
pub(crate) struct CICmdArgs {
Expand Down Expand Up @@ -47,16 +56,14 @@ pub(crate) fn handle_command(args: CICmdArgs) -> anyhow::Result<()> {
CICommand::IntegrationTests => run_integration_tests(&args.target),
CICommand::DocTests => run_doc_tests(&args.target),
CICommand::AllTests => run_all_tests(&args.target),
CICommand::All => {
CICommand::iter()
.filter(|c| *c != CICommand::All && *c != CICommand::AllTests)
.try_for_each(|c| handle_command(
CICmdArgs {
command: c,
target: args.target.clone()
},
))
},
CICommand::All => CICommand::iter()
.filter(|c| *c != CICommand::All && *c != CICommand::AllTests)
.try_for_each(|c| {
handle_command(CICmdArgs {
command: c,
target: args.target.clone(),
})
}),
}
}

Expand All @@ -74,12 +81,12 @@ fn run_audit(target: &Target) -> anyhow::Result<()> {
return Err(anyhow!("Audit check execution failed"));
}
endgroup!();
},
}
Target::All => {
Target::iter()
.filter(|t| *t != Target::All && *t != Target::Examples)
.try_for_each(|t| run_audit(&t))?;
},
}
}
Ok(())
}
Expand All @@ -101,16 +108,19 @@ fn run_format(target: &Target) -> Result<()> {
.status()
.map_err(|e| anyhow!("Failed to execute cargo fmt: {}", e))?;
if !status.success() {
return Err(anyhow!("Format check execution failed for {}", &member.name));
return Err(anyhow!(
"Format check execution failed for {}",
&member.name
));
}
endgroup!();
}
},
}
Target::All => {
Target::iter()
.filter(|t| *t != Target::All)
.try_for_each(|t| run_format(&t))?;
},
}
}
Ok(())
}
Expand All @@ -126,22 +136,33 @@ fn run_lint(target: &Target) -> anyhow::Result<()> {

for member in members {
group!("Lint: {}", member.name);
info!("Command line: cargo clippy --no-deps -p {} -- --deny warnings", &member.name);
info!(
"Command line: cargo clippy --no-deps -p {} -- --deny warnings",
&member.name
);
let status = Command::new("cargo")
.args(["clippy", "--no-deps", "-p", &member.name, "--", "--deny", "warnings",])
.args([
"clippy",
"--no-deps",
"-p",
&member.name,
"--",
"--deny",
"warnings",
])
.status()
.map_err(|e| anyhow!("Failed to execute cargo clippy: {}", e))?;
if !status.success() {
return Err(anyhow!("Lint fix execution failed for {}", &member.name));
}
endgroup!();
}
},
}
Target::All => {
Target::iter()
.filter(|t| *t != Target::All)
.try_for_each(|t| run_lint(&t))?;
},
}
}
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion xtask/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use strum::{Display, EnumIter, EnumString};

#[derive(EnumString, EnumIter, Display, Clone, PartialEq, ValueEnum)]
#[strum(serialize_all = "lowercase")]
pub(crate) enum Target{
pub(crate) enum Target {
All,
Crates,
Examples,
Expand Down
18 changes: 11 additions & 7 deletions xtask/src/commands/pull_request_checks.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
use strum::IntoEnumIterator;

use super::{ci::{self, CICmdArgs, CICommand}, test::run_guide};
use super::{
ci::{self, CICmdArgs, CICommand},
test::run_guide,
};

pub(crate) fn handle_command() -> anyhow::Result<()> {
CICommand::iter()
// Skip audit command
.filter(|c| *c != CICommand::All && *c != CICommand::AllTests && *c != CICommand::Audit )
.try_for_each(|c| ci::handle_command(CICmdArgs {
target: super::Target::All,
command: c.clone(),
})
)?;
.filter(|c| *c != CICommand::All && *c != CICommand::AllTests && *c != CICommand::Audit)
.try_for_each(|c| {
ci::handle_command(CICmdArgs {
target: super::Target::All,
command: c.clone(),
})
})?;
// Execute the guide example
run_guide()
}
Loading
Loading