Skip to content

Lesson 18 of 28How teams plan and ship

Semantic Versioning and Changelogs

What a version number promises, what counts as breaking, ranges and lockfiles, changelogs people read, and automating releases from commits.

12 min read0/4 questions

Your team publishes an internal client library that six other services use. You rename one field in a response model, call it a tidy-up, and release it as 2.4.1. The next morning two of those services fail to deploy, because their builds pulled in your "patch" automatically and their code still reads the old field. Nobody did anything unusual; you just made a promise with the version number and broke it. A version number is a contract with everyone downstream, and a changelog is how you tell them what changed in it. This lesson is about keeping that contract: deciding the number, writing the notes, tagging the release, and retiring old behaviour without stranding people.

What a version number promises

Semantic Versioning (SemVer, specification 2.0.0, still the current edition) says a version is MAJOR.MINOR.PATCH, and each part carries a promise about your public API:

  • PATCH (2.4.0 to 2.4.1): backwards-compatible bug fixes only.
  • MINOR (2.4.1 to 2.5.0): new functionality, backwards compatible. Existing callers keep working. Deprecating something is also a minor change.
  • MAJOR (2.5.0 to 3.0.0): anything that can break an existing caller.

Bumping one part resets the parts to its right, so after 2.5.3 the next minor is 2.6.0. Two rules are easy to forget. First, once a version is published its contents must never change; if 2.4.1 is broken, you release 2.4.2, you do not replace 2.4.1. Second, 0.y.z is initial development, and the spec says anything may change at any time. Many teams sit on 0.x for years to avoid committing to anything. If people depend on your package in production, it is time for 1.0.0.

The Modules and npm lesson introduced these three numbers. The hard part at work is not the rules but deciding which category a change falls into.

What counts as breaking

Breaking is defined by what a reasonable caller could be relying on, not by how small the diff is. All of these are major changes:

  • Removing or renaming a function, class, parameter, field, endpoint or CLI flag.
  • Changing a type: a field that was a number becomes a string, or a function that returned a list now returns a generator.
  • Stricter validation. An argument that used to be accepted now raises an error.
  • Changed defaults. A timeout goes from 30 seconds to 5, or a function stops retrying by default.
  • Dropping a runtime. No longer supporting Python 3.10 or Node 20 breaks everyone still on it.
  • Making an optional argument required, or adding a required field to a request body.

Then there is the grey area. Hyrum's law says that with enough users, every observable behaviour of your system will be depended on by somebody: error message text, the order of keys in a response, how long a call takes. You cannot treat all of that as public API or you could never change anything. The practical answer is to document what is public (the types, the functions, the documented fields), treat that as the contract, and when you knowingly change an undocumented behaviour that many people rely on, mention it prominently in the changelog anyway.

Quick check
Your library is at 3.2.0. You fix a bug where an invalid email was silently accepted; it now raises ValueError. What is the next version?
Need a nudge? A hint rules out a wrong answer.

Pre-releases and build metadata

Before a big release you often want people to try it without everyone getting it automatically. SemVer allows a pre-release label after a hyphen, such as 3.0.0-rc.1 (release candidate) or 3.0.0-beta.2, and build metadata after a plus, such as 3.0.0+20261022.sha.4f2a. A pre-release sorts before its release. Build metadata is ignored for ordering entirely.

The ordering rules have traps, which is why you should never sort versions as strings:

