Skip to content

ceejbot/semver-bump

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

semver-bump 🤜🤛

Tests

A tool for bumping version numbers in a semantic-version-compatible way, designed to be used in a shell scripting context. It takes the previous version number as a command-line argument, bumps the segment you requested to be bumped, and emits the result to stdout with no other noise. It also handles bumping pre-release and build identifiers as well, so you can increment 3.0.0-alpha.1 to 3.0.0-alpha.2.

semver-bump may be installed pre-built from the latest release on GitHub, or with homebrew via brew install ceejbot/tap/semver-bump. You may also build it yourself with cargo install semver-bump. It requires at least Rust 1.74.1 to build.

Usage

There are five commands. The prerelease and build commands take an optional replacement identifier string parameter.

> semver-bump help

Bump a semver-compliant version number and write the result to stdout

Usage: semver-bump <COMMAND>

Commands:
  major       Bump the major version number for a breaking change
  minor       Bump the minor version number for a new feature
  patch       Bump the patch version number for a bug fix
  prerelease  Bump any version number at the end of a pre-release identifier
  build       Bump any version number at the end of a build identifier
  help        Print this message or the help of the given subcommand(s)

Options:
  -h, --help     Print help
  -V, --version  Print version

Examples

Here we bump the version number of semver-bump itself:

#!/usr/bin/env bash
set -e
old=$(tomato get package.version Cargo.toml)
version=$(cargo run -- "$1" "$old")
tomato set package.version "$version" Cargo.toml
cargo check
git commit Cargo.toml Cargo.lock -m "v$version"
git tag "$version"
echo "Release tagged for version $version"

A nearly identical version of this is in the justfile for this repo. You can use cargo-edit for this specific use case if you don't need to manage pre-release or build identifiers. The use case I had in mind was automatic version bumping and tagging for a project in a language other than Rust.

Here are some examples of the prerelease bumping behavior. There are some restrictions on what characters are allowed in the semver prerelease identifiers, and the semver crate's implementation is stricter than some.

> semver-bump prerelease 1.2.3-alpha.4
1.2.3-alpha.5

> semver-bump prerelease 1.2.3-cetialpha4
1.2.3-cetialpha5

> semver-bump prerelease 1.2.3-ceti-alpha-4
1.2.3-ceti-alpha-5

> semver-bump prerelease 1.2.3-ceti-alpha-5 beta
1.2.3-beta.1

> semver-bump prerelease 1.0.0
Error: The current version does not have a prerelease suffix and you did not provide one.

> semver-bump prerelease 1.0.0 +illegal+
Error: unexpected character in pre-release identifier

Bumping the build metadata component is an edge use case, but this tool supports doing so if somebody needs it.

> semver-bump build 1.0.3-rc.2+build-4
1.0.3-rc.2+build-5

LICENSE

This code is licensed via the Parity Public License. This license requires people who build on top of this source code to share their work with the community, too. See the license text for details.

About

Yet another command-line tool for bumping semver version numbers.

Resources

License

Stars

Watchers

Forks

Packages

No packages published