Given a version number MAJOR.MINOR.PATCH, increment the:
Additional labels for pre-release and build metadata are available as extensionsto the MAJOR.MINOR.PATCH format.
In the world of software management there exists a dreaded place called“dependency hell.” The bigger your system grows and the more packages youintegrate into your software, the more likely you are to find yourself, oneday, in this pit of despair.
In systems with many dependencies, releasing new package versions can quicklybecome a nightmare. If the dependency specifications are too tight, you are indanger of version lock (the inability to upgrade a package without having torelease new versions of every dependent package). If dependencies arespecified too loosely, you will inevitably be bitten by version promiscuity(assuming compatibility with more future versions than is reasonable).Dependency hell is where you are when version lock and/or version promiscuityprevent you from easily and safely moving your project forward.
As a solution to this problem, we propose a simple set of rules andrequirements that dictate how version numbers are assigned and incremented.These rules are based on but not necessarily limited to pre-existingwidespread common practices in use in both closed and open-source software.For this system to work, you first need to declare a public API. This mayconsist of documentation or be enforced by the code itself. Regardless, it isimportant that this API be clear and precise. Once you identify your publicAPI, you communicate changes to it with specific increments to your versionnumber. Consider a version format of X.Y.Z (Major.Minor.Patch). Bug fixes notaffecting the API increment the patch version, backward compatible APIadditions/changes increment the minor version, and backward incompatible APIchanges increment the major version.
We call this system “Semantic Versioning.” Under this scheme, version numbersand the way they change convey meaning about the underlying code and what hasbeen modified from one version to the next.
The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”,“SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to beinterpreted as described inRFC 2119.
Software using Semantic Versioning MUST declare a public API. This APIcould be declared in the code itself or exist strictly in documentation.However it is done, it SHOULD be precise and comprehensive.
A normal version number MUST take the form X.Y.Z where X, Y, and Z arenon-negative integers, and MUST NOT contain leading zeroes. X is themajor version, Y is the minor version, and Z is the patch version.Each element MUST increase numerically. For instance: 1.9.0 -> 1.10.0 -> 1.11.0.
Once a versioned package has been released, the contents of that versionMUST NOT be modified. Any modifications MUST be released as a new version.
Major version zero (0.y.z) is for initial development. Anything MAY changeat any time. The public API SHOULD NOT be considered stable.
Version 1.0.0 defines the public API. The way in which the version numberis incremented after this release is dependent on this public API and how itchanges.
Patch version Z (x.y.Z | x > 0) MUST be incremented if only backwardcompatible bug fixes are introduced. A bug fix is defined as an internalchange that fixes incorrect behavior.
Minor version Y (x.Y.z | x > 0) MUST be incremented if new, backwardcompatible functionality is introduced to the public API. It MUST beincremented if any public API functionality is marked as deprecated. It MAY beincremented if substantial new functionality or improvements are introducedwithin the private code. It MAY include patch level changes. Patch versionMUST be reset to 0 when minor version is incremented.
Major version X (X.y.z | X > 0) MUST be incremented if any backwardincompatible changes are introduced to the public API. It MAY also include minorand patch level changes. Patch and minor versions MUST be reset to 0 when majorversion is incremented.
A pre-release version MAY be denoted by appending a hyphen and aseries of dot separated identifiers immediately following the patchversion. Identifiers MUST comprise only ASCII alphanumerics and hyphens[0-9A-Za-z-]. Identifiers MUST NOT be empty. Numeric identifiers MUSTNOT include leading zeroes. Pre-release versions have a lowerprecedence than the associated normal version. A pre-release versionindicates that the version is unstable and might not satisfy theintended compatibility requirements as denoted by its associatednormal version. Examples: 1.0.0-alpha, 1.0.0-alpha.1, 1.0.0-0.3.7,1.0.0-x.7.z.92, 1.0.0-x-y-z.--.
Build metadata MAY be denoted by appending a plus sign and a series of dotseparated identifiers immediately following the patch or pre-release version.Identifiers MUST comprise only ASCII alphanumerics and hyphens [0-9A-Za-z-].Identifiers MUST NOT be empty. Build metadata MUST be ignored when determiningversion precedence. Thus two versions that differ only in the build metadata,have the same precedence. Examples: 1.0.0-alpha+001, 1.0.0+20130313144700,1.0.0-beta+exp.sha.5114f85, 1.0.0+21AF26D3----117B344092BD.
Precedence refers to how versions are compared to each other when ordered.
Precedence MUST be calculated by separating the version into major,minor, patch and pre-release identifiers in that order (Build metadatadoes not figure into precedence).
Precedence is determined by the first difference when comparing each ofthese identifiers from left to right as follows: Major, minor, and patchversions are always compared numerically.
Example: 1.0.0 < 2.0.0 < 2.1.0 < 2.1.1.
When major, minor, and patch are equal, a pre-release version has lowerprecedence than a normal version:
Example: 1.0.0-alpha < 1.0.0.
Precedence for two pre-release versions with the same major, minor, andpatch version MUST be determined by comparing each dot separated identifierfrom left to right until a difference is found as follows:
Identifiers consisting of only digits are compared numerically.
Identifiers with letters or hyphens are compared lexically in ASCIIsort order.
Numeric identifiers always have lower precedence than non-numericidentifiers.
A larger set of pre-release fields has a higher precedence than asmaller set, if all of the preceding identifiers are equal.
Example: 1.0.0-alpha < 1.0.0-alpha.1 < 1.0.0-alpha.beta < 1.0.0-beta < 1.0.0-beta.2 < 1.0.0-beta.11 < 1.0.0-rc.1 < 1.0.0.
<valid semver> ::= <version core> | <version core> "-" <pre-release> | <version core> "+" <build> | <version core> "-" <pre-release> "+" <build><version core> ::= <major> "." <minor> "." <patch><major> ::= <numeric identifier><minor> ::= <numeric identifier><patch> ::= <numeric identifier><pre-release> ::= <dot-separated pre-release identifiers><dot-separated pre-release identifiers> ::= <pre-release identifier> | <pre-release identifier> "." <dot-separated pre-release identifiers><build> ::= <dot-separated build identifiers><dot-separated build identifiers> ::= <build identifier> | <build identifier> "." <dot-separated build identifiers><pre-release identifier> ::= <alphanumeric identifier> | <numeric identifier><build identifier> ::= <alphanumeric identifier> | <digits><alphanumeric identifier> ::= <non-digit> | <non-digit> <identifier characters> | <identifier characters> <non-digit> | <identifier characters> <non-digit> <identifier characters><numeric identifier> ::= "0" | <positive digit> | <positive digit> <digits><identifier characters> ::= <identifier character> | <identifier character> <identifier characters><identifier character> ::= <digit> | <non-digit><non-digit> ::= <letter> | "-"<digits> ::= <digit> | <digit> <digits><digit> ::= "0" | <positive digit><positive digit> ::= "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"<letter> ::= "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z" | "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z"
This is not a new or revolutionary idea. In fact, you probably do somethingclose to this already. The problem is that “close” isn’t good enough. Withoutcompliance to some sort of formal specification, version numbers areessentially useless for dependency management. By giving a name and cleardefinition to the above ideas, it becomes easy to communicate your intentionsto the users of your software. Once these intentions are clear, flexible (butnot too flexible) dependency specifications can finally be made.
A simple example will demonstrate how Semantic Versioning can make dependencyhell a thing of the past. Consider a library called “Firetruck.” It requires aSemantically Versioned package named “Ladder.” At the time that Firetruck iscreated, Ladder is at version 3.1.0. Since Firetruck uses some functionalitythat was first introduced in 3.1.0, you can safely specify the Ladderdependency as greater than or equal to 3.1.0 but less than 4.0.0. Now, whenLadder version 3.1.1 and 3.2.0 become available, you can release them to yourpackage management system and know that they will be compatible with existingdependent software.
As a responsible developer you will, of course, want to verify that anypackage upgrades function as advertised. The real world is a messy place;there’s nothing we can do about that but be vigilant. What you can do is letSemantic Versioning provide you with a sane way to release and upgradepackages without having to roll new versions of dependent packages, saving youtime and hassle.
If all of this sounds desirable, all you need to do to start using SemanticVersioning is to declare that you are doing so and then follow the rules. Linkto this website from your README so others know the rules and can benefit fromthem.
The simplest thing to do is start your initial development release at 0.1.0and then increment the minor version for each subsequent release.
If your software is being used in production, it should probably already be1.0.0. If you have a stable API on which users have come to depend, you shouldbe 1.0.0. If you’re worrying a lot about backward compatibility, you shouldprobably already be 1.0.0.
Major version zero is all about rapid development. If you’re changing the APIevery day you should either still be in version 0.y.z or on a separatedevelopment branch working on the next major version.
This is a question of responsible development and foresight. Incompatiblechanges should not be introduced lightly to software that has a lot ofdependent code. The cost that must be incurred to upgrade can be significant.Having to bump major versions to release incompatible changes means you’llthink through the impact of your changes, and evaluate the cost/benefit ratioinvolved.
It is your responsibility as a professional developer to properly documentsoftware that is intended for use by others. Managing software complexity is ahugely important part of keeping a project efficient, and that’s hard to do ifnobody knows how to use your software, or what methods are safe to call. Inthe long run, Semantic Versioning, and the insistence on a well defined publicAPI can keep everyone and everything running smoothly.
As soon as you realize that you’ve broken the Semantic Versioning spec, fixthe problem and release a new minor version that corrects the problem andrestores backward compatibility. Even under this circumstance, it isunacceptable to modify versioned releases. If it’s appropriate,document the offending version and inform your users of the problem so thatthey are aware of the offending version.
That would be considered compatible since it does not affect the public API.Software that explicitly depends on the same dependencies as your packageshould have their own dependency specifications and the author will notice anyconflicts. Determining whether the change is a patch level or minor levelmodification depends on whether you updated your dependencies in order to fixa bug or introduce new functionality. We would usually expect additional codefor the latter instance, in which case it’s obviously a minor level increment.
Use your best judgment. If you have a huge audience that will be drasticallyimpacted by changing the behavior back to what the public API intended, thenit may be best to perform a major version release, even though the fix couldstrictly be considered a patch release. Remember, Semantic Versioning is allabout conveying meaning by how the version number changes. If these changesare important to your users, use the version number to inform them.
Deprecating existing functionality is a normal part of software development andis often required to make forward progress. When you deprecate part of yourpublic API, you should do two things: (1) update your documentation to letusers know about the change, (2) issue a new minor release with the deprecationin place. Before you completely remove the functionality in a new major releasethere should be at least one minor release that contains the deprecation sothat users can smoothly transition to the new API.
No, but use good judgment. A 255 character version string is probably overkill,for example. Also, specific systems may impose their own limits on the size ofthe string.
No, “v1.2.3” is not a semantic version. However, prefixing a semantic versionwith a “v” is a common way (in English) to indicate it is a version number.Abbreviating “version” as “v” is often seen with version control. Example:git tag v1.2.3 -m "Release version 1.2.3"
, in which case “v1.2.3” is a tagname and the semantic version is “1.2.3”.
There are two. One with named groups for those systems that support them(PCRE [Perl Compatible Regular Expressions, i.e. Perl, PHP and R], Pythonand Go).
See:https://regex101.com/r/Ly7O1x/3/
^(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)(?:-(?P<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$
And one with numbered capture groups instead (so cg1 = major, cg2 = minor,cg3 = patch, cg4 = prerelease and cg5 = buildmetadata) that is compatiblewith ECMA Script (JavaScript), PCRE (Perl Compatible Regular Expressions,i.e. Perl, PHP and R), Python and Go.
See:https://regex101.com/r/vkijKf/1/
^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$
The Semantic Versioning specification was originally authored byTomPreston-Werner, inventor of Gravatar andcofounder of GitHub.
If you’d like to leave feedback, pleaseopen an issue onGitHub.