Skip to content

Commit

Permalink
feat(cli): add --deny to build, check, and docs
Browse files Browse the repository at this point in the history
This is useful for CI, where people that may have
a stricter workflow want to force CI to fail if any warnings
are detected.
  • Loading branch information
rvcas committed Sep 6, 2023
1 parent 819a0a2 commit 1de7b28
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## v1.0.17-alpha - unreleased

### Added

- **aiken**: add ability to force warnings to cause a failing exit code on check, build, and docs

### Fixed

- **uplc**: trim whitespace when loading files with hex strings to avoid confusing errors #720
Expand Down
2 changes: 1 addition & 1 deletion crates/aiken/src/cmd/blueprint/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub fn exec(
rebuild,
}: Args,
) -> miette::Result<()> {
with_project(directory, |p| {
with_project(directory, false, |p| {
if rebuild {
p.build(false, Tracing::NoTraces)?;
}
Expand Down
2 changes: 1 addition & 1 deletion crates/aiken/src/cmd/blueprint/apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub fn exec(
validator,
}: Args,
) -> miette::Result<()> {
with_project(None, |p| {
with_project(None, false, |p| {
let title = module.as_ref().map(|m| {
format!(
"{m}{}",
Expand Down
2 changes: 1 addition & 1 deletion crates/aiken/src/cmd/blueprint/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub fn exec(
rebuild,
}: Args,
) -> miette::Result<()> {
with_project(directory, |p| {
with_project(directory, false, |p| {
if rebuild {
p.build(false, Tracing::NoTraces)?;
}
Expand Down
2 changes: 1 addition & 1 deletion crates/aiken/src/cmd/blueprint/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub fn exec(
rebuild,
}: Args,
) -> miette::Result<()> {
with_project(directory, |p| {
with_project(directory, false, |p| {
if rebuild {
p.build(false, Tracing::NoTraces)?;
}
Expand Down
7 changes: 6 additions & 1 deletion crates/aiken/src/cmd/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ pub struct Args {
/// Path to project
directory: Option<PathBuf>,

/// Deny warnings; warnings will be treated as errors
#[clap(short = 'D', long)]
deny: bool,

/// Also dump textual uplc
#[clap(short, long)]
uplc: bool,
Expand All @@ -18,9 +22,10 @@ pub struct Args {
pub fn exec(
Args {
directory,
deny,
uplc,
keep_traces,
}: Args,
) -> miette::Result<()> {
crate::with_project(directory, |p| p.build(uplc, keep_traces.into()))
crate::with_project(directory, deny, |p| p.build(uplc, keep_traces.into()))
}
7 changes: 6 additions & 1 deletion crates/aiken/src/cmd/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ pub struct Args {
/// Path to project
directory: Option<PathBuf>,

/// Deny warnings; warnings will be treated as errors
#[clap(short = 'D', long)]
deny: bool,

/// Skip tests; run only the type-checker
#[clap(short, long)]
skip_tests: bool,
Expand Down Expand Up @@ -33,14 +37,15 @@ pub struct Args {
pub fn exec(
Args {
directory,
deny,
skip_tests,
debug,
match_tests,
exact_match,
no_traces,
}: Args,
) -> miette::Result<()> {
crate::with_project(directory, |p| {
crate::with_project(directory, deny, |p| {
p.check(
skip_tests,
match_tests.clone(),
Expand Down
7 changes: 6 additions & 1 deletion crates/aiken/src/cmd/docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ pub struct Args {
/// Path to project
directory: Option<PathBuf>,

/// Deny warnings; warnings will be treated as errors
#[clap(short = 'D', long)]
deny: bool,

/// Output directory for the documentation
#[clap(short = 'o', long)]
destination: Option<PathBuf>,
Expand All @@ -14,8 +18,9 @@ pub struct Args {
pub fn exec(
Args {
directory,
deny,
destination,
}: Args,
) -> miette::Result<()> {
crate::with_project(directory, |p| p.docs(destination.clone()))
crate::with_project(directory, deny, |p| p.docs(destination.clone()))
}
2 changes: 1 addition & 1 deletion crates/aiken/src/cmd/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ fn create_github_action(root: &Path) -> miette::Result<()> {
version: v{version}
- run: aiken fmt --check
- run: aiken check
- run: aiken check -D
- run: aiken build
"#,
version = built_info::PKG_VERSION,
Expand Down
9 changes: 7 additions & 2 deletions crates/aiken/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub mod built_info {
include!(concat!(env!("OUT_DIR"), "/built.rs"));
}

pub fn with_project<A>(directory: Option<PathBuf>, mut action: A) -> miette::Result<()>
pub fn with_project<A>(directory: Option<PathBuf>, deny: bool, mut action: A) -> miette::Result<()>
where
A: FnMut(&mut Project<Terminal>) -> Result<(), Vec<aiken_project::error::Error>>,
{
Expand All @@ -37,7 +37,7 @@ where

let warning_count = warnings.len();

for warning in warnings {
for warning in &warnings {
warning.report()
}

Expand Down Expand Up @@ -85,6 +85,11 @@ where
warning_text.if_supports_color(Stderr, |s| s.yellow()),
);
}

if warning_count > 0 && deny {
process::exit(1);
}

Ok(())
}

Expand Down

0 comments on commit 1de7b28

Please sign in to comment.