Code Monkey home page Code Monkey logo

semver-tool's Introduction

The semver shell utility

semver is a little tool to manipulate version bumping in a project that follows the semver 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 with git pre-commit hooks to guarantee correct versioning.

Unit Tests and Linters GitHub release (latest by date) License

installation

The semver tool can be downloaded from github and made executable with these commands:

# Download the script and save it to /usr/local/bin
wget -O /usr/local/bin/semver \
  https://raw.githubusercontent.com/fsaintjacques/semver-tool/master/src/semver

# Make script executable
chmod +x /usr/local/bin/semver

# Prove it works
semver --version
# semver: 3.4.0

Most likely, you will want to insure that the directory containing semver is on your PATH.

See installation alternatives below.

usage

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 --version

Arguments:
  <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

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 rc.1 1.0.1
1.0.1-rc.1
$ semver bump prerelease rc.1 1.0.1
1.0.1-rc.1
$ semver bump prerel rc.. 1.2.0-beta2
1.2.0-rc.1
$ semver bump prerel 1.0.1-rc.1+build4423
1.0.1-rc.2
$ semver bump prerel beta. 1.1.0-beta2
1.1.0-beta3
$ semver bump build build.051 1.0.1-rc1.1.0
1.0.1-rc1.1.0+build.051
$ semver bump release v0.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 v1.0.1-rc1.1.0+build.051 V1.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
$ 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.1
prerelease
$ semver diff 10.1.4 10.1.4

$ semver diff 10.1.4-rc4 10.4.2-rc1
minor

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 prerelease 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
$ semver get release 1.2.3-rc.4+build.567
1.2.3
$ semver get prerel 1.2.3+build.568

$ semver get prerel 1.2.3-rc.4+build.569
rc.4
$ semver get prerel 1.2.3-rc-4+build.570
rc-4

Validate

$ semver validate 1.0.0
valid
$ semver validate 1
invalid

installation alternatives

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

asdf is a tool version manager. See the asdf documentation explaining how to set up asdf, install plugins and tools, and how to set/select versions.

The semver plugin handles the installation of the semver-tool. The plugin README file contains an example installation.

bpkg

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

git

Clone this repo (or download a specific release). Then, make install will (by default--this can be changed) install semver in /usr/local/bin.

developing semver

We welcome anyone wishing to contribute to semver. 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 makes reviewing 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.

the development environment

Once you have cloned the project, you have one main source file to work on: a bash script in src/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 in test 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 the semver 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 the bats testing framework. It's pretty easy and still in bash.

We also use shellcheck to "lint" our shell scripts. Your changes need to come through clean.

A custom test tool test/documentation-test makes sure that the examples in this REAME file are correct.

All the tests can be run via make. This same Makefile is used for CI testing (GitHub Actions) when a PR is submitted.

setting up test tools

One way to look at the testing environment is the following sequence of scenarios:

  1. 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 that the tools are set up correctly by running make test-local. Everything should pass.

  2. When my stuff works, and/or to make sure nothing else broke, I run make test-local The complete test suite is identical to the test suite run automatically when I submit a pull request. Except, except ... maybe I did not install the version of the test tool used in CI. I can check the tool version by looking in the DEPENDENCIES file. Of course, maybe it doesn't matter or maybe I'm exploring moving to a different test tool version: I want the local version to differ from the "stable" version!

  3. 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 test tools: the same ones that the CI workflow will use. Of course, I don't have to run this and it requires that I have Docker installed, configured, and running. On the other hand, once I have Docker available, I don't strickly have to even install the test tools in my environment. I can just run the tests via Docker and/or via the Makefile. It's user choice.

  4. When my pull request is sent, GitHub will kick off a workflow and make test-stable will be run. If this fails, it is most likely something about configuring the CI workflow or GitHub projects (or make versions?) ... not because my code is failing the tests. "It's not my fault!"

This can all be summarized as:

  1. Test by hand.
  2. Run the test suite locally.
  3. Run the test suite using the stable environment.
  4. Let GitHub Actions run the test suite using the stable environment.

a note about dev environments

It is almost inescapable that developers have to understand and manage their environments, and this can be a pain ... even for small projects. And it is often a source of subtle errors. If everything was "auto-magic", "batteries included"; then who--if not the dev's--is going to do the work to provide the batteries and magic?

But there are helpers available. One of them mentioned above is asdf. Plugins for bats and shellcheck are available meaning that you can use asdf to set up your semver-tool test environment as you wish: the current stable versions, exploratory versions, or surely one day the next stable versions.

semver-tool's People

Contributors

