diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-02-22 21:19:35 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-02-22 21:19:35 +0900 |
| commit | 50218dc68c1e8b1e6b5e5619c5ddb297012c3c15 (patch) | |
| tree | 4e6b6342b1082e8f4e929ee7397731461716cc22 /crates/mozart/src | |
| parent | 2ee14562e344a26504e16c12d380db1e016e9869 (diff) | |
| download | php-mozart-50218dc68c1e8b1e6b5e5619c5ddb297012c3c15.tar.gz php-mozart-50218dc68c1e8b1e6b5e5619c5ddb297012c3c15.tar.zst php-mozart-50218dc68c1e8b1e6b5e5619c5ddb297012c3c15.zip | |
fix(bump): return exit code 1 on dry-run with changes and warn when type is absent
Match Composer behavior: --dry-run now returns exit code 1 when
un-bumped constraints are detected (useful for CI). Also warn when
the package type field is missing, since Composer treats it as
"library" by default.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Diffstat (limited to 'crates/mozart/src')
| -rw-r--r-- | crates/mozart/src/commands/bump.rs | 47 |
1 files changed, 35 insertions, 12 deletions
diff --git a/crates/mozart/src/commands/bump.rs b/crates/mozart/src/commands/bump.rs index 42b0d82..105379f 100644 --- a/crates/mozart/src/commands/bump.rs +++ b/crates/mozart/src/commands/bump.rs @@ -48,16 +48,29 @@ pub async fn execute( serde_json::from_str(&composer_json_content)?; // Warn if package is not a project (libraries shouldn't bump) - if let Some(ref pkg_type) = root.package_type - && pkg_type != "project" - { - console.info(&format!( - "{}", - mozart_core::console::warning(&format!( - "Warning: Bumping constraints for a non-project package (type=\"{pkg_type}\"). \ - Libraries should not pin their dependencies." - )) - )); + match root.package_type.as_deref() { + Some("project") => {} + Some(pkg_type) => { + console.info(&format!( + "{}", + mozart_core::console::warning(&format!( + "Warning: Bumping constraints for a non-project package (type=\"{pkg_type}\"). \ + Libraries should not pin their dependencies." + )) + )); + } + None if !args.dev_only => { + console.info(&format!( + "{}", + mozart_core::console::warning( + "Warning: Bumping constraints for a non-project package. \ + No type was set so it defaults to \"library\". \ + Libraries should not pin their dependencies. \ + Consider using --dev-only or setting the type to \"project\"." + ) + )); + } + None => {} } // Check lock file existence @@ -171,7 +184,10 @@ pub async fn execute( if args.dry_run { println!("\n{} constraint(s) would be bumped.", total_changes); - return Ok(()); + // Return exit code 1 when dry-run detects changes (useful for CI to detect un-bumped constraints) + return Err(mozart_core::exit_code::bail_silent( + mozart_core::exit_code::GENERAL_ERROR, + )); } // Apply changes to root package @@ -387,7 +403,14 @@ mod tests { verbosity: mozart_core::console::Verbosity::Normal, decorated: false, }; - execute(&args, &cli, &console).await.unwrap(); + let result = execute(&args, &cli, &console).await; + + // dry-run with changes returns exit code 1 (for CI usage) + let err = result.unwrap_err(); + let mozart_err = err + .downcast_ref::<mozart_core::exit_code::MozartError>() + .expect("should be MozartError"); + assert_eq!(mozart_err.exit_code, mozart_core::exit_code::GENERAL_ERROR); // composer.json should be unchanged let content = std::fs::read_to_string(dir.path().join("composer.json")).unwrap(); |