JavaScript
// Parse "1.0.0-rc.1+build.7" into its parts. Build metadata is kept but ignored.function parse(v) { const [core, build] = v.split("+"); const dash = core.indexOf("-"); const main = dash === -1 ? core : core.slice(0, dash); const pre = dash === -1 ? [] : core.slice(dash + 1).split("."); return { nums: main.split(".").map(Number), pre, build };} function compareIds(a, b) { const aNum = /^\d+$/.test(a), bNum = /^\d+$/.test(b); if (aNum && bNum) return Number(a) - Number(b); // 2 < 11 if (aNum) return -1; // numbers sort before words if (bNum) return 1; return a < b ? -1 : a > b ? 1 : 0; // plain ASCII order} function compare(x, y) { const a = parse(x), b = parse(y); for (let i = 0; i < 3; i++) if (a.nums[i] !== b.nums[i]) return a.nums[i] - b.nums[i]; if (!a.pre.length || !b.pre.length) return b.pre.length - a.pre.length; // release beats pre-release for (let i = 0; i < Math.min(a.pre.length, b.pre.length); i++) { const c = compareIds(a.pre[i], b.pre[i]); if (c !== 0) return c; } return a.pre.length - b.pre.length; // more fields wins a tie} const tags = ["1.0.0", "1.0.0-rc.10", "1.0.0-beta.11", "1.0.0-rc.2", "1.0.0-alpha", "1.0.0-beta.2", "1.0.0-alpha.1", "0.9.12", "1.0.0-alpha.beta"];console.log(tags.toSorted(compare).join(" < "));console.log("String sort gets it wrong:", ["1.0.0-rc.10", "1.0.0-rc.2"].toSorted().join(", "));console.log("Build metadata ignored:", compare("1.0.0+linux", "1.0.0+mac") === 0);
Output
Press Run (⌘ Enter) to see what happens.

This matches the ordering in the SemVer spec and the npm semver package. Dot-separated numeric parts compare as numbers, so rc.2 comes before rc.10. If you are going to ship ten or more release candidates, that is why the dot in rc.1 matters: rc1 to rc10 would compare as text.

Ranges, lockfiles and who should pin

Package managers let a dependency declare a range instead of one version. npm's caret ^1.2.3 accepts any 1.x.y at or above 1.2.3, and tilde ~1.2.3 accepts 1.2.x. The details that bite people at work:

  • Caret is stricter below 1.0. ^0.2.3 accepts 0.2.x only, and ^0.0.3 accepts exactly 0.0.3, because in 0.x a minor bump may break things.
  • Pre-releases are excluded from ranges. ^1.2.3 will not pick 1.3.0-beta.1. You only get a pre-release if your range itself names one on the same version.
  • Python does not use SemVer. Its versions follow PEP 440, which writes pre-releases as 3.0.0rc1. The compatible-release operator ~=1.4.2 means >=1.4.2, ==1.4.*, and ~=1.4 means >=1.4, ==1.*. Explicit bounds like >=1.4,<2 say the same thing more readably. pip and uv skip pre-releases unless you ask for them.

Ranges alone make installs drift: two developers running install a week apart can get different versions. A lockfile (package-lock.json, pnpm-lock.yaml, uv.lock, poetry.lock) records the exact version of every package, including dependencies of dependencies, so every machine and every CI run installs the same tree. Commit it, and install from it in CI (npm ci, uv sync --locked).

The rule of thumb for who pins what:

  • Applications commit a lockfile and update deliberately, usually through Renovate or Dependabot pull requests that run the full test suite.
  • Libraries declare the widest range they genuinely support, because a library that pins requests==2.32.3 will conflict with every other library that needs a different patch. The library's own lockfile is for its tests, not for its users.
Match the pairs0/5 matched

Match each declared range to what it accepts.

Choose an item, then its match on the other side.

CalVer: when dates fit better

Not everything suits SemVer. Calendar versioning puts the date in the number. Ubuntu uses YY.MM (24.04 shipped in April 2024), and pip uses the year plus a counter (25.1, 25.2). CalVer fits when releases are time-based and "is this up to date?" matters more than "will this break me?": operating systems, applications users install, tools on a fixed cadence, and internal services that nobody imports. It is a poor fit for a library, because the number tells callers nothing about compatibility. For a deployed web service, many teams do not use a public version at all; the commit SHA on the image is the version.

Changelogs written for people

A changelog is a curated list of notable changes, written for the people who use your software. It is not git log pasted into a file. Your users do not care that you renamed an internal helper; they care that a field changed and what to do about it. The Keep a Changelog convention (version 1.1.0) is the common format:

