next_version/lib.rs
1//! Library to calculate next semantic version based on
2//! [conventional commits](https://www.conventionalcommits.org/).
3//!
4//! It does not analyze git history, the list of commits must be provided by the user.
5//!
6//! # Version changes
7//!
8//! ## Non conventional commits
9//!
10//! If conventional commits are not used, the patch is incremented.
11//!
12//! ```rust
13//! use semver::Version;
14//! use next_version::NextVersion;
15//!
16//! let commits = ["my change"];
17//! assert_eq!(Version::new(1, 2, 3).next(commits), Version::new(1, 2, 4));
18//! ```
19//!
20//! ## `0.0.x` versions
21//!
22//! In `0.0.x` versions the patch is always incremented:
23//!
24//! ```rust
25//! use semver::Version;
26//! use next_version::NextVersion;
27//!
28//! let commits = ["my change"];
29//! assert_eq!(Version::new(0, 0, 4).next(&commits), Version::new(0, 0, 5));
30//!
31//! let commits = ["feat!: break user"];
32//! assert_eq!(Version::new(0, 0, 1).next(&commits), Version::new(0, 0, 2));
33//! ```
34//!
35//! <div class="warning">We don't increase the minor version because the bump
36//! from <code>0.0.x</code> to <code>0.1.x</code>
37//! should be intentional (not automated) because the author communicates an higher level of
38//! API stability to the user.</div>
39//!
40//! ## Features
41//!
42//! If a feature comment is present:
43//! - If the major number is `0`: the patch is incremented.
44//! - Otherwise: the minor is incremented.
45//!
46//! ```rust
47//! use semver::Version;
48//! use next_version::NextVersion;
49//!
50//! let commits = ["my change", "feat: make coffe"];
51//! assert_eq!(Version::new(1, 2, 4).next(&commits), Version::new(1, 3, 0));
52//!
53//! assert_eq!(Version::new(0, 2, 4).next(&commits), Version::new(0, 2, 5));
54//! ```
55//!
56//! <div class="warning">When the major number is <code>0</code>,
57//! we don't increase the minor version because the bump from <code>0.x.y</code> to <code>0.(x+1).0</code>
58//! indicates a breaking change.</div>
59//!
60//! ## Breaking changes
61//!
62//! Breaking changes will increment:
63//! - major if major is not `0`.
64//! - minor if major is `0`.
65//!
66//! ```rust
67//! use semver::Version;
68//! use next_version::NextVersion;
69//!
70//! let commits = ["feat!: break user"];
71//! assert_eq!(Version::new(1, 2, 4).next(&commits), Version::new(2, 0, 0));
72//!
73//! assert_eq!(Version::new(0, 4, 4).next(&commits), Version::new(0, 5, 0));
74//! ```
75//!
76//! According to the [conventional commits specification](https://www.conventionalcommits.org/),
77//! breaking changes can also be specified in the footer:
78//!
79//! ```rust
80//! use semver::Version;
81//! use next_version::NextVersion;
82//!
83//! let breaking_commit = r#"feat: make coffe
84//!
85//! my change
86//!
87//! BREAKING CHANGE: user will be broken
88//! "#;
89//!
90//! let commits = [breaking_commit];
91//! assert_eq!(Version::new(1, 2, 4).next(&commits), Version::new(2, 0, 0));
92//! ```
93//!
94//! ## Pre-release
95//!
96//! Pre-release versions are incremented in the same way, independently
97//! by the type of commits:
98//!
99//! ```rust
100//! use semver::Version;
101//! use next_version::NextVersion;
102//!
103//! let commits = ["feat!: break user"];
104//! let version = Version::parse("1.0.0-alpha.1.2").unwrap();
105//! let expected = Version::parse("1.0.0-alpha.1.3").unwrap();
106//! assert_eq!(version.next(commits.clone()), expected);
107//!
108//! // If the pre-release doesn't contain a version, `.1` is appended.
109//! let version = Version::parse("1.0.0-beta").unwrap();
110//! let expected = Version::parse("1.0.0-beta.1").unwrap();
111//! assert_eq!(version.next(commits), expected);
112//!
113//! ```
114//!
115//! ## Build metadata
116//!
117//! Build metadata isn't modified.
118//!
119//! ```rust
120//! use semver::Version;
121//! use next_version::NextVersion;
122//!
123//! let commits = ["my change"];
124//! let version = Version::parse("1.0.0-beta.1+1.1.0").unwrap();
125//! let expected = Version::parse("1.0.0-beta.2+1.1.0").unwrap();
126//! assert_eq!(version.next(commits.clone()), expected);
127//!
128//! let version = Version::parse("1.0.0+abcd").unwrap();
129//! let expected = Version::parse("1.0.1+abcd").unwrap();
130//! assert_eq!(version.next(commits.clone()), expected);
131//! ```
132//!
133//! # Custom version increment
134//!
135//! If you don't like the default increment rules of the crate,
136//! you can customize them by using [`VersionUpdater`].
137
138mod next_version;
139mod version_increment;
140mod version_updater;
141
142pub use crate::{next_version::*, version_increment::*, version_updater::*};