Git Product home page Git Product logo

version's Introduction

Version

Command line tool (and Go package) for keeping track of the versions of projects or directories. Version creates and maintains a .version file in the directory containing the current version number, and provides a command line tool to easily get, and update the version number.

Perfect for:

  • Automated build/release scripts
  • Integration with GitHub tags

Smart incrementing

Version increases numbers in a smart way, so if you increase the major version number it will automatically reset the minor and build numbers, like this:

  • v1.2.3 will jump to v1.3.0 if you increase the minor build number
  • v1.2.3 will jump to v2.0.0 if you increase the major build number

Command line

The version command line has the following syntax:

version [flags] path [option]
  • flags - Optionally any flags (see below)
  • path - Path to set the version for. Use ./ for current directory.
  • option
    • No option will just read and return the current value and will not change it
    • + Increase the build number (1.0.0 -> 1.0.1) and return the new value
    • ++ Increase the minor number (1.0.0 -> 1.1.0) and return the new value
    • +++ Increase the major number (1.0.0 -> 2.0.0) and return the new value

Supported flags

  • -n - Suppress the linefeed at the end of the output
  • -v=false - Do not print the v prefix
  • -short - Print the shortest possible representation of the version number, i.e. instead of v1.0.0, it will just output v1.

Download

Pick one that matches your machine:

Place it into your /usr/bin directory or equivalent.

Tips for writing scripts

Use backticks to get the current version and use it in another command:

echo `version ./`
= v1.0.0

Or get the version of another directory:

version /path/to/directory
= v2.3.1

Remove the linefeed using the -n flag:

echo `version -n ./`

Increase the build version at the same time as getting it using the + option:

echo `version -n ./ +`

If you find reading v1.0.0 annoying like we do, use the -short flag to give you the shortest possible representation:

version -short ./
= v1

To use the version multiple times, use variables:

VERSION=`version -n ./ +`; echo $VERSION; echo $VERSION; echo $VERSION

Releasing in GitHub

We built Version so we could write scripts that managed our GitHub releases, so it allows you to do things like this:

echo "Last version:" `version ./`

# increase the version and keep it in the VERSION variable
VERSION=`version -n ./ +`

echo "New version: $VERSION"

# get the human-readable version number
SHORTVERSION=`version -short -n ./`

echo "Tagging release..."

# Tag the new release
git tag -a `echo $VERSION` -m "Release SHORTVERSION"

echo "Updating version file..."

# Commit the new .version file, since it's changed
git commit .version -m "Updated to version $SHORTVERSION"

echo "Pushing changes..."

# push changes and tags
git push origin master
git push --tags

echo "Finished"

Development

Version is a Go package that you are welcome to use in your own projects.

To get started, go get the package:

go get github.com/matryer/version

Then you may use the version.Version object in your own programs.

version's People

Contributors

matryer avatar matryerfpd avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.