Skip to content

Commit

Permalink
Merge pull request #1386 from cachix/tasks
Browse files Browse the repository at this point in the history
Tasks
  • Loading branch information
domenkozar authored Sep 24, 2024
2 parents f318d27 + 2562910 commit 045c4c4
Show file tree
Hide file tree
Showing 35 changed files with 3,312 additions and 922 deletions.
434 changes: 384 additions & 50 deletions Cargo.lock

Large diffs are not rendered by default.

15 changes: 8 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
[workspace]
resolver = "2"
members = [
"devenv",
"devenv-run-tests",
"xtask",
]
members = ["devenv", "devenv-run-tests", "xtask", "tasks"]

[workspace.package]
edition = "2021"
Expand All @@ -25,7 +21,12 @@ miette = { version = "7.1.0", features = ["fancy"] }
nix = { version = "0.28.0", features = ["signal"] }
regex = "1.10.3"
reqwest = "0.11.26"
schematic = { version = "0.14.3", features = ["schema", "yaml", "renderer_template", "renderer_json_schema"] }
schematic = { version = "0.14.3", features = [
"schema",
"yaml",
"renderer_template",
"renderer_json_schema",
] }
serde = "1.0.197"
serde_json = "1.0.114"
serde_yaml = "0.9.32"
Expand All @@ -35,5 +36,5 @@ tracing = "0.1.40"
which = "6.0.0"
whoami = "1.5.1"
xdg = "2.5.2"

tokio = "1.39.3"
schemars = "0.8.16"
1 change: 1 addition & 0 deletions devenv-run-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ clap.workspace = true
tempdir.workspace = true

devenv= { path = "../devenv" }
tokio = "1.39.3"
26 changes: 21 additions & 5 deletions devenv-run-tests/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ struct TestResult {
passed: bool,
}

fn run_tests_in_directory(args: &Args) -> Result<Vec<TestResult>, Box<dyn std::error::Error>> {
async fn run_tests_in_directory(
args: &Args,
) -> Result<Vec<TestResult>, Box<dyn std::error::Error>> {
let logger = Logger::new(Level::Info);

logger.info("Running Tests");
Expand Down Expand Up @@ -118,11 +120,13 @@ fn run_tests_in_directory(args: &Args) -> Result<Vec<TestResult>, Box<dyn std::e
// Run .setup.sh if it exists
if setup_script_path.exists() {
println!(" Running {setup_script}");
devenv.shell(&Some(format!("./{setup_script}")), &[], false)?;
devenv
.shell(&Some(format!("./{setup_script}")), &[], false)
.await?;
}

// TODO: wait for processes to shut down before exiting
let status = devenv.test();
let status = devenv.test().await;
let result = TestResult {
name: dir_name.to_string(),
passed: status.is_ok(),
Expand All @@ -135,10 +139,22 @@ fn run_tests_in_directory(args: &Args) -> Result<Vec<TestResult>, Box<dyn std::e
Ok(test_results)
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let args = Args::parse();

let test_results = run_tests_in_directory(&args)?;
let executable_path = std::env::current_exe()?;
let executable_dir = executable_path.parent().unwrap();
std::env::set_var(
"PATH",
format!(
"{}:{}",
executable_dir.display(),
std::env::var("PATH").unwrap_or_default()
),
);

let test_results = run_tests_in_directory(&args).await?;
let num_tests = test_results.len();
let num_failed_tests = test_results.iter().filter(|r| !r.passed).count();

Expand Down
2 changes: 2 additions & 0 deletions devenv.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
env.DEVENV_NIX = inputs.nix.packages.${pkgs.stdenv.system}.nix;
# ignore annoying browserlists warning that breaks pre-commit hooks
env.BROWSERSLIST_IGNORE_OLD_DATA = "1";
env.RUST_LOG = "devenv=debug";
env.RUST_LOG_SPAN_EVENTS = "full";

packages = [
pkgs.cairo
Expand Down
11 changes: 11 additions & 0 deletions devenv/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ default-run = "devenv"
ansiterm.workspace = true
clap.workspace = true
cli-table.workspace = true
crossterm = "0.28.1"
dotlock.workspace = true
fs2.workspace = true
hex.workspace = true
include_dir.workspace = true
indoc.workspace = true
miette.workspace = true
nix.workspace = true
petgraph = "0.6.5"
pretty_assertions = { version = "1.4.0", features = ["unstable"] }
regex.workspace = true
reqwest.workspace = true
schemars.workspace = true
Expand All @@ -29,6 +32,14 @@ serde_json.workspace = true
serde_yaml.workspace = true
sha2.workspace = true
tempdir.workspace = true
tempfile = "3.12.0"
test-log = { version = "0.2.16", features = ["trace"] }
thiserror = "1.0.63"
tokio = { version = "1.39.3", features = [
"process",
"macros",
"rt-multi-thread",
] }
tracing.workspace = true
which.workspace = true
whoami.workspace = true
Expand Down
6 changes: 6 additions & 0 deletions devenv/init/devenv.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
git --version
'';

# https://devenv.sh/tasks/
# tasks = {
# "myproj:setup".exec = "mytool build";
# "devenv:enterShell".after = [ "myproj:setup" ];
# };

# https://devenv.sh/tests/
enterTest = ''
echo "Running tests"
Expand Down
13 changes: 13 additions & 0 deletions devenv/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ pub(crate) enum Commands {
command: ProcessesCommand,
},

#[command(about = "Run tasks. https://devenv.sh/tasks/")]
Tasks {
#[command(subcommand)]
command: TasksCommand,
},

#[command(about = "Run tests. http://devenv.sh/tests/", alias = "ci")]
Test {
#[arg(short, long, help = "Don't override .devenv to a temporary directory.")]
Expand Down Expand Up @@ -241,6 +247,13 @@ pub(crate) enum ProcessesCommand {
// TODO: Status/Attach
}

#[derive(Subcommand, Clone)]
#[clap(about = "Run tasks. https://devenv.sh/tasks/")]
pub(crate) enum TasksCommand {
#[command(about = "Run tasks.")]
Run { tasks: Vec<String> },
}

#[derive(Subcommand, Clone)]
#[clap(
about = "Build, copy, or run a container. https://devenv.sh/containers/",
Expand Down
Loading

0 comments on commit 045c4c4

Please sign in to comment.