Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
dcodesdev committed Sep 21, 2024
1 parent dff3c3d commit 62161cc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion crates/rustfinity-runner/example.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh

cargo run run \
cargo -q run run \
--code cHViIGZuIGhlbGxvX3dvcmxkKCkgewogICAgcHJpbnRsbiEoImhlbGxvIHdvcmxkIikKfQo= \
--challenge printing-hello-world
24 changes: 19 additions & 5 deletions crates/rustfinity-runner/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,20 @@ pub async fn run_code(code_base64: &str, challenge: &str) -> anyhow::Result<Stri

output.push_str("---");

let challenges_path = get_challenges_path();
let current_challenge_path = format!("{challenges_path}/{challenge}");

// Check time
let test_running_command = extract_unittest_path(&output).unwrap();

run_command_and_merge_output(&test_running_command, &[], None).await?;
let time_tracking_output = run_command_and_merge_output(
"time",
&[&test_running_command],
Some(&current_challenge_path),
)
.await?;

output.push_str(&time_tracking_output);

Ok(output)
}
Expand All @@ -39,10 +49,7 @@ async fn run_tests(code_base64: &str, challenge: &str) -> anyhow::Result<String>
return Ok(output);
}

// If you run this code outside a container, use the env var
let challenges_path = env::var("CHALLENGES_PATH")
// default value in container
.unwrap_or("/app/rustfinity.com/challenges".to_string());
let challenges_path = get_challenges_path();

let repo_path = format!("{challenges_path}/{challenge}");
let repository_path = Path::new(&repo_path).canonicalize()?;
Expand All @@ -61,6 +68,13 @@ async fn run_tests(code_base64: &str, challenge: &str) -> anyhow::Result<String>
Ok(output)
}

fn get_challenges_path() -> String {
// If you run this code outside a container, use the env var
env::var("CHALLENGES_PATH")
// default value in container
.unwrap_or("/app/rustfinity.com/challenges".to_string())
}

pub async fn run_command_and_merge_output(
command: &str,
args: &[&str],
Expand Down

0 comments on commit 62161cc

Please sign in to comment.