项目作者: chriskilding

项目描述 :
Semantic Versioning utility
高级语言: Shell
项目地址: git://github.com/chriskilding/semver.git
创建时间: 2019-02-16T23:22:54Z
项目社区:https://github.com/chriskilding/semver

开源协议:MIT License

下载


semver

Codecov

Semantic Versioning utility.

Description

The semver utility is a text filter for Semantic Version strings. It searches text from the standard input, selects any Semantic Versions that are present, and writes them to the standard output. It can optionally sort or tabulate the selected versions.

A version string will be selected within the text stream if the following criteria are met:

  • version is a valid Semantic Version.
  • version is a whole line. (This can be modified with the -w option.)

Install

Homebrew

  1. brew tap chriskilding/semver
  2. brew install semver

From source

Dependencies:

  • Perl 5+ (pre-installed on: macOS, Debian, openSUSE)
  • Bats (test)
  1. make
  2. make test # optional
  3. make install

Usage

  1. semver [-hqstw]

Options:

  • -h --help
    Show the help screen.
  • -q --quiet
    Quiet - suppress normal output.
  • -s --sort
    Sort the matched versions in precedence order (low-to-high).
  • -t --tabulate
    Tabulate the matched versions (separator: ‘\t’).
  • -w --word-match
    Select words that match the semver pattern. (Equivalent to the grep(1) --word-regexp option.)

Most options can be combined. For example, semver -stw will word-match occurrences of semvers, sort them, and print them in tabulated form.

Manual

  1. man semver

Examples

Select lines that are version strings:

  1. semver < example.txt

Calculate the next Git tag:

  1. # ++major
  2. git tag | semver -st | tail -n 1 | awk -F '\t' '{ print ++$1 "." 0 "." 0 }'
  3. # ++minor
  4. git tag | semver -st | tail -n 1 | awk -F '\t' '{ print $1 "." ++$2 "." 0 }'
  5. # ++patch
  6. git tag | semver -st | tail -n 1 | awk -F '\t' '{ print $1 "." $2 "." ++$3 }'

Cut out the major, minor, and patch components of a version:

  1. semver -t <<< '1.2.3-alpha+1' | cut -f 1-3

Download all artifacts in a version range:

  1. v='0.0.1'
  2. while curl -fs "https://example.com/artifact/$v.tar.gz" > "$v.tar.gz"; do
  3. v=$(semver -t <<< "$v" | awk -F '\t' '{ print $1 "." $2 "." ++$3 }')
  4. done

Find the current Git tag:

  1. git tag | semver -s | tail -n 1

Format versions as CSV:

  1. semver -tw < example.txt | tr '\t' ','

Validate a candidate version string:

  1. semver -q <<< '1.2.3' && echo 'ok'

Functions

These Bash helper functions can make complex versioning operations easier.

  1. #!/usr/bin/env bash
  2. function ++major {
  3. semver -t <<< "$1" | awk -F '\t' '{ print ++$1 "." 0 "." 0 }'
  4. }
  5. function ++minor {
  6. semver -t <<< "$1" | awk -F '\t' '{ print $1 "." ++$2 "." 0 }'
  7. }
  8. function ++patch {
  9. semver -t <<< "$1" | awk -F '\t' '{ print $1 "." $2 "." ++$3 }'
  10. }

Examples:

  1. ++major '1.2.3' #=> 2.0.0
  2. ++minor '1.2.3' #=> 1.3.0
  3. ++patch '1.2.3' #=> 1.2.4