ah-clem avatar alyssais avatar azuenko avatar bradfordboyle avatar eviweb avatar fsaintjacques avatar haguenau avatar josephschmitt avatar jwerle avatar kbingham avatar kenjones-cisco avatar llonchj avatar mathew-fleisch avatar mrzasa avatar mymasse avatar particleflux avatar qyanu avatar ranger6 avatar tlahn avatar troian avatar wonno avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

semver-tool's Issues

"tag" badge in README.md file is inconsistent and confusing

The "tag" badge is:

  1. Dynamic: always returns the most recent tag
  2. Static: the "click through" URL always points to a specific tag, not the most recent
  3. Error prone: one has to remember to edit the badge (the static part) when a commit is tagged. This has not always been done.

Some design thought about this tag needs to be done: what it is supposed to represent?

The dynamic part is "nice" in that one can always find the most recent tag (release? -- might be a better choice!) no matter which version of the README one is looking at. You can see if you are on the most recent. Note there is a text field in the badge "stable version" which maybe hints at the purpose of the badge. Unfortunately, this text is not displayed and only if one has the discipline to only tag stable versions does it make sense. The label for this dynamic part, however, suggests that one is looking at the named tag. But this is not the case.

The static part is "nice" in that clicking on it gets you to a specific tag: just not necessarily the one that it advertised. For example, at version 3.1.0, if one clicks on the badge, one navigates to version 3.0.0 (where the badge still advertises 3.1.0). If you then click on the badge in version 3.0.0, one navigates to 2.0.0

Part of the problem is the required manual editing step to update the badge URL during the release process. But even if one did this, it is still confusing.

Suggested work: define what is really wanted: current stable release? most recent tag? pointer to the stable release that this commit is based on? ?? Then figure out how to represent it.

FYI: Issue #48 also covers badges. Might be a good idea to do a badge cleanup PR that resolves both issues.

Support docker version with build number

Docker versions can't use + in tag, hence build bump isn't available if you want to use semver in this case.
Can we have any customization to make different build syntax? like - instead + ?

Feature request: get '$major.$minor.*`

Thank you for this tool!

It would be nice to have the ability to construct requirement strings (eg. relax requirements while parsing the output of some package manager) through a template like $MAJOR.$MINOR.*. Of course this can be done by concatenating $(... get major).$(... get minor).*, but it will be more ergonomic to pass a template string in.

"release" subcommand not implemented for "get", documentation irregularities

The "release" subcommand is not implemented in the semver script and, in fact, causes a confusing error message if used. In addition, the "release" subcommand for "bump" is not completely documented in the public documentation (README.md): not in syntax, but example is given. "release" does work for "bump".

The external, public doc (README.md) does not correspond to the script's usage message. The usage message is correct.

"bats" test files are fragmented and inconsistent

Currently, there are three "bats" unit test files. There does not seem to be a motivation (why 3?), a naming convention, or consistency (different files test different things .. but then they sometimes overlap).
A clean-up is needed. Suggestion: a single file, with tests organised by type/functionality (simple and just fine for a simple tool); or factor this out into separate files (can do this later if there is really a need).

Request regarding "semver bump prerel"

Dear dev team,

I'm currently automating my build pipeline to apply semantic versioning. In the frontend app this is already working fine done with npm version.
Whenever I have a "feature" oder "bugfix" branch, the pipeline is calling "npm verion prerelease --preid=dev". The first "prelease" call is adding the prerelease but also bumping the patch version. So I can always call this function:

  • 0.1.0 --> 0.1.1-dev.1
  • 0.1.1-dev.1 --> 0.1.1-dev.2

Merging back to master then calls a patch bump ("npm version patch" from 0.1.1-dev.2 to 0.1.1).
As you can see, the patch bump is not increasing the patch but just removing the prerelease part.

semver bump works a little bit different:

  • semver bump prerel dev.. 0.1.0 --> 0.1.0-dev.1
  • semver bump prerel dev.. 0.1.0-dev.1 --> 0.1.0-dev.2
  • semver bump patch 0.1.0-dev.1 --> 0.1.1

My intuitive understanding is that npm patch bump works correctly. You want to switch from 1.0.0-rc.1 to 1.0.0

Now my question: Is there any option to make semver work the same way?

  1. Increaing the patch version in a prerelease bump in case there is no prerelease part yet
  2. Not increasing the patch version in a patch bump in case there is a prerelease part

Print the parts

It would be great, if your script could print all the specific parts of a given version, like:

semver get major 1.2.3
1
semver get minor 1.2.3
2
semver get patch 1.2.3
3
semver get prerel 1.2.3-rc.1
rc.1

