Sub topic 1
Versioning Rules: MAJOR.MINOR.PATCH and What Each Bump Means
Prerequisites
This chapter assumes you can do the following:
- Create commits, branches, and tags with git.
- Read a GitHub pull request and understand labels.
- Read basic YAML.
No workflow knowledge is needed yet. This chapter covers the numbering rules that later chapters automate.
Why a version number needs rules
A release tag such as v1.4.2 is more than a label. Users read it to decide whether upgrading is safe. Automation reads it to decide how to publish a release. If the number follows no rules, neither of them can trust it.
Semantic versioning, often shortened to SemVer, is a set of rules that gives each part of the number a fixed meaning. A version has three non-negative integers separated by dots:
MAJOR.MINOR.PATCHWhat each bump means
Each part answers a different question about the change.
| Part | Increase it when | Example | Resets |
|---|---|---|---|
| MAJOR | You make a change that breaks existing users | 1.4.2 to 2.0.0 | MINOR and PATCH go to 0 |
| MINOR | You add functionality in a backward-compatible way | 1.4.2 to 1.5.0 | PATCH goes to 0 |
| PATCH | You fix a bug without changing the public interface | 1.4.2 to 1.4.3 | Nothing |
Three points are easy to get wrong:
- A bump resets every part to its right. After
1.4.2, a new feature gives1.5.0, not1.5.2. - Only one part changes per release. If a release contains a fix, a feature, and a breaking change, you bump MAJOR once.
- "Breaking" is defined by your public interface: a command-line flag, an HTTP endpoint, an exported function, or a config file format. Internal refactoring that users cannot observe is not breaking.
Special cases
Versions before 1.0.0
A version such as 0.8.3 signals that the interface is still unstable. SemVer allows anything to change at any time in the 0.y.z range. Many projects use MINOR for breaking changes and PATCH for everything else until they reach 1.0.0.
Pre-release suffixes
A hyphen followed by identifiers marks a pre-release, for example 1.3.0-rc.1 or 2.0.0-beta.2. A pre-release sorts before the final version it leads up to: 1.3.0-rc.1 is lower than 1.3.0. A later chapter uses this suffix to mark GitHub pre-releases.
The `v` prefix
SemVer itself defines 1.2.0, not v1.2.0. Git tags conventionally add a v, and this tutorial does the same. The tag is v1.2.0 and the version is 1.2.0. Pick one convention and keep it. Your workflow's tag filter and validation must match it.
Versions are never reused
Once a version is published, do not change its contents. If v1.2.0 has a mistake, publish v1.2.1. Moving a tag that people have already downloaded breaks reproducible builds and cached dependencies.
How this connects to automation
Later chapters build a workflow that starts when you push a tag. That workflow does not decide the number. You do, or a tool does it from your commit messages. A reliable release process therefore needs a clear rule for choosing the number before any YAML is written.
Below is a small script that applies the rules from this chapter. It takes a current version and a bump type, then prints the next version.
#!/usr/bin/env bash
set -euo pipefail
current="${1:?usage: bump.sh MAJOR.MINOR.PATCH major|minor|patch}"
kind="${2:?usage: bump.sh MAJOR.MINOR.PATCH major|minor|patch}"
IFS=. read -r major minor patch <<< "$current"
case "$kind" in
major) major=$((major + 1)); minor=0; patch=0 ;;
minor) minor=$((minor + 1)); patch=0 ;;
patch) patch=$((patch + 1)) ;;
*) echo "Unknown bump type: $kind" >&2; exit 1 ;;
esac
echo "$major.$minor.$patch"Running ./bump.sh 1.4.2 minor prints 1.5.0. Running ./bump.sh 1.4.2 major prints 2.0.0. The script handles plain versions only. It does not parse pre-release suffixes.
Common mistakes
- Bumping PATCH for a change that removes a flag or renames an output. Users who upgrade automatically will break.
- Forgetting to reset lower parts, which produces versions like
2.1.4after a major bump. - Treating the version as a date or a counter of how much work was done. It describes compatibility only.
Exercise
The current version is 2.3.5. A release adds a new optional --verbose flag and fixes two bugs. What is the next version, and why?
Show answer
2.4.0. The new flag is backward-compatible functionality, so MINOR is bumped. The bug fixes do not add a second bump because only the highest-impact part changes. PATCH resets to 0.
Exercise
A release removes the --legacy flag from a command-line tool at version 1.9.2. What is the next version, and what happens to the other parts?
Show answer
2.0.0. Removing a flag breaks existing users, so MAJOR is bumped, and MINOR and PATCH reset to 0.