TExcelTAD
Home › Assets, Tools & Shipping › Version & Build Numbers

Version & Build Numbers

Every build that leaves your machine needs an identity. Players report bugs against it, crash reports group by it, stores require it to increase, and your future self needs to rebuild it. A game typically carries two numbers: a human-facing version (1.4.2) and a machine-facing build number that only ever goes up (10402, or 587 from CI).

Semantic versioning, adapted to games

Semantic Versioning defines MAJOR.MINOR.PATCH with optional pre-release (-beta.2) and build metadata (+build.587). Its rules were written for libraries ("bump MAJOR on a breaking API change"); games usually read them like this:

Part Bump when Example
MAJOR a big content release or save-format break; 1.0 = launch 0.9.3 → 1.0.0 at launch
MINOR a content update, new features 1.0.4 → 1.1.0
PATCH fixes only 1.1.0 → 1.1.1
pre-release builds before a release: -alpha.N, -beta.N, -rc.N 1.1.0-beta.3
build metadata the CI build, commit hash; ignored when comparing 1.1.0+587.a1b2c3d

Pre-release ordering surprises people: beta.10 comes after beta.2 (numeric parts compare as numbers), and any pre-release comes before the plain release. A small comparison function makes the rules concrete:

python · try it yourself
import re

SEMVER = re.compile(r"^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+([0-9A-Za-z.-]+))?
quot;) def parse(v): m = SEMVER.match(v) if not m: raise ValueError(f"not a semantic version: {v}") major, minor, patch, pre, _build = m.groups() pre_key = [] if pre: for part in pre.split("."): pre_key.append((0, int(part), "") if part.isdigit() else (1, 0, part)) # a release (no pre-release) sorts after all of its pre-releases return (int(major), int(minor), int(patch), 0 if pre else 1, pre_key) versions = ["1.0.0", "1.0.0-rc.1", "1.0.0-beta.10", "1.0.0-beta.2", "0.9.3", "1.0.1", "1.0.0-alpha", "1.0.0+build.587"] for v in sorted(versions, key=parse): print(v) try: parse("v1.2") except ValueError as e: print("error:", e)
0.9.3
1.0.0-alpha
1.0.0-beta.2
1.0.0-beta.10
1.0.0-rc.1
1.0.0
1.0.0+build.587
1.0.1
error: not a semantic version: v1.2

1.0.0 and 1.0.0+build.587 compare equal (build metadata is ignored), so the sort keeps their original order.

Build numbers that stores accept

Stores need a build number that strictly increases with every upload, and they don't understand semver:

Platform Field Rule
Google Play versionCode positive integer, must increase with every upload; Google documents a maximum of 2,100,000,000
Apple App Store CFBundleVersion (build) must increase within a version (CFBundleShortVersionString)
Steam build ID assigned by Steam on upload; your version string is for players
itch.io build number assigned by itch; pass yours with butler push --userversion

In Unity these are PlayerSettings.bundleVersion, PlayerSettings.Android.bundleVersionCode and PlayerSettings.iOS.buildNumber; Unreal and Godot have the same fields in their project and export settings.

Two common schemes for deriving the integer:

python · try it yourself
def code_from_version(major, minor, patch, build=0):
    """MMmmpppbb: readable, but every part has a fixed number of digits"""
    if minor > 99 or patch > 999 or build > 99:
        raise ValueError("part too large for the scheme")
    return major * 10_000_000 + minor * 100_000 + patch * 100 + build

def code_from_ci(run_number, offset=1000):
    """CI run counter: always increases, says nothing about the version"""
    return offset + run_number

for v in [(1, 0, 0), (1, 0, 1), (1, 4, 2, 3), (2, 0, 0)]:
    print(f"{'.'.join(map(str, v[:3])):>6} -> versionCode {code_from_version(*v):>9}")
print("CI run 587  -> versionCode", code_from_ci(587))
try:
    code_from_version(1, 100, 0)
except ValueError as e:
    print("1.100.0 ->", e)

limit = 2_100_000_000
print(f"room left under Google's limit with the first scheme: up to major {limit // 10_000_000 - 1}")
 1.0.0 -> versionCode  10000000
 1.0.1 -> versionCode  10000100
 1.4.2 -> versionCode  10400203
 2.0.0 -> versionCode  20000000
CI run 587  -> versionCode 1587
1.100.0 -> part too large for the scheme
room left under Google's limit with the first scheme: up to major 209

The first scheme lets anyone read the version from the code; the second never collides, even for two builds of the same version. Many teams combine them: version from a tag, build number from CI.

One source of truth

The version must come from one place, or the title screen, the store and the crash reports disagree. Options:

  • a Git tag (v1.4.2), read by the build script with git describe --tags (Branches, Tags & Release Lines);
  • a VERSION file in the repository, bumped by a release script;
  • GameCI's versioning: Semantic input, which derives a version from tags and commit count (GitHub Actions & GameCI).

Turning git describe output into a version and build number is a few lines:

python · try it yourself
import re

def from_describe(desc, ci_run):
    m = re.match(r"^v(\d+\.\d+\.\d+)(?:-(\d+)-g([0-9a-f]+))?(-dirty)?
quot;, desc) if not m: raise ValueError(desc) version, ahead, sha, dirty = m.groups() if ahead: # commits after the tag: a development build major, minor, patch = map(int, version.split(".")) version = f"{major}.{minor}.{patch + 1}-dev.{ahead}" # sorts after 1.4.2, before 1.4.3 meta = f"+{ci_run}" + (f".{sha}" if sha else "") + (".dirty" if dirty else "") return version + meta for desc in ["v1.4.2", "v1.4.2-3-g9f1c2ab", "v1.4.2-3-g9f1c2ab-dirty"]: print(f"{desc:<24} -> {from_describe(desc, 587)}")
v1.4.2                   -> 1.4.2+587
v1.4.2-3-g9f1c2ab        -> 1.4.3-dev.3+587.9f1c2ab
v1.4.2-3-g9f1c2ab-dirty  -> 1.4.3-dev.3+587.9f1c2ab.dirty

Note the development build is called 1.4.3-dev.3, not 1.4.2-dev.3: a pre-release sorts before its release, so a build made after v1.4.2 must pre-release the next version.

Show the full string in the pause menu or a corner of the title screen, write it at the top of the log file, and attach it to every crash report.

Test yourself

Which comes first in semantic-version order?

  1. 1.0.0
  2. 1.0.0-rc.1
  3. 1.0.0-beta.10
  4. 1.0.0-beta.2

What does Google Play require of versionCode?

  1. It must match the version name
  2. It must be a positive integer that increases with every upload
  3. It must be semver
  4. Nothing

Why derive the version from a single source such as a Git tag?

  1. Tags are faster
  2. So the title screen, store, logs and crash reports always agree
  3. Stores require Git
  4. To skip CI