#semver #semantic #versioning #conventional #commits

next_version

Determine next semantic version based on conventional commits

15 releases

0.2.3 Mar 13, 2023
0.2.1 Feb 26, 2023
0.1.10 Dec 17, 2022
0.1.9 Nov 4, 2022
0.1.1 Mar 27, 2022

#852 in Development tools

Download history 158/week @ 2022-11-29 174/week @ 2022-12-06 108/week @ 2022-12-13 48/week @ 2022-12-20 47/week @ 2022-12-27 182/week @ 2023-01-03 195/week @ 2023-01-10 360/week @ 2023-01-17 185/week @ 2023-01-24 112/week @ 2023-01-31 102/week @ 2023-02-07 172/week @ 2023-02-14 221/week @ 2023-02-21 139/week @ 2023-02-28 55/week @ 2023-03-07 55/week @ 2023-03-14

497 downloads per month
Used in 2 crates (via release_plz_core)

MIT/Apache

13KB
144 lines

next_version

Library to calculate next semantic version based on conventional commits.

It does not analyze git history, the list of commits must be provided by the user.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

See CONTRIBUTING.md.

Credits

Parts of the codebase are inspired by cocogitto.


lib.rs:

Library to calculate next semantic version based on conventional commits.

It does not analyze git history, the list of commits must be provided by the user.

Version changes

If conventional commits are not used, the patch is incremented.

use semver::Version;
use next_version::NextVersion;

let commits = vec!["my change"];
assert_eq!(Version::new(1, 2, 3).next(commits), Version::new(1, 2, 4));

If a feature comment, is present and the major number is not 1, than the minor is incremented

use semver::Version;
use next_version::NextVersion;

let commits = vec!["my change", "feat: make coffe"];
assert_eq!(Version::new(1, 2, 4).next(&commits), Version::new(1, 3, 0));

assert_eq!(Version::new(0, 2, 4).next(&commits), Version::new(0, 2, 5));

Breaking changes will increment:

  • major if major is not 0.
  • minor if major is 0.
use semver::Version;
use next_version::NextVersion;

let commits = vec!["feat!: break user"];
assert_eq!(Version::new(1, 2, 4).next(&commits), Version::new(2, 0, 0));

assert_eq!(Version::new(0, 4, 4).next(&commits), Version::new(0, 5, 0));

In 0.0.x versions the patch is always incremented:

use semver::Version;
use next_version::NextVersion;

let commits = vec!["my change"];
assert_eq!(Version::new(0, 0, 4).next(&commits), Version::new(0, 0, 5));

let commits = vec!["feat!: break user"];
assert_eq!(Version::new(0, 0, 1).next(&commits), Version::new(0, 0, 2));

Pre-release versions are incremented in the same way, independently by the type of commits:

use semver::Version;
use next_version::NextVersion;

let commits = vec!["feat!: break user"];
let version = Version::parse("1.0.0-alpha.1.2").unwrap();
let expected = Version::parse("1.0.0-alpha.1.3").unwrap();
assert_eq!(version.next(commits.clone()), expected);

// If the pre-release doesn't contain a version, `.1` is appended.
let version = Version::parse("1.0.0-beta").unwrap();
let expected = Version::parse("1.0.0-beta.1").unwrap();
assert_eq!(version.next(commits), expected);

Build metadata isn't modified.

use semver::Version;
use next_version::NextVersion;

let commits = vec!["my change"];
let version = Version::parse("1.0.0-beta.1+1.1.0").unwrap();
let expected = Version::parse("1.0.0-beta.2+1.1.0").unwrap();
assert_eq!(version.next(commits.clone()), expected);

let version = Version::parse("1.0.0+abcd").unwrap();
let expected = Version::parse("1.0.1+abcd").unwrap();
assert_eq!(version.next(commits.clone()), expected);

Dependencies

~3MB
~59K SLoC