README should factor out package manager installation notes

This simple tool with no dependencies except for bash (not even more modern versions) is easy to install: download the single script file to anywhere, make it executable, and (if desired) be sure it is on your PATH.

However, the script has also been packaged up by (at present) two other tools: adsf and bpkg. These package managers can also install semver and might be useful in certain contexts, especially if the package managers are already being used. It is doubtful that setting up a package manager just to install semver makes any sense. Maybe other package managers/installers will appear: RPM, Debian, ?, .. (lol!).

The package manager details, especially how to set them up, do not belong in the semver README installation notes. This project does not (and should not) test the package manager setup and semver packaging/configuration. Packaging is a downstream activity.

Proposed:

  1. The README file should contain pointers and a brief description of these package managers (a few lines). It should not contain set-up procedures.
  2. These notes should not distract from the simple procedure or get in the way of the main contents of the README. There should be pointer (link) to an "alternate installations" section to be found towards the end of the README from the "installation".

See the discussion of this in PR #65

I think it is great that others have found the semver tool useful to the point of doing downstream packaging! There is no reason that the semver project shouldn't reference these efforts. And, we shouldn't be breaking things for these efforts (e.g. arbitrary name changes, versioning hygiene, etc).

manipulate prerel numbered versions?

it would be great if this tool could bump the number of a prerel, for example something like

$ semver bump prerel alpha 1.2.3-alpha.3
1.2.3-alpha.4

Currently bumping a prerel strips any numbered versioning that prerelease version has.

Examples

Got any examples for the pre-commit hooks? And actual git usage?

asdf plugin

Not sure if you've heard of the asdf version manager, but I've created a plugin for this semver tool. Essentially asdf uses github releases to install specific binaries for each host system. Once asdf is installed, semver can now be installed with this new plugin

# Install asdf plugin for semver
asdf plugin add semver

# Install specific version
asdf install semver latest

# Set a version globally (on your ~/.tool-versions file)
asdf global semver latest

# Now semver commands are available
semver --version
semver: 3.2.0

Just wanted to share this, but didn't know where... feel free to close this issue whenever
https://github.com/mathew-fleisch/asdf-semver

Feature request: Add "validate" command

For a script I'm currently writing it would be nice to have an option to just validate a version string. Would it be possible to add something like semver validate 0.1.0-dev+001? And as a result it could return version 0.1.0-dev+001 does match the semver scheme. That would be really nice :)

Inconsistent re-naming of "is-nat"

It looks like in commit e0a836c, "is-nat" was renamed to "is:_nat" in src/semver. There is no mention of this (strange) naming in the commit log which was meant to resolve issue #42. Looks like a typo in a global substitution to me.

Fix: replace "is:_nat" with "is_nat" everywhere.

Feature request

Add a "sort" command, sorting version numbers read from STDIN.

"bump prerel" should support numerical increments

It is common that the pre-release portion of a semantic version string contains a numerical value that represents successive versions. E.g. "3.1.0-rc.1" or "1.0.0-beta2". When such numbering is used during the release process, it is this numerical value that is most frequently "bumped". Given the frequency of the operation and that fact that this operation is often tied to an automated build/test/release process (pushing out new candidates), it is advantageous to have an automated "bump". The current version of semver does not do this: in fact, the "bump prerel" command simply replaces the pre-release portion and drops any build portion. Any change to the numbering must either be done by hand, or, through some exterior process that needs to be designed, built, integrated, and maintained in the automated pipeline.

It is proposed that the common case of incrementing a trailing numerical value in the pre-release field be supported. It should be amenable to automated pipelines. It should not break the previous usage of "bump prerel". It should not introduce new options or commands if not needed (which I believe is feasible).

I have prototyped such an extension and am willing to move it forward towards a pull request unless there are objections.

The basic approach is that a current disallowed usage of "bump prerel" with a trailing dot can be used to introduce numerical bumping. In the proposed change the trailing dot denotes a numeric value that is either created or updated. Here are a few examples:

  1. semver bump prerel rc. 1.0.1 => 1.0.1-rc1
  2. semver bump prerel rc. 1.0.1-rc1 => 1.0.1-rc2
  3. semver bump prerel rc. 1.0.1-beta2 => 1.0.1-rc1
  4. semver bump prerel rc.. 1.0.1 => 1.0.1-rc.1
  5. semver bump prerel rc. 1.0.1-beta2+b1455 => 1.0.1-rc1
  6. semver bump prerel . 1.0.1 => 1.0.1-1

