Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output lint summary after build #958

Open
wants to merge 1 commit into
base: spk-lint-update
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion crates/spk-cli/cmd-build/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ spfs = { workspace = true }
spk-cli-common = { workspace = true }
spk-cmd-make-binary = { workspace = true }
spk-cmd-make-source = { workspace = true }
spk-schema = { workspace = true }
tracing = { workspace = true }

[dev-dependencies]
rstest = { workspace = true }
spk-schema = { workspace = true }
spk-storage = { workspace = true }
tempfile = { workspace = true }
tokio = { workspace = true }
19 changes: 19 additions & 0 deletions crates/spk-cli/cmd-build/src/cmd_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
// SPDX-License-Identifier: Apache-2.0
// https://github.com/spkenv/spk

use std::collections::BTreeMap;

use clap::Args;
use miette::Result;
use spk_cli_common::{flags, CommandArgs, Run};
use spk_cmd_make_binary::cmd_make_binary::PackageSpecifier;
use spk_schema::Lint::Key;

#[cfg(test)]
#[path = "./cmd_build_test/mod.rs"]
Expand Down Expand Up @@ -83,17 +86,22 @@ impl Run for Build {
}

let mut builds_for_summary = spk_cli_common::BuildResult::default();
let mut generated_lints = BTreeMap::new();

for packages in runs {
let mut make_source = spk_cmd_make_source::cmd_make_source::MakeSource {
options: self.options.clone(),
verbose: self.verbose,
packages: packages.clone(),
runtime: self.runtime.clone(),
created_src: spk_cli_common::BuildResult::default(),
lints: BTreeMap::new(),
};
let idents = make_source.make_source().await?;
builds_for_summary.extend(make_source.created_src);

generated_lints.extend(std::mem::take(&mut make_source.lints));

let mut make_binary = spk_cmd_make_binary::cmd_make_binary::MakeBinary {
verbose: self.verbose,
runtime: self.runtime.clone(),
Expand Down Expand Up @@ -129,6 +137,17 @@ impl Run for Build {
println!(" {artifact}");
}

if !generated_lints.is_empty() {
println!("Lints:");
for (pkg, lints) in generated_lints.iter() {
for lint in lints.iter() {
match lint {
Key(k) => tracing::warn!("{} {}", pkg, k.generate_message()),
}
}
}
}

Ok(BuildResult {
exit_status: 0,
created_builds: builds_for_summary,
Expand Down
1 change: 1 addition & 0 deletions crates/spk-cli/cmd-make-source/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ migration-to-components = [
miette = { workspace = true, features = ["fancy"] }
async-trait = { workspace = true }
clap = { workspace = true }
serde_yaml = { workspace = true }
spfs = { workspace = true }
spk-build = { workspace = true }
spk-cli-common = { workspace = true }
Expand Down
32 changes: 31 additions & 1 deletion crates/spk-cli/cmd-make-source/src/cmd_make_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
// https://github.com/spkenv/spk

use std::collections::BTreeMap;
use std::path::PathBuf;
use std::sync::Arc;

Expand All @@ -11,7 +12,17 @@ use spk_build::SourcePackageBuilder;
use spk_cli_common::{flags, BuildArtifact, BuildResult, CommandArgs, Run};
use spk_schema::foundation::format::FormatIdent;
use spk_schema::ident::LocatedBuildIdent;
use spk_schema::{Package, Recipe, SpecTemplate, Template, TemplateExt};
use spk_schema::v0::Spec;
use spk_schema::{
AnyIdent,
Lint,
LintedItem,
Package,
Recipe,
SpecTemplate,
Template,
TemplateExt,
};
use spk_storage as storage;

/// Build a source package from a spec file.
Expand All @@ -34,6 +45,10 @@ pub struct MakeSource {
/// Populated with the created src to generate a summary from the caller.
#[clap(skip)]
pub created_src: BuildResult,

/// Used to gather lints to output at the end of a build.
#[clap(skip)]
pub lints: BTreeMap<String, Vec<Lint>>,
}

#[async_trait::async_trait]
Expand Down Expand Up @@ -81,6 +96,7 @@ impl MakeSource {
template
}
};

let root = template
.file_path()
.parent()
Expand All @@ -100,6 +116,20 @@ impl MakeSource {
})?;
let ident = recipe.ident();

let lints: std::result::Result<LintedItem<Spec<AnyIdent>>, serde_yaml::Error> =
serde_yaml::from_str(&template.render_to_string(&options)?);

match lints {
Ok(linted_item) => match linted_item.lints.is_empty() {
true => (),
false => {
self.lints
.insert(ident.format_ident(), linted_item.lints.clone());
}
},
Err(e) => tracing::error!("Failed to retrieve lints: {e}"),
}

tracing::info!("saving package recipe for {}", ident.format_ident());
local.force_publish_recipe(&recipe).await?;

Expand Down
Loading