Skip to content

Commit

Permalink
WIP tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
domenkozar committed Aug 23, 2024
1 parent b285601 commit bfd5290
Show file tree
Hide file tree
Showing 14 changed files with 1,326 additions and 53 deletions.
407 changes: 357 additions & 50 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions devenv.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{ inputs, pkgs, lib, config, ... }: {
env.DEVENV_NIX = inputs.nix.packages.${pkgs.stdenv.system}.nix;
env.RUST_LOG = "devenv=debug";
env.RUST_LOG_SPAN_EVENTS = "full";

packages = [
pkgs.cairo
Expand Down Expand Up @@ -208,6 +210,10 @@ EOF
'';
};


tasks.sleep.exec = "sleep 10";
tasks.sleep.depends = [ "enterShell" ];

pre-commit.hooks = {
nixpkgs-fmt.enable = true;
#shellcheck.enable = true;
Expand Down
11 changes: 11 additions & 0 deletions devenv/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@ license.workspace = true

[dependencies]
ansiterm.workspace = true
assert_matches = "1.5.0"
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"
regex.workspace = true
reqwest.workspace = true
schemars.workspace = true
Expand All @@ -25,6 +28,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
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
37 changes: 36 additions & 1 deletion devenv/src/devenv.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::{cli, command, config, log};
use super::{cli, command, config, log, tasks};
use clap::crate_version;
use cli_table::Table;
use cli_table::{print_stderr, WithTitle};
Expand Down Expand Up @@ -566,6 +566,41 @@ impl Devenv {
Ok(self.has_processes.unwrap())
}

pub async fn tasks_run(&mut self, roots: Vec<String>) -> Result<()> {
if roots.is_empty() {
bail!("No tasks specified.");
}
let config = {
let _logprogress = self.log_progress.with_newline("Evaluating tasks");
self.run_nix(
"nix",
&[
"build",
".#devenv.task.config",
"--no-link",
"--print-out-paths",
],
&command::Options::default(),
)?
};
// parse tasks config
let config_content =
std::fs::read_to_string(String::from_utf8_lossy(&config.stdout).trim())
.expect("Failed to read config file");
let tasks: Vec<tasks::TaskConfig> =
serde_json::from_str(&config_content).expect("Failed to parse tasks config");
// run tasks
let config = tasks::Config { roots, tasks };
let mut tui = tasks::TasksUi::new(config).await?;
let tasks_status = tui.run().await?;

if tasks_status.failed > 0 || tasks_status.dependency_failed > 0 {
Err(miette::bail!("Some tasks failed"))
} else {
Ok(())
}
}

pub fn test(&mut self) -> Result<()> {
self.assemble(true)?;

Expand Down
3 changes: 3 additions & 0 deletions devenv/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#[macro_use]
extern crate assert_matches;
mod cli;
pub mod command;
pub mod config;
mod devenv;
pub mod log;
pub mod tasks;

pub use cli::{default_system, GlobalOptions};
pub use devenv::{Devenv, DevenvOptions};
9 changes: 7 additions & 2 deletions devenv/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ mod command;
mod config;
mod devenv;
mod log;
mod tasks;

use clap::{crate_version, Parser};
use cli::{Cli, Commands, ContainerCommand, InputsCommand, ProcessesCommand};
use cli::{Cli, Commands, ContainerCommand, InputsCommand, ProcessesCommand, TasksCommand};
use devenv::Devenv;
use miette::Result;

fn main() -> Result<()> {
#[tokio::main]
async fn main() -> Result<()> {
let cli = Cli::parse();

let level = if cli.global_options.verbose {
Expand Down Expand Up @@ -126,6 +128,9 @@ fn main() -> Result<()> {
}
ProcessesCommand::Down {} => devenv.down(),
},
Commands::Tasks { command } => match command {
TasksCommand::Run { tasks } => devenv.tasks_run(tasks).await,
},
Commands::Inputs { command } => match command {
InputsCommand::Add { name, url, follows } => devenv.inputs_add(&name, &url, &follows),
},
Expand Down
Loading

0 comments on commit bfd5290

Please sign in to comment.