Skip to content
Draft
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
451 changes: 1 addition & 450 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions crates/omnix-ci/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ omnix-health = { workspace = true }
nix_rs = { workspace = true, features = ["clap"] }
nonempty = { workspace = true }
omnix-common = { workspace = true }
reqwest = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
shell-words = { workspace = true }
Expand All @@ -35,6 +34,3 @@ thiserror = { workspace = true }
tokio = { workspace = true }
tracing = { workspace = true }
tracing-subscriber = { workspace = true }
try-guard = { workspace = true }
url = { workspace = true }
urlencoding = { workspace = true }
21 changes: 14 additions & 7 deletions crates/omnix-ci/src/command/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ use nix_rs::command::NixCmd;
use omnix_common::config::OmConfig;
use tracing::instrument;

use crate::flake_ref::FlakeRef;
use nix_rs::flake::url::FlakeUrl;

use super::{gh_matrix::GHMatrixCommand, run::RunCommand};

/// Top-level commands for `om ci`
#[derive(Debug, Subcommand, Clone)]
pub enum Command {
/// Run all CI steps for all or given subflakes
/// Run all CI steps for current directory flake
Run(RunCommand),

/// Print the Github Actions matrix configuration as JSON
Expand All @@ -31,7 +31,7 @@ impl Command {
#[instrument(name = "run", skip(self))]
pub async fn run(self) -> anyhow::Result<()> {
tracing::info!("{}", "\n👟 Reading om.ci config from flake".bold());
let url = self.get_flake_ref().to_flake_url().await?;
let url = self.get_flake_ref();
let cfg = OmConfig::get(self.nixcmd(), &url).await?;

tracing::debug!("OmConfig: {cfg:?}");
Expand All @@ -48,11 +48,18 @@ impl Command {
}
}

/// Get the [FlakeRef] associated with this subcommand
fn get_flake_ref(&self) -> &FlakeRef {
/// Get the [FlakeUrl] associated with this subcommand
fn get_flake_ref(&self) -> FlakeUrl {
let base_url = ".".to_string();
match self {
Command::Run(cmd) => &cmd.flake_ref,
Command::DumpGithubActionsMatrix(cmd) => &cmd.flake_ref,
Command::Run(cmd) => {
if let Some(config) = &cmd.config {
FlakeUrl(format!(".#{}", config))
} else {
FlakeUrl(base_url)
}
}
Command::DumpGithubActionsMatrix(_) => FlakeUrl(base_url),
}
}

Expand Down
9 changes: 1 addition & 8 deletions crates/omnix-ci/src/command/gh_matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,11 @@ use clap::Parser;
use nix_rs::{command::NixCmd, flake::system::System};
use omnix_common::config::OmConfig;

use crate::{config::subflakes::SubflakesConfig, flake_ref::FlakeRef, github};
use crate::{config::subflakes::SubflakesConfig, github};

/// Command to generate a Github Actions matrix
#[derive(Parser, Debug, Clone)]
pub struct GHMatrixCommand {
/// Flake URL or github URL
///
/// A specific omnix-ci configuration can be specified
/// using '#': e.g. `om ci run .#extra-tests`
#[arg(default_value = ".")]
pub flake_ref: FlakeRef,

/// Systems to include in the matrix
#[arg(long, value_parser, value_delimiter = ',')]
pub systems: Vec<System>,
Expand Down
29 changes: 12 additions & 17 deletions crates/omnix-ci/src/command/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ use omnix_health::{traits::Checkable, NixHealth};
use serde::{Deserialize, Serialize};

use crate::{
config::subflakes::SubflakesConfig, flake_ref::FlakeRef, github::actions::in_github_log_group,
config::subflakes::SubflakesConfig, github::actions::in_github_log_group,
step::core::StepsResult,
};

use super::run_remote;

/// Run all CI steps for all or given subflakes
/// Run all CI steps for current directory flake
/// Command to run all CI steps
#[derive(Parser, Debug, Clone)]
pub struct RunCommand {
Expand Down Expand Up @@ -61,17 +61,14 @@ pub struct RunCommand {
#[arg(long)]
no_link: bool,

/// Flake URL or github URL
///
/// A specific configuration can be specified
/// using '#': e.g. `om ci run .#default.extra-tests`
#[arg(default_value = ".")]
pub flake_ref: FlakeRef,

/// Print Github Actions log groups (enabled by default when run in Github Actions)
#[clap(long, default_value_t = env::var("GITHUB_ACTION").is_ok())]
pub github_output: bool,

/// CI configuration to use (e.g., "default.simple-example")
#[arg(help = "Specify which CI sub-configuration to run")]
pub config: Option<String>,

/// Arguments for all steps
#[command(flatten)]
pub steps_args: crate::step::core::StepsArgs,
Expand All @@ -97,11 +94,10 @@ impl RunCommand {
}
}

/// Override the `flake_ref` and `out_link`` for building locally.
pub fn local_with(&self, flake_ref: FlakeRef, out_link: Option<PathBuf>) -> Self {
/// Override the `out_link` for building locally.
pub fn local_with(&self, out_link: Option<PathBuf>) -> Self {
let mut new = self.clone();
new.on = None; // Disable remote building
new.flake_ref = flake_ref;
new.no_link = out_link.is_none();
new.out_link = out_link;
new
Expand Down Expand Up @@ -140,10 +136,7 @@ impl RunCommand {
.await?;

// Then, do the CI steps
tracing::info!(
"{}",
format!("\n🤖 Running CI for {}", self.flake_ref).bold()
);
tracing::info!("{}", "\n🤖 Running CI for current directory".bold());
let res = ci_run(&self.nixcmd, self, &cfg, &nix_info.nix_config).await?;

let msg = in_github_log_group::<anyhow::Result<String>, _, _>(
Expand Down Expand Up @@ -218,7 +211,9 @@ impl RunCommand {
args.push("--no-link".to_string());
}

args.push(self.flake_ref.to_string());
if let Some(config) = self.config.as_ref() {
args.push(config.clone());
}

args.extend(self.steps_args.to_cli_args());

Expand Down
12 changes: 3 additions & 9 deletions crates/omnix-ci/src/command/run_remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub async fn run_on_remote_store(
format!("\n🛜 Running CI remotely on {} ({:?})", ssh_uri, opts).bold()
);

let (flake_closure, local_flake_url) = &cache_flake(nixcmd, cfg, opts.copy_inputs).await?;
let (flake_closure, _local_flake_url) = &cache_flake(nixcmd, cfg, opts.copy_inputs).await?;
let omnix_source = PathBuf::from(OMNIX_SOURCE);

let paths_to_push = vec![omnix_source, flake_closure.clone()];
Expand All @@ -59,9 +59,7 @@ pub async fn run_on_remote_store(
// Then, SSH and run the same `om ci run` CLI but without the `--on` argument but with `--out-link` pointing to the temporary location.
run_ssh(
&ssh_uri.to_string(),
&om_cli_with(
run_cmd.local_with(local_flake_url.clone().into(), Some(om_json_path.clone())),
),
&om_cli_with(run_cmd.local_with(Some(om_json_path.clone()))),
)
.await?;

Expand Down Expand Up @@ -93,11 +91,7 @@ pub async fn run_on_remote_store(
);
} else {
// Then, SSH and run the same `om ci run` CLI but without the `--on` argument.
run_ssh(
&ssh_uri.to_string(),
&om_cli_with(run_cmd.local_with(local_flake_url.clone().into(), None)),
)
.await?;
run_ssh(&ssh_uri.to_string(), &om_cli_with(run_cmd.local_with(None))).await?;
}
Ok(())
}
Expand Down
93 changes: 0 additions & 93 deletions crates/omnix-ci/src/flake_ref.rs

This file was deleted.

1 change: 0 additions & 1 deletion crates/omnix-ci/src/github/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//! GitHub related types and functions.
pub mod actions;
pub mod matrix;
pub mod pull_request;
Loading