npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

civersion

v1.0.1

Published

Calculates the next semantic version. Designed to work with CI/CD pipelines to update version during a build based on which branch is being built

Downloads

3

Readme

BuildVersion

Automatically calculates the next semantic version, based on the branch being built and the current version of a project - designed for use in a CI/CD pipeline.

Install

npm install -g civersion

Usage

As a command line utility:

civersion -h

CI Version

  Automatically calculates the next semantic version, based on the branch being
  built and the current version of a project

Options

  -h, --help              Show usage
  -V, --verbose           Print extra logging info
  -z, --dumpConfig        Dump the default config out to the command line. Cannot be used with any
                          other options
  -d, --dryrun            If set, will show what the next version is without updating the output file
  -o, --outputFile        The name of the file where BuildVersion will write its results. Defaults to
                          version.json
  -c, --config            The config file to read. If this is specified then the default config will
                          not be used.
  -v, --version           The current version, whatever it may be
  -m, --master            The version that master is currently on, whatever it may be
  -b, --branch            The branch being built. Defaults to develop

By default, CI Version writes the calculated version to a file, which can be read to get the next version. The calculated value is set into currentVersion in the JSON object in the file. To get the info on the command line, run with the --dryrun flag, and the JSON will be written to STDOUT instead of a file.

What Version am I on Now?

The current version can be stored as a Git tag:

git tag -am "Tagging a build" 1.0.0

and retrieved with:

git describe --first-parent --exclude [a-zA-Z]* --tags --abbrev=0

This gets the tag that's on the current branch. It excludes tags that start with alphabetical characters, but isn't foolproof! TODO More work is needed here.

If you're using Git Flow (http://nvie.com/posts/a-successful-git-branching-model/) then the master branch may be tagged with a version that's ahead of other branches, such as develop. This comes after a release, which causes the release branch to be merged back into develop and master. This will trigger 2 builds, each of which will get new versions. The develop build will increment the semver Patch number, but the master build will increment Minor (depending on configuration). When development continues, we want the next develop build to increment from the version tag on the master branch.

To get the version of the master branch, you can run:

git describe --first-parent --exclude [a-zA-Z]* --tags --abbrev=0 origin/master

Forcing Versions

Occasionally you want to make a breaking change, which should bump the Major semver number to the next value. You can do this 2 ways, either by setting a pre-release tag on the master branch, or by using using the forceVersion setting in the configuration file. If you do this though, you'll need to remember to take the forceVersion setting out again after the release!

For example, to force the next version to be 2.0.0, you could tag your release branch:

git tag -am "Tagging to force the version" 2.0.0-rc.0

then make the release

git flow release finish
git push --all

The CICD server will then pick up the develop and master branches and build them, making the next master version 2.0.0.

Configuration

This covers which versions to increment when. By default, a run on the master branch will bump the Minor version and on develop, the Patch version. This is configurable though! Run BuildVersion with the --dumpConfig flag to see the JSON structure that defines the config. This is can be saved in a config file and modified, then used with the --config option.

The config specifies the Semver part that should be incremented. Build Version uses the NPM Semver (https://www.npmjs.com/package/semver) library under the hood to increment versions, and the level codes can be found in that library's docs.

TODO: Allow specification of pre-release labels in branch settings TODO: Allow regex patterns in branch settings to match complex branches such as feature/myNewFeature

{
  "forceVersion": "",
  "develop": {
    "level": "patch"
  },
  "master": {
    "level": "minor"
  },
  "release": {
    "level": "preminor"
  },
  "pullrequest": {
    "level": "prepatch"
  },
  "feature": {
    "level": "prepatch"
  }
}