semver bash implementation
Clone or download
fsaintjacques Merge pull request #24 from alyssais/patch-1
Add customizable PREFIX in Makefile
Latest commit 3e05ee0 Nov 26, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src Release 2.1.0. Oct 5, 2018
test Address shellcheck lint issues Apr 20, 2018
.travis.yml Add lint check to Makefile and travis Mar 6, 2017
LICENSE adds LICENSE Dec 22, 2015
Makefile Add DESTDIR to Makefile Nov 26, 2018
README.md Add tests for get command Oct 3, 2018

README.md

The semver shell utility

semver is a little tool to manipulate version bumping in a project that follows the semver specification. Its use are:

  • bump version
  • compare version
  • extract specific version part

It can be combined git pre-commit hooks to guarantee a correct versioning.

Build Status Stable Version License

usage

Usage:
  semver bump (major|minor|patch|prerel <prerel>|build <build>) <version>
  semver compare <version> <other_version>
  semver get (major|minor|patch|release|prerel|build) <version>
  semver --help
  semver --version

Arguments:
  <version>  A version must match the following regex pattern:
             \"${SEMVER_REGEX}\".
             In english, the version must match X.Y.Z(-PRERELEASE)(+BUILD)
             where X, Y and Z are positive integers, PRERELEASE is an optionnal
             string composed of alphanumeric characters and hyphens and
             BUILD is also an optional string composed of alphanumeric
             characters and hyphens.

  <other_version>  See <version> definition.

  <prerel>  String that must be composed of alphanumeric characters and hyphens.

  <build>   String that must be composed of alphanumeric characters and hyphens.

Options:
  -v, --version          Print the version of this tool.
  -h, --help             Print this help message.

Commands:
  bump     Bump <version> by one of major, minor, patch, prerel, build
           or a forced potentialy conflicting version. The bumped version is
           shown to stdout.

  compare  Compare <version> with <other_version>, output to stdout the
           following values: -1 if <other_version> is newer, 0 if equal, 1 if
           older.

  get      Extract given part of <version>, where part is one of major, minor,
           patch, prerel, build.

examples

Basic bumping operations

$ semver bump patch 0.1.0
0.1.1
$ semver bump minor 0.1.1
0.2.0
$ semver bump patch 0.2.0
0.2.1
$ semver bump major 0.2.1
1.0.0
$ semver bump patch 1.0.0
1.0.1
$ semver bump prerel rc1.1.0 1.0.1
1.0.1-rc1.1.0
$ semver bump build build.051 1.0.1-rc1.1.0
1.0.1-rc1.1.0+build.051
$ semver bump release 0.1.0-SNAPSHOT
0.1.0

Comparing version for scripting

$ semver compare 1.0.1-rc1.1.0+build.051 1.0.1
1
$ semver compare 1.0.1-rc1.1.0+build.051 1.0.1-rc1.1.0
0
$ semver compare 1.0.1-rc1.1.0+build.051 1.0.1-rc1.1.0+build.052
0
$ semver compare 1.0.1-rc1.1.0+build.051 1.0.1-rb1.1.0
1
$ semver compare 10.1.4-rc4 10.4.2-rc1
-1

Extract version part

$ semver get patch 1.2.3
3
$ semver get minor 1.2.3
2
$ semver get major 1.2.3
1
$ semver get prerel 1.2.3-rc.4
rc.4
$ semver get prerel 1.2.3-alpha.4.5
alpha.4.5
$ semver get build 1.2.3-rc.4+build.567
build.567