feat(cli): add --deny to build, check, and docs

This is useful for CI, where people that may have
a stricter workflow want to force CI to fail if any warnings
are detected.
This commit is contained in:
rvcas 2023-09-06 17:19:44 -04:00
parent 819a0a20e6
commit 1de7b2866a
No known key found for this signature in database
GPG Key ID: C09B64E263F7D68C
10 changed files with 34 additions and 10 deletions

View File

@ -2,6 +2,10 @@
## v1.0.17-alpha - unreleased ## v1.0.17-alpha - unreleased
### Added
- **aiken**: add ability to force warnings to cause a failing exit code on check, build, and docs
### Fixed ### Fixed
- **uplc**: trim whitespace when loading files with hex strings to avoid confusing errors #720 - **uplc**: trim whitespace when loading files with hex strings to avoid confusing errors #720

View File

@ -34,7 +34,7 @@ pub fn exec(
rebuild, rebuild,
}: Args, }: Args,
) -> miette::Result<()> { ) -> miette::Result<()> {
with_project(directory, |p| { with_project(directory, false, |p| {
if rebuild { if rebuild {
p.build(false, Tracing::NoTraces)?; p.build(false, Tracing::NoTraces)?;
} }

View File

@ -48,7 +48,7 @@ pub fn exec(
validator, validator,
}: Args, }: Args,
) -> miette::Result<()> { ) -> miette::Result<()> {
with_project(None, |p| { with_project(None, false, |p| {
let title = module.as_ref().map(|m| { let title = module.as_ref().map(|m| {
format!( format!(
"{m}{}", "{m}{}",

View File

@ -29,7 +29,7 @@ pub fn exec(
rebuild, rebuild,
}: Args, }: Args,
) -> miette::Result<()> { ) -> miette::Result<()> {
with_project(directory, |p| { with_project(directory, false, |p| {
if rebuild { if rebuild {
p.build(false, Tracing::NoTraces)?; p.build(false, Tracing::NoTraces)?;
} }

View File

@ -29,7 +29,7 @@ pub fn exec(
rebuild, rebuild,
}: Args, }: Args,
) -> miette::Result<()> { ) -> miette::Result<()> {
with_project(directory, |p| { with_project(directory, false, |p| {
if rebuild { if rebuild {
p.build(false, Tracing::NoTraces)?; p.build(false, Tracing::NoTraces)?;
} }

View File

@ -6,6 +6,10 @@ pub struct Args {
/// Path to project /// Path to project
directory: Option<PathBuf>, directory: Option<PathBuf>,
/// Deny warnings; warnings will be treated as errors
#[clap(short = 'D', long)]
deny: bool,
/// Also dump textual uplc /// Also dump textual uplc
#[clap(short, long)] #[clap(short, long)]
uplc: bool, uplc: bool,
@ -18,9 +22,10 @@ pub struct Args {
pub fn exec( pub fn exec(
Args { Args {
directory, directory,
deny,
uplc, uplc,
keep_traces, keep_traces,
}: Args, }: Args,
) -> miette::Result<()> { ) -> 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()))
} }

View File

@ -6,6 +6,10 @@ pub struct Args {
/// Path to project /// Path to project
directory: Option<PathBuf>, directory: Option<PathBuf>,
/// Deny warnings; warnings will be treated as errors
#[clap(short = 'D', long)]
deny: bool,
/// Skip tests; run only the type-checker /// Skip tests; run only the type-checker
#[clap(short, long)] #[clap(short, long)]
skip_tests: bool, skip_tests: bool,
@ -33,6 +37,7 @@ pub struct Args {
pub fn exec( pub fn exec(
Args { Args {
directory, directory,
deny,
skip_tests, skip_tests,
debug, debug,
match_tests, match_tests,
@ -40,7 +45,7 @@ pub fn exec(
no_traces, no_traces,
}: Args, }: Args,
) -> miette::Result<()> { ) -> miette::Result<()> {
crate::with_project(directory, |p| { crate::with_project(directory, deny, |p| {
p.check( p.check(
skip_tests, skip_tests,
match_tests.clone(), match_tests.clone(),

View File

@ -6,6 +6,10 @@ pub struct Args {
/// Path to project /// Path to project
directory: Option<PathBuf>, directory: Option<PathBuf>,
/// Deny warnings; warnings will be treated as errors
#[clap(short = 'D', long)]
deny: bool,
/// Output directory for the documentation /// Output directory for the documentation
#[clap(short = 'o', long)] #[clap(short = 'o', long)]
destination: Option<PathBuf>, destination: Option<PathBuf>,
@ -14,8 +18,9 @@ pub struct Args {
pub fn exec( pub fn exec(
Args { Args {
directory, directory,
deny,
destination, destination,
}: Args, }: Args,
) -> miette::Result<()> { ) -> miette::Result<()> {
crate::with_project(directory, |p| p.docs(destination.clone())) crate::with_project(directory, deny, |p| p.docs(destination.clone()))
} }

View File

@ -199,7 +199,7 @@ fn create_github_action(root: &Path) -> miette::Result<()> {
version: v{version} version: v{version}
- run: aiken fmt --check - run: aiken fmt --check
- run: aiken check - run: aiken check -D
- run: aiken build - run: aiken build
"#, "#,
version = built_info::PKG_VERSION, version = built_info::PKG_VERSION,

View File

@ -13,7 +13,7 @@ pub mod built_info {
include!(concat!(env!("OUT_DIR"), "/built.rs")); 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 where
A: FnMut(&mut Project<Terminal>) -> Result<(), Vec<aiken_project::error::Error>>, A: FnMut(&mut Project<Terminal>) -> Result<(), Vec<aiken_project::error::Error>>,
{ {
@ -37,7 +37,7 @@ where
let warning_count = warnings.len(); let warning_count = warnings.len();
for warning in warnings { for warning in &warnings {
warning.report() warning.report()
} }
@ -85,6 +85,11 @@ where
warning_text.if_supports_color(Stderr, |s| s.yellow()), warning_text.if_supports_color(Stderr, |s| s.yellow()),
); );
} }
if warning_count > 0 && deny {
process::exit(1);
}
Ok(()) Ok(())
} }