PageRenderTime 56ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/spec/v0.2.0.md

https://gitlab.com/kainy/semver.org
Markdown | 194 lines | 148 code | 46 blank | 0 comment | 0 complexity | 889c0c88542b0a4b288a77c4888aee28 MD5 | raw file
  1. ---
  2. layout: default
  3. title: Semantic Versioning 0.2.0
  4. ---
  5. Semantic Versioning 0.2.0
  6. =========================
  7. In the world of software management there exists a dread place called
  8. "dependency hell." The bigger your system grows and the more packages you
  9. integrate into your software, the more likely you are to find yourself, one
  10. day, in this pit of despair.
  11. In systems with many dependencies, releasing new package versions can quickly
  12. become a nightmare. If the dependency specifications are too tight, you are in
  13. danger of version lock (the inability to upgrade a package without having to
  14. release new versions of every dependent package). If dependencies are
  15. specified too loosely, you will inevitably be bitten by version promiscuity
  16. (assuming compatibility with more future versions than is reasonable).
  17. Dependency hell is where you are when version lock and/or version promiscuity
  18. prevent you from easily and safely moving your project forward.
  19. As a solution to this problem, I propose a simple set of rules and
  20. requirements that dictate how version numbers are assigned and incremented.
  21. For this system to work, you first need to declare a public API. This may
  22. consist of documentation or be enforced by the code itself. Regardless, it is
  23. important that this API be clear and precise. Once you identify your public
  24. API, you communicate changes to it with specific increments to your version
  25. number. Consider a version format of X.Y.Z (Major.Minor.Patch). Bug fixes not
  26. affecting the API increment the patch version, backwards compatible API
  27. additions/changes increment the minor version, and backwards incompatible API
  28. changes increment the major version.
  29. I call this system "Semantic Versioning." Under this scheme, version numbers
  30. and the way they change convey meaning about the underlying code and what has
  31. been modified from one version to the next.
  32. Semantic Versioning Specification (SemVer)
  33. ------------------------------------------
  34. The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD",
  35. "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be
  36. interpreted as described in RFC 2119.
  37. 1. Software using Semantic Versioning MUST declare a public API. This API
  38. could be declared in the code itself or exist strictly in documentation.
  39. However it is done, it should be precise and comprehensive.
  40. 1. A normal version number MUST take the form X.Y.Z where X, Y, and Z are
  41. integers. X is the major version, Y is the minor version, and Z is the patch
  42. version. Each element MUST increase numerically. For instance: 1.9.0 < 1.10.0
  43. < 1.11.0.
  44. 1. A special version number MAY be denoted by appending an arbitrary string
  45. immediately following the patch version. The string MUST be comprised of only
  46. alphanumerics plus dash [0-9A-Za-z-] and MUST begin with an alpha character
  47. [A-Za-z]. Special versions satisfy but have a lower precedence than the
  48. associated normal version. Precedence SHOULD be determined by lexicographic
  49. ASCII sort order. For instance: 1.0.0beta1 < 1.0.0beta2 < 1.0.0.
  50. 1. Once a versioned package has been released, the contents of that version
  51. MUST NOT be modified. Any modifications must be released as a new version.
  52. 1. Major version zero (0.y.z) is for initial development. Anything may change
  53. at any time. The public API should not be considered stable.
  54. 1. Version 1.0.0 defines the public API. The way in which the version number
  55. is incremented is now dependent on this public API and how it changes.
  56. 1. Patch version Z (x.y.Z | x > 0) MUST be incremented if only backwards
  57. compatible bug fixes are introduced. A bug fix is defined as an internal
  58. change that fixes incorrect behavior.
  59. 1. Minor version Y (x.Y.z | x > 0) MUST be incremented if new, backwards
  60. compatible functionality is introduced to the public API. It MAY be
  61. incremented if substantial new functionality or improvements are introduced
  62. within the private code. It MAY include patch level changes.
  63. 1. Major version X (X.y.z | X > 0) MUST be incremented if any backwards
  64. incompatible changes are introduced to the public API. It MAY include minor
  65. and patch level changes.
  66. Tagging Specification (SemVerTag)
  67. ---------------------------------
  68. This sub-specification SHOULD be used if you use a version control system
  69. (Git, Mercurial, SVN, etc) to store your code. Using this system allows
  70. automated tools to inspect your package and determine SemVer compliance and
  71. released versions.
  72. 1. When tagging releases in a version control system, the tag for a version
  73. MUST be "vX.Y.Z" e.g. "v3.1.0".
  74. 1. The first revision that introduces SemVer compliance SHOULD be tagged
  75. "semver". This allows pre-existing projects to assume compliance at any
  76. arbitrary point and for automated tools to discover this fact.
  77. Why Use Semantic Versioning?
  78. ----------------------------
  79. This is not a new or revolutionary idea. In fact, you probably do something
  80. close to this already. The problem is that "close" isn't good enough. Without
  81. compliance to some sort of formal specification, version numbers are
  82. essentially useless for dependency management. By giving a name and clear
  83. definition to the above ideas, it becomes easy to communicate your intentions
  84. to the users of your software. Once these intentions are clear, flexible (but
  85. not too flexible) dependency specifications can finally be made.
  86. A simple example will demonstrate how Semantic Versioning can make dependency
  87. hell a thing of the past. Consider a library called "Firetruck." It requires a
  88. Semantically Versioned package named "Ladder." At the time that Firetruck is
  89. created, Ladder is at version 3.1.0. Since Firetruck uses some functionality
  90. that was first introduced in 3.1.0, you can safely specify the Ladder
  91. dependency as greater than or equal to 3.1.0 but less than 4.0.0. Now, when
  92. Ladder version 3.1.1 and 3.2.0 become available, you can release them to your
  93. package management system and know that they will be compatible with existing
  94. dependent software.
  95. As a responsible developer you will, of course, want to verify that any
  96. package upgrades function as advertised. The real world is a messy place;
  97. there's nothing we can do about that but be vigilant. What you can do is let
  98. Semantic Versioning provide you with a sane way to release and upgrade
  99. packages without having to roll new versions of dependent packages, saving you
  100. time and hassle.
  101. If all of this sounds desirable, all you need to do to start using Semantic
  102. Versioning is to declare that you are doing so and then follow the rules. Link
  103. to this website from your README so others know the rules and can benefit from
  104. them.
  105. FAQ
  106. ---
  107. ### How do I know when to release 1.0.0?
  108. If your software is being used in production, it should probably already be
  109. 1.0.0. If you have a stable API on which users have come to depend, you should
  110. be 1.0.0. If you're worrying a lot about backwards compatibility, you should
  111. probably already be 1.0.0.
  112. ### Doesn't this discourage rapid development and fast iteration?
  113. Major version zero is all about rapid development. If you're changing the API
  114. every day you should either still be in version 0.x.x or on a separate
  115. development branch working on the next major version.
  116. ### If even the tiniest backwards incompatible changes to the public API require a major version bump, won't I end up at version 42.0.0 very rapidly?
  117. This is a question of responsible development and foresight. Incompatible
  118. changes should not be introduced lightly to software that has a lot of
  119. dependent code. The cost that must be incurred to upgrade can be significant.
  120. Having to bump major versions to release incompatible changes means you'll
  121. think through the impact of your changes, and evaluate the cost/benefit ratio
  122. involved.
  123. ### Documenting the entire public API is too much work!
  124. It is your responsibility as a professional developer to properly document
  125. software that is intended for use by others. Managing software complexity is a
  126. hugely important part of keeping a project efficient, and that's hard to do if
  127. nobody knows how to use your software, or what methods are safe to call. In
  128. the long run, Semantic Versioning, and the insistence on a well defined public
  129. API can keep everyone and everything running smoothly.
  130. ### What do I do if I accidentally release a backwards incompatible change as a minor version?
  131. As soon as you realize that you've broken the Semantic Versioning spec, fix
  132. the problem and release a new minor version that corrects the problem and
  133. restores backwards compatibility. Remember, it is unacceptable to modify
  134. versioned releases, even under this circumstance. If it's appropriate,
  135. document the offending version and inform your users of the problem so that
  136. they are aware of the offending version.
  137. ### What should I do if I update my own dependencies without changing the public API?
  138. That would be considered compatible since it does not affect the public API.
  139. Software that explicitly depends on the same dependencies as your package
  140. should have their own dependency specifications and the author will notice any
  141. conflicts. Determining whether the change is a patch level or minor level
  142. modification depends on whether you updated your dependencies in order to fix
  143. a bug or introduce new functionality. I would usually expect additional code
  144. for the latter instance, in which case it's obviously a minor level increment.
  145. About
  146. -----
  147. The Semantic Versioning specification is authored by [Tom Preston-Werner](http://tom.preston-werner.com), inventor of Gravatars and cofounder of GitHub.
  148. If you'd like to leave feedback, please [open an issue on GitHub](https://github.com/mojombo/semver.org/issues).