CHANGELOG.md
# Changelog
 
## [Unreleased]
### Added
- `Client.search()` accepts `max_price`.
 
## [3.0.0] - 2026-10-22
### Changed
- **Breaking:** `Order.total` is now `Order.total_cents` (an integer).
  Multiply old values by 100. See the migration guide.
### Removed
- **Breaking:** Python 3.10 support. 3.11 is now the minimum.
### Fixed
- Retries no longer resend a request that already succeeded.
### Security
- Redact the `Authorization` header from debug logs.
 
## [2.9.0] - 2026-09-30
### Deprecated
- `Order.total`. Use `Order.total_cents`; `total` is removed in 3.0.

The six headings are Added, Changed, Deprecated, Removed, Fixed and Security. Newest first, ISO dates, and an Unreleased section at the top where changes collect until the next release, so writing the entry is part of the pull request rather than an archaeology job at release time. Every breaking change says what to do, not just what happened.

Automating the number and the notes

Deciding the bump by hand works until a busy release where someone forgets a breaking change. Teams automate it by writing commit messages in a machine-readable shape. Conventional Commits (version 1.0.0) is the common one: type(scope): description, where fix means a patch, feat means a minor, and a ! after the type or a BREAKING CHANGE: footer means a major. Types like docs, chore, test and refactor do not trigger a release on their own. Commits that keep your history readable, the subject of the commit hygiene lesson in this course, pay off directly here.

JavaScript
const LEVELS = ["none", "patch", "minor", "major"]; function levelOf(message) { const m = message.match(/^(\w+)(?:\([^)]*\))?(!)?: /); if (!m) return 0; // not a Conventional Commit const [, type, bang] = m; if (bang || message.includes("\nBREAKING CHANGE: ")) return 3; if (type === "feat") return 2; if (type === "fix" || type === "perf") return 1; return 0; // docs, chore, test, ci, refactor} function nextVersion(current, commits) { const level = Math.max(0, ...commits.map(levelOf)); const [major, minor, patch] = current.split(".").map(Number); if (level === 3) return `${major + 1}.0.0`; if (level === 2) return `${major}.${minor + 1}.0`; if (level === 1) return `${major}.${minor}.${patch + 1}`; return current; // nothing user-facing: no release} const sinceLastTag = [ "docs: explain the retry option", "fix(cart): keep quantities when the session refreshes", "feat(search): filter results by price", "chore: bump eslint",];console.log("level:", LEVELS[Math.max(...sinceLastTag.map(levelOf))]);console.log("2.3.1 ->", nextVersion("2.3.1", sinceLastTag)); const withBreaking = [...sinceLastTag, "refactor(api): rename total to totalCents\n\nBREAKING CHANGE: the order response field total is now totalCents"];console.log("2.3.1 ->", nextVersion("2.3.1", withBreaking));console.log("2.3.1 ->", nextVersion("2.3.1", ["chore: tidy", "test: add cases"]));
Output
Press Run (⌘ Enter) to see what happens.

The highest level among the commits since the last tag wins. A refactor is normally release-neutral, but the footer turned it into a major, which is exactly the case a human forgets.

Predict the outputJavaScript

What does this print?

const commits = ["docs: fix typo", "fix(cart): keep quantities", "feat!: drop Node 18"];
const level = (c) =>
/^\w+(\(.*\))?!:/.test(c) ? 3 : c.startsWith("feat") ? 2 : c.startsWith("fix") ? 1 : 0;
const names = ["none", "patch", "minor", "major"];
console.log(names[Math.max(...commits.slice(0, 2).map(level))], names[Math.max(...commits.map(level))]);
Need a nudge? Hints walk you through it.

