TExcelTAD
Home › Release Engineering & CI/CD › Pre-releases & Build Metadata

Pre-releases & Build Metadata

Before 2.0.0 is final you want people to try it without the package manager handing it to everyone. After a build you want to know which commit and pipeline produced it. SemVer has one suffix for each job: the pre-release (-rc.1) and the build metadata (+sha.1a2b3c4).

2.0.0-rc.1+build.417.sha.1a2b3c4
│     │    └── build metadata: after "+", ignored for precedence
│     └─────── pre-release: after "-", lowers precedence
└───────────── the version it leads up to

Pre-release rules

  • A pre-release comes before its version: 2.0.0-alpha < 2.0.0-rc.1 < 2.0.0.
  • Identifiers are dot-separated, [0-9A-Za-z-] only, never empty, and numeric ones have no leading zeros.
  • They compare left to right: numbers numerically, text in ASCII order, numbers before text, and a shorter list loses when all earlier identifiers are equal (alpha < alpha.1).
  • A pre-release "indicates that the version is unstable and might not satisfy the intended compatibility requirements". Range matching tools reflect this: npm's ^1.2.0 does not match 1.3.0-beta.1; a range only matches pre-releases of the same MAJOR.MINOR.PATCH that it mentions explicitly (^1.3.0-beta.0).

Because ASCII order puts alpha < beta < rc, the common label sequence sorts correctly by accident of the alphabet. A label such as preview would sort after beta but before rc, and RC (capital) would sort before all lowercase labels. Pick a scheme and keep it.

Computing the next pre-release

Release tools compute pre-release numbers the same way npm's npm version prerelease --preid rc does. This model implements the four common operations:

js · try it yourself
function parse(v) {
  const [, core, pre] = /^(\d+\.\d+\.\d+)(?:-([^+]+))?(?:\+.*)?$/.exec(v);
  const [major, minor, patch] = core.split('.').map(Number);
  return { major, minor, patch, pre: pre ? pre.split('.') : [] };
}
const fmt = (v) => `${v.major}.${v.minor}.${v.patch}${v.pre.length ? '-' + v.pre.join('.') : ''}`;

function inc(version, kind, preid = 'rc') {
  const v = parse(version);
  switch (kind) {
    case 'premajor': return fmt({ major: v.major + 1, minor: 0, patch: 0, pre: [preid, '0'] });
    case 'preminor': return fmt({ ...v, minor: v.minor + 1, patch: 0, pre: [preid, '0'] });
    case 'prepatch': return fmt({ ...v, patch: v.patch + 1, pre: [preid, '0'] });
    case 'prerelease': {
      if (!v.pre.length) return fmt({ ...v, patch: v.patch + 1, pre: [preid, '0'] });
      const last = v.pre[v.pre.length - 1];
      if (v.pre[0] === preid && /^\d+$/.test(last)) {
        return fmt({ ...v, pre: [...v.pre.slice(0, -1), String(Number(last) + 1)] });
      }
      return fmt({ ...v, pre: [preid, '0'] });   // switching label: beta.3 -> rc.0
    }
    case 'release': return fmt({ ...v, pre: [] }); // drop the suffix: 2.0.0-rc.2 -> 2.0.0
  }
}

let v = '1.4.2';
const steps = [['premajor', 'alpha'], ['prerelease', 'alpha'], ['prerelease', 'beta'],
               ['prerelease', 'beta'], ['prerelease', 'rc'], ['prerelease', 'rc'], ['release']];
console.log(v);
for (const [kind, id] of steps) {
  v = inc(v, kind, id);
  console.log(`  ${kind.padEnd(10)} ${(id ?? '').padEnd(5)} -> ${v}`);
}
console.log('prepatch of 1.4.2 ->', inc('1.4.2', 'prepatch'));
console.log('preminor of 1.4.2 ->', inc('1.4.2', 'preminor', 'beta'));
1.4.2
  premajor   alpha -> 2.0.0-alpha.0
  prerelease alpha -> 2.0.0-alpha.1
  prerelease beta  -> 2.0.0-beta.0
  prerelease beta  -> 2.0.0-beta.1
  prerelease rc    -> 2.0.0-rc.0
  prerelease rc    -> 2.0.0-rc.1
  release          -> 2.0.0
prepatch of 1.4.2 -> 1.4.3-rc.0
preminor of 1.4.2 -> 1.5.0-beta.0

Most teams start the counter at .0 (npm's convention) or .1 (semantic-release's convention, which you'll see in Pre-release Branches & Channels). Either is fine; mixing them in one project is not.

Build metadata

Build metadata records which build this is, without affecting ordering:

Use Example
commit 1.4.2+sha.1a2b3c4
CI run 1.4.2+build.8812
platform 1.4.2+linux.x86_64 (better in the artifact name, see Artifact Naming & Checksums)
nightly 1.5.0-nightly.20260115+sha.1a2b3c4 (the date in the pre-release so nightlies do order)

Caveats:

  • Many registries strip or reject build metadata. npm drops it on publish (1.0.0+abc becomes 1.0.0), so two "different" builds collide. Use it in binaries' --version output and file names, not as a registry version.
  • Docker tags can't contain +. The usual convention is to replace it with - or _ in image tags (app:1.4.2_sha.1a2b3c4), or to keep metadata in image labels instead.
  • Because metadata is ignored for precedence, "is 1.4.2+build.9 newer than 1.4.2+build.8?" has no SemVer answer. If you need ordering, put the counter in the pre-release or the version itself.

Other ecosystems' spellings

SemVer is the lingua franca, but several ecosystems spell pre-releases their own way:

Ecosystem Pre-release Notes
npm, Cargo, NuGet, Go modules 2.0.0-rc.1 SemVer 2 (Go requires a v prefix: v2.0.0-rc.1; Go pseudo-versions such as v0.0.0-20260115100000-1a2b3c4d5e6f are pre-releases)
Python (PEP 440) 2.0.0rc1, 2.0.0b2, 2.0.0a1, 2.0.0.dev3, post-releases 2.0.0.post1 not SemVer: 2.0.0-rc.1 is normalised to 2.0.0rc1; local versions +abc are rejected by PyPI (Python Packaging)
Maven 2.0.0-SNAPSHOT (mutable, development), 2.0.0-RC1, 2.0.0-M1 Maven's own ordering rules; SNAPSHOTs are re-deployable (Java Builds)
Debian packages 2.0.0~rc1 the ~ sorts before the empty string, so 2.0.0~rc1 < 2.0.0
RPM 2.0.0~rc1 (modern rpm) same idea as Debian

When one product ships to several of these, keep one canonical SemVer version in the repository and convert it per format at packaging time (2.0.0-rc.1 → 2.0.0rc1 for PyPI, 2.0.0~rc.1 for a .deb).

Test yourself

Does the npm range ^1.2.0 match 1.3.0-beta.1?

  1. Yes, it is between 1.2.0 and 2.0.0
  2. No: ranges only match pre-releases of a version they name explicitly
  3. Only with --force
  4. Only if 1.3.0 doesn't exist

Why is beta.10 safer than beta10 as a pre-release label?

  1. Dots are required
  2. With a separate numeric identifier, 10 compares numerically, so beta.10 > beta.9; beta10 compares as text and sorts before beta9
  3. Registries reject beta10
  4. There is no difference

Where should a Debian package put the pre-release so that 2.0.0 sorts after it?

  1. 2.0.0-rc1
  2. 2.0.0~rc1
  3. 2.0.0+rc1
  4. 2.0.0.rc1