π§ Semantic Versioning (SemVer) β Complete Guide
Semantic Versioning is a versioning system that conveys meaning about the underlying changes in a release through its version number. It helps teams communicate changes, manage dependencies, and avoid unexpected breakages.
π’ Format: MAJOR.MINOR.PATCH
Each version number is made of three digits, for example:
1.4.2
Part | Purpose | Example |
---|---|---|
MAJOR | Breaking changes | 2.0.0 |
MINOR | Backward-compatible feature additions | 1.5.0 |
PATCH | Backward-compatible bug fixes | 1.5.3 |
π§ When to Increment?
Scenario | Example Before β After |
---|---|
Breaking API contract | 1.4.0 β 2.0.0 |
Adding new backward-compatible features | 1.4.0 β 1.5.0 |
Fixing bugs or performance improvements | 1.4.0 β 1.4.1 |
π Pre-release Tags and Build Metadata
You can add optional labels to denote pre-release or build metadata:
- Pre-release: use hyphen (
-
)
1.4.0-alpha.1
1.4.0-beta
- Build metadata: use plus (
+
)
1.4.0+build.123
Pre-releases are considered lower precedence than the associated final release.
π What is a Release Candidate (RC)?
A Release Candidate is a version that is feature-complete and potentially ready to become a final release β unless significant bugs emerge. It signals the final stages of testing before the stable release.
π’ Format
RC versions use the pre-release syntax with a hyphen (-
) followed by rc
(short for "release candidate") and a number:
1.0.0-rc.1
1.0.0-rc.2
Each increment reflects an iteration toward stabilization.
π SemVer Precedence Rules
Pre-release versions have lower precedence than the associated final release:
Version | Meaning |
---|---|
1.0.0-alpha.1 |
Early prototype version |
1.0.0-beta.1 |
More stable than alpha, less than RC |
1.0.0-rc.1 |
Release candidate |
1.0.0 |
Final release |
So:
1.0.0-alpha.1 < 1.0.0-beta.1 < 1.0.0-rc.1 < 1.0.0
β When to Use Release Candidates
- All major functionality is implemented.
- Bugs from earlier testing phases (alpha, beta) are fixed.
- You are ready for final validation and user acceptance testing.
π Best Practices
- Use RCs to let internal teams or early adopters validate stability.
- Clearly document whatβs changed between
rc.1
,rc.2
, etc. - Avoid introducing new features during RC phase β it should be focused on stabilization only.
π Example Workflow
- Release
1.0.0-alpha.1
β internal development - Release
1.0.0-beta.1
β early user feedback - Release
1.0.0-rc.1
β bug fixes and performance stabilization - Release
1.0.0
β final stable version
π·οΈ Version Tags in Package Managers
Tool | RC Usage Example |
---|---|
npm | npm install mylib@rc |
pip | pip install mylib==1.0.0rc1 |
Maven | Use <version>1.0.0-RC1</version> |
Cargo | 1.0.0-rc.1 in Cargo.toml |
π Why Semantic Versioning Matters
- β Predictability for clients using your software
- β Safe upgrades without breaking things
- β Clear contract of stability and changes
- β Automation-friendly for dependency managers
π« Common Mistakes to Avoid
- β Publishing breaking changes as a minor or patch
- β Using v1.0.0 without API stability
- β Skipping semantic versioning altogether
π¦ SemVer in Package Managers
- npm (Node.js): uses SemVer with carets (
^
) and tildes (~
) - pip (Python): supports SemVer via constraints like
>=1.2.0, <2.0.0
- Composer (PHP): strictly encourages SemVer
- Cargo (Rust), Go Modules, Maven: all follow SemVer principles
π Best Practices
- Start with
0.y.z
if your project is still unstable. - Only release
1.0.0
when your API is stable and documented. - Communicate breaking changes with release notes or changelogs.
- Use tooling like:
- Semantic Release for automated versioning
- Commitizen for standard commits
- Conventional Commits to link commits with version bumps
π§ Summary Table
Action | SemVer Change | Backward Compatible? |
---|---|---|
Breaking API change | MAJOR | β No |
New feature (compatible) | MINOR | β Yes |
Bug fix or small patch | PATCH | β Yes |
π Resources
<< back to Guides