As well, an "implicit" scheme is supported where the existing pre-release portion is used as the base:

  1. semver bump prerel 1.0.1-rc1 => 1.0.1-rc2
  2. semver bump prerel 1.0.1-beta => 1.0.1-beta1
  3. semver bump prerel 1.0.1 => 1.0.1-1

The existing command is still supported:

  1. semver bump prerel rc.3 1.0.1-rc1 => 1.0.1-rc.3
  2. semver bump prerel rc 1.0.1-beta2+b1455 => 1.0.1-rc

N.B. examples 1 through 9 would cause an error in the current version either because of the trailing dot or the lack of a required argument. This lack of "backwards error compatibility" could be corrected by the use of an environment variable that forces complete backward compatibility with version 3.x.x of semver. I believe this is useful for non-regression testing, but not worth it for general use.

It seems to me that this proposed change does not imply a bump of the major version of semver.

definition for PRERELEASE and BUILD doesn't conform to semver 2.0.0

Hi François,

in https://github.com/fsaintjacques/semver-tool/blob/eb430f81c353feee4c4ab8206f0844d283e498dd/src/semver
in line 23 and following, the definition for PRERELEASE is given as follows:

PRERELEASE is an optional string composed of alphanumeric characters and hyphens

and the definition for BUILD is given as follows:

BUILD is also an optional string composed of alphanumeric characters and hyphens

The regex in line 5 of the same file seems to match these definitions.

However, the README.md in the repositorie's root folder explicitely declares compatibility with semver as defined by https://github.com/mojombo/semver which gives a slighty different definition for PRERELEASE and BUILD respectively. Quoted from there:

a series of dot separated identifiers
and further details the notion of "identifier" as follows:
Identifiers MUST comprise only ASCII alphanumerics and hyphen [0-9A-Za-z-].
Identifiers MUST NOT be empty.
Numeric identifiers MUST NOT include leading zeroes.

The definition as given by semver is at odds with the definition given by this script. I would consider this a bug (and therefore this bug report) and propose the following options of resolving it:

a) documentation and code-comments should state clearly that the difference is intended. preferably a reason or reasons should also be given as to why the difference exists.
b) the README.md in the root of this repository should explicitely reference semver 1.x, as this version has a different definition of PRERELEASE that is more similar to this script's implementation.
c) change this script's implementation in order to match the semver 2.x definition.

With regards to (a), i could not be of any help as i do not have knowledge of the development process that lead up to the current state.
Option (b) seems to be the quickest solution with regards to implementation effort. However, semver 2.x was released quite some time ago and is the de-facto norm. It seems to me, that when people make unqualified reference to "semver", that version 2 is meant.

Regarding option (c), i intend to attach a patch to this issue shortly.

with best wishes,

Max

Test dependencies obscure/confusing and not DRY

Looking at the GitHub action logs, I noticed the following:

asdf install semver latest
asdf global semver latest
semver --version
semver: 3.3.0

which seemed a bit strange because the action (unit tests and lint):

  1. should have been running against a non-released commit of semver
  2. appeared to be running against a non-latest release (we are at 3.4.0)

As well, the log output claim "asdf install semver latest" is simply the output of echo "asdf install semver latest". The actual install specifies version 3.3.0.

After I ran a couple tests, it turns out that the GitHub action tests do run (AFAICS) against the appropriate semver commit. Ouff.

On the other hand, the output is confusing and it's not clear what the point of downloading a specific version and echoing the version string when that is not (in most cases) the code being tested.

And more: the GitHub action code requires/downloads version 1.3.0 of Bats while the project moved to version 1.6.0 a bit before the GitHub action code was committed. On the upside, the action code did specify a version for the spellcheck dependency (the Makefile does not).

These problems seem to be the result of:

  1. non-DRY parameterization
  2. distributed dependency management
  3. two separate testing paths: a Makefile running tests under Docker and using *nix install; a GitHub action script (ci.yaml) with it's own test execution scripting and asdf installation

Suggested steps to clean this up (in priority order):

  1. At a minimum: specify exact and consistent versions for dependencies; maybe use variables rather than imbedded constants.
  2. Remove or clarify/adjust the script that downloads a specific release of semver and prints its version string; then tests something else.
  3. Create a little file with dependencies defined once and in one place. Use these definitions in the various scripts and tools.
  4. Eliminate the difference between local testing and automated (GitHub actions) testing: GitHub actions become wrappers around the local testing scripts/tools. If asdf installation is to be tested (good idea! same for the other installation methods!), it should be explicitly tested: not by simply using it as part of the GitHub actions.

Dots are not allowed in prerelease identifiers

Dots are not considered as valid in the prelease part:

> semver validate 3.2.0-2023.03.03.1
invalid

without the dots:

> semver validate 3.2.0-2301011
valid

Semver allows it:

A pre-release version MAY be denoted by appending a hyphen and a series of dot separated identifiers immediately following the patch version

Feature request: command to validate if something is a semver

We use a combination of the semver diff and bump to increment our docker images version based on included librairies in the docker file. However some of these libs don't use semver and we had to resort to a small hack. Having a command to check if something is a valid semver would be usefull.

Here is a snippet of what we are doing

set +e
semver get major ${CURRENT_APP_VERSION} >/dev/null 2>&1
IS_SEMVER=$?
set -e

if [[ ${IS_SEMVER} -eq 0 ]]; then
  NEW_IMAGE_VERSION=$(semver bump $(semver diff ${CURRENT_APP_VERSION} ${NEW_APP_VERSION}) ${CURRENT_IMAGE_VERSION})
else
  NEW_IMAGE_VERSION=$(semver bump major ${CURRENT_IMAGE_VERSION})
fi

What I would be looking at is removing the first 4 lines and basically using something like this instead

if [[ $(semver isvalid ${CURRENT_APP_VERSION}) -eq 0 ]]; then
  NEW_IMAGE_VERSION=$(semver bump $(semver diff ${CURRENT_APP_VERSION} ${NEW_APP_VERSION}) ${CURRENT_IMAGE_VERSION})
else
  NEW_IMAGE_VERSION=$(semver bump major ${CURRENT_IMAGE_VERSION})
fi

distribution packaging

Would be great to see this tool available right from the package repository. Personally I care about .deb but I imagine others would be interested in other package formats as well.

Merge semver-tool and git-semver?

Hi fsaintjacques

Independently of your tool (I only just found it now!) I built a git plugin for semantic versioning:

https://github.com/markchalloner/git-semver

This also has it's own plugin architecture that can be used for validating versions scattered around projects (e.g. change log, manifests etc), as well as a built in updater.

As the two project seem pretty complimentary, I was wondering if you would be interested in merging the two in a new independent organisation account and working together on it?

Thanks

prerel compare issue

Hello,

Following is correct :

$ ./semver.sh compare 0.2.0-rc3 0.2.0-rc2
1

But the following compare should return -1:

$ ./semver.sh compare 0.2.0-rc3 0.2.0-rc21
1

Maybe with 2 digits prerel :

$ ./semver.sh compare 0.2.0-rc03 0.2.0-rc21
-1

But the recent bump prerel is moving from 2 digits to 1 :

$ ./semver.sh bump prerel 0.2.0-rc01+1.2.8
0.2.0-rc2

Thanks for the code

Piping doesn't work

Maybe I'm doing something wrong, but seems as though this should work:

git tag --sort=v:refname | tail -n 1 | semver get major

Instead it errors and gives the usage guide

Licensing

I see this is licensed as GPLv3, is there a reason for being that restrictive?

I'm bundling the script into a project of mine which I was planning on releasing as MIT and I've read that they are not compatible. I'm not planning on making my project GPLv3, how should I proceed?

I'm not making any changes to the script, I'm just bundling it to avoid having to manually install it inside a docker container.

Thanks :)

semver validate exit codes

Hi community,

I'm raising an issue to see if anyone else would be interested in having exit codes returned when using the 'validate' command.

Since this tool is built with CI in mind, it would be useful if a pipeline, pre-commit hook, etc. could be failed due to a non-zero exit code on version validation, rather than just echoing valid/invalid.

What does everyone else think? Is there some gotcha that I didn't consider? Maybe it could be controlled with a flag to start with, e.g. --exit-code, so as to not break pipelines currently using this tool.

Thanks for your consideration

Never ending loop when trying to compare 2 version strings

Hi fsaintjacques.

At first, I want to thank You for such a great utility.

Despite the fact, that You primary targeted this tool for project usage, it also have possibility to compare 2 strings (which is my case):

semver compare <ver1> <ver2>

In case of compare two version strings, it ends in never ending loop when trying to find version file, since I'm running semver as utility (no .version file anywhere).
Maybe you should consider to load vesion file in case if only 1 parameter is passed (here) instead of doing that for each case (here).

Thanks in advance

Wrong result when comparing pre-release and normal version

Hi François,
as indicated in paragraph 11. of the semver specification v2.0.0:
When major, minor, and patch are equal, a pre-release version has lower precedence than a normal version, which means 1.0.0-alpha < 1.0.0
so running $ semver compare 1.0.0 1.0.0-alpha should result in 1 when it currently returns -1
best regards
Eric

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.