Skip to content

Commit

Permalink
factor out
Browse files Browse the repository at this point in the history
  • Loading branch information
srid committed Mar 25, 2024
1 parent 1ab4b14 commit e5e346b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
31 changes: 14 additions & 17 deletions src/github/matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use nix_rs::flake::system::System;
use serde::{Deserialize, Serialize};

use crate::config::Config;
use crate::config::Subflakes;

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct GitHubMatrixRow {
Expand All @@ -15,22 +15,19 @@ pub struct GitHubMatrix {
pub include: Vec<GitHubMatrixRow>,
}

pub(crate) async fn dump_github_actions_matrix(
cfg: &Config,
systems: Vec<System>,
) -> anyhow::Result<()> {
let include: Vec<GitHubMatrixRow> = systems
.iter()
.flat_map(|system| {
cfg.subflakes.0.iter().filter_map(|(k, v)| {
v.can_build_on(&[system.clone()]).then(|| GitHubMatrixRow {
system: system.clone(), // Only clone system here if necessary.
subflake: k.clone(), // Assuming k needs to be owned here.
impl GitHubMatrix {
pub fn from(systems: Vec<System>, subflakes: &Subflakes) -> Self {
let include: Vec<GitHubMatrixRow> = systems
.iter()
.flat_map(|system| {
subflakes.0.iter().filter_map(|(k, v)| {
v.can_build_on(&[system.clone()]).then(|| GitHubMatrixRow {
system: system.clone(),
subflake: k.clone(),
})
})
})
})
.collect();
let matrix = GitHubMatrix { include };
println!("{}", serde_json::to_string(&matrix)?);
Ok(())
.collect();
GitHubMatrix { include }
}
}
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ pub async fn nixci(args: CliArgs) -> anyhow::Result<Vec<DrvOut>> {
match args.command {
cli::Command::Build(build_cfg) => nixci_build(args.verbose, &build_cfg, &url, &cfg).await,
cli::Command::DumpGithubActionsMatrix { systems, .. } => {
github::matrix::dump_github_actions_matrix(&cfg, systems).await?;
let matrix = github::matrix::GitHubMatrix::from(systems, &cfg.subflakes);
println!("{}", serde_json::to_string(&matrix)?);
// TODO: Return something meaningful, or break the function.
Ok(vec![])
}
Expand Down

0 comments on commit e5e346b

Please sign in to comment.