What is the smallest version base on Semantic Versioning 2.0.0? - semantic-versioning

What is the smallest version base on Semantic Versioning 2.0.0?
Semantic Versioning 2.0.0: https://semver.org/
https://go.dev/ref/mod go mod force me to use Semantic Versioning 2.0.0 as git tag. And I need to make sure my version is increase. I just commit my library first time, so I think I should use the smallest version as first version.

Base on my test the smallest version is v0.0.0-0 . No biggest version when string length is unlimited.
Here is my test base on some example:
https://gist.github.com/bronze1man/90aad9f41692c16895be3e499021dc73
valid (sort by smallest to biggest)
v0.0.0-0
v0.0.0-0+0
v0.0.0-2
v0.0.0-12
v0.0.0--0
v0.0.0-12alpha
v0.0.0-alpha
v0.0.0-alpha12
v0.0.0+0
v0.0.0
v0.0
v0
v0.0.1-0
v0.0.1-0.0
v0.0.1-0.0.0.0.0.0.0.0.0.1
v0.0.1-0.0.0.1
v0.0.1-0.0.1
v0.0.1-0.1
v0.0.1-1
v0.0.1-a
v0.0.1-alpha
v0.0.1
v0.0.2
v0.0.12
v1.0.0-0
v1
v1.0
v1.0.0
v2.0.0
v12.0.0
v99999999999999999999999999999999.0.0
invalid
v0.0.0.1
v0.0.0-000
v0.0.0-002
v0.0.0+
v0.0.0-
v0-0
v1-0

Related

Pin version of a 3rd party crate dependency

I have a crate that has several dependencies that use one common dependency, same as the root project. An intersecting range, though.
I.e.,:
[dependencies]
bitcoin="0.28"
hdpath="0.6" <- this one depends on `>=0.27`
hwkey="0.1" <- this one depends on `=0.28`
And the current latest version is bitcoin:0.29.2
The current Cargo.lock file contains bitcoin:0.28.1 so it all works for all of the deps and compiles fine.
But if I try to publish the crate there is no way to enforce it using the version from Cargo.lock and it tries to use two different version of bitcoin. The latest 0.29.2 for hdpath because it allows any version, and 0.28.1 for other parts because they are not compatible with the latest one.
That obviously doesn't work because it produces incompatible data types.
Is there any way to force Cargo to disable such an upgrade and use version from the lock file?

How I can bump the version to 1.0.0 by GitVersion

I operate git-version with git-flow.
I want to bump version up to 1.0.0 when I merge develop to main.
Version as of develop is 0.1.0, and I did merge it to main with commit message contains bumping keyword.
However it hit the constraint below, and the version didn't increment.
https://gitversion.net/docs/reference/version-increments
One thing to be aware of: If the current version is an alpha-version (i.e. 0.x.y.), attempting to bump the major version will merely bump the minor (eg from 0.2.0 to 0.3.0 instead of 1.0.0). Once the current version is greater than 1.0.0, bumping the major version works as expected.
I think this is very ordinary case, but we have the constraint in some reason. Why do we have it?
How can I bump my version to 1.0.0?
You need to git tag the commit on main, with v1.0.0. This will produce 1.0.0 semver, and also kickstart gitversion's semver calculation like how the documentation shows.
But wait, what? Why? 👇
0.1.0 is the default starting semver gitversion produces on a repository without ANY git tags with accompanying semver, like v1.2.3 and v0.3.2.
Without any git tags, even with commit log message bumps, gitversion will never produce any semver higher than 0.2.0.
The reason is gitversion expects you to use git tags to help initiate subsequent semver calculations.
But even if your repository has git tags like v0.2.0 or even v0.99.999, gitversion will still not produce any semver that breaks the major version barrier from 0 to 1, regardless of commit log message bumps.
The point is, when you have created the v1.0.0 git tag to that commit on main, then gitversion will function as the documentation describes.

Is Server canonical for NPM?

Which of these package version numbers is canonical for NPM?
2.0.0-pre1
2.0.0-pre.1
NPM just uses the semver package, which follows https://semver.org/, so there isn't any "npm-flavored" semver.
According to semver, both of your examples are valid prerelease versions; the only requirement is that the version number is followed by a hyphen and a series of dot-separated alphanumeric identifiers.
That said, in my opinion, the second is more idiomatic, assuming that you are trying to convey the idea of prerelease version "pre #1". 2.0.0-beta.37, makes it clear that this is beta #37, which comes after prelease beta #36 and before prelease beta #38; as opposed to 2.0.0-beta37, which is ambiguous: beta37 could mean beta #37, or it could be a codename for this particular prerelease, followed by 2.0.0-blue42 etc. etc.

semver: matching a pre-release suffix (3.* =/= 3.4.5-1)

Using this online semver checker: https://jubianchi.github.io/semver-check/
Notice how
version "3.4.5" is compatible with expression "3."
but...
version "3.4.5-1" is NOT compatible with expression "3."
How can I change my compatibility expression to include this pre-release version?
That's because pre-release versions are not included by default.
According to the docs:
SemVer comparisons without a pre-release comparator will skip pre-release versions. For example, >=1.2.3 will skip pre-releases when looking at a list of releases while >=1.2.3-0 will evaluate and find pre-releases.
In order to match that pre-release version, you could use, for example: ~3 >3.4.5-0.
3.4.5-1 satisfies constraint ~3 >3.4.5-0

How to release a beta version of a crate for limited public testing?

I want to carefully release a new version of a crate to give users a chance to test it first. How can I release it to crates.io as a "beta"? (similar to how npm has #next tagged releases).
It's not supposed to be a breaking change, so I'm not going to increase semver-major version. I don't want it to be automatically picked when users do cargo upgrade until the beta testing period ends.
What version syntax should I use for the release?
Do I need to use any special cargo options when releasing it?
How do users use cargo/Cargo.toml to opt in into the beta version?
Semantic versioning defines the concept of a pre-release version:
A pre-release version MAY be denoted by appending a hyphen and a series of dot separated identifiers immediately following the patch version. Identifiers MUST comprise only ASCII alphanumerics and hyphen [0-9A-Za-z-]. Identifiers MUST NOT be empty. Numeric identifiers MUST NOT include leading zeroes. Pre-release versions have a lower precedence than the associated normal version. A pre-release version indicates that the version is unstable and might not satisfy the intended compatibility requirements as denoted by its associated normal version. Examples: 1.0.0-alpha, 1.0.0-alpha.1, 1.0.0-0.3.7, 1.0.0-x.7.z.92
To use this in Cargo, publish a crate of the planned version number but append a pre-release identifier. I suggest -beta.0, allowing you to easily increase if you need a second:
[package]
name = "library"
version = "0.1.1-beta.0"
To use this, you need to specifically opt into it by putting beta into the version requirement:
[dependencies]
library = "0.1.1-beta"
To test this, I:
Spun up a local crates.io server
Uploaded the crate library with version 0.1.0
Used library = "0.1.0" in a binary project app — it resolved to 0.1.0
Uploaded the crate library with version 0.1.1-beta.0
Ran cargo update in app — the version did not change.
Changed to library = "0.1.1-beta" in app, ran cargo update — the version did change.
Uploaded the crate library with version 0.1.1-beta.1
Ran cargo update in app — the version did change.

Resources