- Notifications
You must be signed in to change notification settings - Fork0
githubFeature/semver-tool
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
semver is a little tool to manipulate version bumping in a project thatfollows thesemver 2.x specification. Its uses are:
- bump version
- extract specific version part
- compare versions
- identify most significant difference between two versions
- validate version syntax
It can be combined withgit
pre-commit hooks to guarantee correct versioning.
The semver tool can be downloaded from github and made executable with these commands:
# Download the script and save it to /usr/local/binwget -O /usr/local/bin/semver \ https://raw.githubusercontent.com/fsaintjacques/semver-tool/master/src/semver# Make script executablechmod +x /usr/local/bin/semver# Prove it workssemver --version# semver: 3.4.0
Most likely, you will want to insure that the directory containingsemver
is on yourPATH
.
Seeinstallation alternatives below.
Usage: semver bump major <version> semver bump minor <version> semver bump patch <version> semver bump prerel|prerelease [<prerel>] <version> semver bump build <build> <version> semver bump release <version> semver get major <version> semver get minor <version> semver get patch <version> semver get prerel|prerelease <version> semver get build <version> semver get release <version> semver compare <version> <other_version> semver diff <version> <other_version> semver validate <version> semver --help semver --versionArguments: <version> A version must match the following regular expression: "^[vV]?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(\-(0|[1-9][0-9]*|[0-9]*[A-Za-z-][0-9A-Za-z-]*)(\.(0|[1-9][0-9]*|[0-9]*[A-Za-z-][0-9A-Za-z-]*))*)?(\+[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$" In English: -- The version must match X.Y.Z[-PRERELEASE][+BUILD] where X, Y and Z are non-negative integers. -- PRERELEASE is a dot separated sequence of non-negative integers and/or identifiers composed of alphanumeric characters and hyphens (with at least one non-digit). Numeric identifiers must not have leading zeros. A hyphen ("-") introduces this optional part. -- BUILD is a dot separated sequence of identifiers composed of alphanumeric characters and hyphens. A plus ("+") introduces this optional part. <other_version> See <version> definition. <prerel> A string as defined by PRERELEASE above. Or, it can be a PRERELEASE prototype string followed by a dot. <build> A string as defined by BUILD above.Options: -v, --version Print the version of this tool. -h, --help Print this help message.Commands: bump Bump by one of major, minor, patch; zeroing or removing subsequent parts. "bump prerel" (or its synonym "bump prerelease") sets the PRERELEASE part and removes any BUILD part. A trailing dot in the <prerel> argument introduces an incrementing numeric field which is added or bumped. If no <prerel> argument is provided, an incrementing numeric field is introduced/bumped. "bump build" sets the BUILD part. "bump release" removes any PRERELEASE or BUILD parts. The bumped version is written to stdout. get Extract given part of <version>, where part is one of major, minor, patch, prerel (alternatively: prerelease), build, or release. compare Compare <version> with <other_version>, output to stdout the following values: -1 if <other_version> is newer, 0 if equal, 1 if older. The BUILD part is not used in comparisons. diff Compare <version> with <other_version>, output to stdout the difference between two versions by the release type (MAJOR, MINOR, PATCH, PRERELEASE, BUILD). validate Validate if <version> follows the SEMVER pattern (see <version> definition). Print 'valid' to stdout if the version is valid, otherwise print 'invalid'.See also: https://semver.org -- Semantic Versioning 2.0.0
Basic bumping operations
$ semver bump patch 0.1.00.1.1$ semver bump minor 0.1.10.2.0$ semver bump patch 0.2.00.2.1$ semver bump major 0.2.11.0.0$ semver bump patch 1.0.01.0.1$ semver bump prerel rc.1 1.0.11.0.1-rc.1$ semver bump prerelease rc.1 1.0.11.0.1-rc.1$ semver bump prerel rc.. 1.2.0-beta21.2.0-rc.1$ semver bump prerel 1.0.1-rc.1+build44231.0.1-rc.2$ semver bump prerel beta. 1.1.0-beta21.1.0-beta3$ semver bump build build.051 1.0.1-rc1.1.01.0.1-rc1.1.0+build.051$ semver bump release v0.1.0-SNAPSHOT0.1.0
Comparing version for scripting
$ semver compare 1.0.1-rc1.1.0+build.051 1.0.1-1$ semver compare v1.0.1-rc1.1.0+build.051 V1.0.1-rc1.1.00$ semver compare 1.0.1-rc1.1.0+build.051 1.0.1-rc1.1.0+build.0520$ semver compare 1.0.1-rc1.1.0+build.051 1.0.1-rb1.1.01$ semver compare 10.1.4-rc4 10.4.2-rc1-1$ semver compare 10.1.4-rc4 10.4.2-1234-1
Find most significant difference
$ semver diff 1.0.1-rc1.1.0+build.051 1.0.1prerelease$ semver diff 10.1.4 10.1.4$ semver diff 10.1.4-rc4 10.4.2-rc1minor
Extract version part
$ semver get patch 1.2.33$ semver get minor 1.2.32$ semver get major 1.2.31$ semver get prerel 1.2.3-rc.4rc.4$ semver get prerelease 1.2.3-rc.4rc.4$ semver get prerel 1.2.3-alpha.4.5alpha.4.5$ semver get build 1.2.3-rc.4+build.567build.567$ semver get release 1.2.3-rc.4+build.5671.2.3$ semver get prerel 1.2.3+build.568$ semver get prerel 1.2.3-rc.4+build.569rc.4$ semver get prerel 1.2.3-rc-4+build.570rc-4
Validate
$ semver validate 1.0.0valid$ semver validate 1invalid
The manual installation of the semver tool is simple: just place a single file where you want it.Sometimes,however, alternative installation mechanisms might be desired. Two such methods are referenced below.
asdf
is a tool version manager.See theasdf
documentation explaining how to set up asdf, install plugins and tools, and how to set/select versions.
Thesemver plugin handles the installation of the semver-tool. The plugin README file contains an example installation.
bpkg
is a lightweight bash package manager.It takes care of fetching the shell scripts, installing them appropriately,setting the execution permission and more.
The semver tool can be installed by running:
bpkg install -g semver-tool
Clone this repo (or download a specific release). Then,make install
will (by default--this can be changed) installsemver
in/usr/local/bin
.
We welcome anyone wishing to contribute tosemver
. Contributions can be new functionality, bug fixes, improvements to documentation, examples of usage (gists).
This is a small and rather simple tool: only one source file! So, it's not too hard to get started. A good starting place might be looking at the open issues.
Of course, submitting issues without being an active contributor is fine too. Just be aware that issues that basically ask for someone to add something usually don't get much traction: it's always good to explain why it's a good idea,how you would use it (i.e. your use-case), how other alternatives are not as good.
For a small project, there is a bit of rigor:
- Kick off a potential contribution by submitting an issue. It should solicit comments. Proposing a path forward is always good. Issues are often an "intention to submit a pull request".
- Being a semantic versioning tool, we are sort of sensitive to breaking changes, compatibility. Consistency is (almost) never a bad thing.
- Tests are expected. We even test documentation.
- Commit messages should explain what was changed, why, design choices.
- Readable code--including comments, consistent formatting, reasonable names--along with good commit messages makesreviewing work a pleasure. It also means that new contributors can ramp up quickly and old folks can sleep,wake up years later, and still catch up.
- We follow the usual Pull Request scheme. If you've submitted an issue (or commented on an existing one)and gotten positive feedback on a proposed direction, then getting your PR accepted should be smooth.Your PR should reference the issue(s) and indicate which issues it would close.A PR out of the blue is generally a waste of everyone's time.
Once you have cloned the project, you have one main source file to work on: a bash script insrc/semver
.Use your favorite editor or IDE. The basic cycle is "hack-test-hack".Of course, test driven developement works just fine here: write failing tests intest
and then get them to pass.Might as well: you will need to write that test sooner or later.
Oh, you might not be working on thesemver
script itself: you might be working on documentation (written in MarkDown) or the Makefile, or maybe the CI workflow (yaml
). But still, pretty simple stuff.
We use thebats
testing framework. It's pretty easy and still inbash
.
We also useshellcheck
to "lint" our shell scripts. Your changes need to come through clean.
A custom test tooltest/documentation-test
makes sure that the examples in this REAME file are correct.
All the tests can be run viamake
. This same Makefile is used for CI testing (GitHub Actions) when a PR is submitted.
One way to look at the testing environment is the following sequence of scenarios:
I use the test tools by hand on a specific change or test I'm working on.So, I'll need to install these tools in my work environment. Before starting work, I check thatthe tools are set up correctly by running
make test-local
. Everything should pass.When my stuff works, and/or to make sure nothing else broke, I run
make test-local
The complete test suiteis identical to the test suite run automatically when I submit a pull request. Except, except ... maybeI did not install the version of the test tool used in CI. I can check the tool version by lookingin theDEPENDENCIES
file. Of course, maybe it doesn't matter or maybe I'm exploring moving toa different test tool version: Iwant the local version to differ from the "stable" version!When I'm ready to submit a PR and so as to avoid the embarrasment of failing the CI workflow, I can run
make test-stable
. This runs the same tests as above, but uses currated Docker images of the testtools: the same ones that the CI workflow will use. Of course, I don'thave to run this and itrequires that I have Docker installed, configured, and running. On the other hand, once I have Dockeravailable, I don't strickly have to even install the test tools in my environment. I can justrun the tests via Docker and/or via the Makefile. It's user choice.When my pull request is sent, GitHub will kick off a workflow and
make test-stable
will be run. If thisfails, it is most likely something about configuring the CI workflow or GitHub projects(ormake
versions?) ... not because my code is failing the tests. "It's not my fault!"
This can all be summarized as:
- Test by hand.
- Run the test suite locally.
- Run the test suite using the stable environment.
- Let GitHub Actions run the test suite using the stable environment.
It is almost inescapable that developers have to understand and manage their environments, and thiscan be a pain ... even for small projects. And it is often a source of subtle errors. If everythingwas "auto-magic", "batteries included"; then who--if not the dev's--is going to do the work toprovide the batteries and magic?
But there are helpers available. One of them mentioned above isasdf
.Plugins forbats
andshellcheck
are available meaning that you can useasdf
to set up yoursemver-tool
test environment as you wish: the current stable versions, exploratory versions, orsurely one day the next stable versions.
About
semver bash implementation
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Languages
- Shell91.6%
- Makefile8.4%