Three tools do this for real, and you will meet all of them:

  • release-please (from Google) keeps an open "release PR" that bumps the version and updates CHANGELOG.md as commits land on main. Merging that PR creates the tag and the GitHub Release. Humans stay in control of when.
  • semantic-release runs in CI on every push to the release branch, works out the version, writes the notes, tags and publishes with no human step. It suits libraries that should release on every merge.
  • Changesets asks each pull request to include a small file saying which packages change and whether it is a patch, minor or major, plus a sentence for the changelog. It is popular in JavaScript monorepos, where one merge can bump several packages differently, and the human-written summary often reads better than commit subjects.
release-please from commit to published release
Feature PRs: feat:, fix: commitsFeature PRsfeat:, fix: commitsmain: squash mergesmainsquash mergesRelease PR: version + CHANGELOGRelease PRversion + CHANGELOGTag v2.4.0: annotatedTag v2.4.0annotatedGitHub Release: notesGitHub ReleasenotesRegistry: npm or PyPIRegistrynpm or PyPImergebot updatesmerge itpublish job

Ordinary pull requests merge with Conventional Commit messages. With squash merging, the PR title becomes the commit, so teams lint PR titles.

1/4

Git tags and releases by hand

Underneath every tool is a Git tag. Use annotated tags for releases: they store who tagged, when, and a message, and git describe and git push --follow-tags only consider annotated tags by default. Lightweight tags are just a name for a commit, fine for personal bookmarks. The v prefix is a convention, not part of SemVer, but nearly every tool expects it.

git tag -a v1.1.0 -m "Release 1.1.0"      # annotated tag on the current commitgit push origin v1.1.0                    # tags are not pushed by plain git pushgit push --follow-tags                    # or: push commits plus annotated tags they reachgit tag -l --sort=-v:refname | head -3    # newest first, compared as versionsgit describe                              # v1.1.0-3-g1aca471: 3 commits after v1.1.0git log --oneline v1.0.1..v1.1.0          # what went into this releasegh release create v1.1.0 --verify-tag --generate-notes   # GitHub Release from an existing tag

Two details from trying this in a real repo. Plain git tag -l sorts as text, so v1.10.0 lands before v1.9.0; --sort=v:refname fixes that. Even version sort puts v1.1.0-rc.1 after v1.1.0 unless you set git config versionsort.suffix -, which tells Git that anything after a hyphen is a pre-release. Never move or delete a tag that has been pushed and published; release a new version instead, exactly as SemVer says.

Deprecating without stranding people

Breaking changes are sometimes right. The professional way to make one is a deprecation policy that gives people time:

  1. Warn. In a minor release, add the replacement and make the old path emit a warning (warnings.warn(..., DeprecationWarning) in Python, a console warning or a @deprecated JSDoc tag in TypeScript).
  2. Document. A Deprecated entry in the changelog, with the replacement and the version in which removal will happen.
  3. Wait. Give a published window: at least one minor release, often six months or a year for widely used packages.
  4. Remove in the next major, listed under Removed, with a migration guide.

Web APIs follow the same idea with different machinery, because you cannot make clients upgrade. Teams version the API itself, in the path (/v2/orders) or a header, add fields freely (additive changes are safe if clients ignore unknown fields), and run old versions in parallel until traffic drops off. Many APIs also send Deprecation and Sunset response headers. API Design in the system design course covers the API side in more depth.

Put it in order5 steps

You need to rename Order.total to Order.total_cents in a library at 2.8.0. Put the steps in order.

  1. Tap the steps below in the right order.
Need a nudge? A hint shows where it starts.
Key terms
semantic versioning
MAJOR.MINOR.PATCH numbering where each part promises breaking changes, compatible features, or fixes only.
breaking change
Any change that can make existing correct callers fail, including stricter validation, new defaults and dropped runtimes.
pre-release
A version such as 3.0.0-rc.1 that sorts before its release and is excluded from normal ranges.
lockfile
A committed file recording the exact version of every installed package so every install is identical.
Conventional Commits
A commit message format (type, optional scope, description, breaking marker) that tools use to compute versions and notes.
annotated tag
A Git tag object with a tagger, date and message, used to mark releases.
deprecation policy
Warn, document and wait a published window before removing old behaviour in a major release.