Crate nextsv

Source
Expand description

§Calculate next semantic bump and/or version number

Calculates the next semantic bump and/or version number based on the current version number and the conventional commits made since the last version has been released.

§Usage

Add the dependency to Cargo.toml

[dependencies]
nextsv = "0.19.22"

Calculation workflow:

  1. Create the configuration
  2. Build the calculator
  3. Report the calculation

Report the results from the calculator

    // arguments collected from CLI
    let args = Args {
        prefix: String::from("v"),
        level: true,
        number: true,
        force: None,
        require: vec![OsString::from("README.md"), OsString::from("CHANGES.md"), ],
        enforce_level: Hierarchy::Feature,
        check: None,
    };

    // 1. Create the configuration

    let mut calculator_config = CalculatorConfig::new();

    // Set the version number prefix
    calculator_config = calculator_config.set_prefix(&args.prefix);

    // What do we want to output?    
    calculator_config = calculator_config.set_bump_report(args.level);
    calculator_config = calculator_config.set_version_report(args.number);

    // Is the bump level being forced?
    if let Some(force) = args.force {
        calculator_config = calculator_config.set_force_bump(force);
    };

    // Are there files that must be updated? What change level should they be enforced at?
    if !args.require.is_empty() {
        calculator_config = calculator_config.add_required_files(args.require);
        calculator_config = calculator_config.set_required_enforcement(args.enforce_level);
    };

    // Is three a threshold set that must be met before proceeding with a change?
    if let Some(check_level) = args.check {
        calculator_config = calculator_config.set_reporting_threshold(check_level);
    }

    // 2. Build the calculator
    // Apply the config and create a calculator
    let calculator = calculator_config.build()?;
     
    // 3. Report the calculations
    println!("{}", calculator.report());

Structs§

Calculator
Used to calculate the bump and next version number.
CalculatorConfig
Captures the user configuration set for the bump and version number calculation
Workspace
Represents the Cargo.toml of the workspace

Enums§

Error
The error type for nextsv.
ForceBump
This enum is used by CalculatorConfig::set_force_bump to override the bump that would be calculated from conventional commits.
Hierarchy
The Hierarchy enum provides a hieracchy for commit types that maps to the levels of Major, Minor and Patch levels of semver. The top level is for breaking commits and would be mapped to a Major version change for a new production release.