Introducing semver-utils, an open-source tool for streamlined semantic versioning from automated pipelines. This post covers how to fetch and create semantic version tags in Git repositories, manage multiple version sets with prefixes, and integrate with CI/CD workflows.
semver-utils
comes with two binaries:semver
-- a simple CLI used to interact with semantic versions, broadly speaking it covers the following: bumping the major/minor/patch version, extracting version information, overriding version information, and comparing semantic version stringssemver-git
-- a CLI used to find existing semantic version tags against a git repository, and generate new ones when required by incrementing the desired major/minor/patch component, with optional support for setting a prefix, build and prerelease metadata.semver
CLI functions, the rest of this post will discuss how the semver-git
tool works.gitGraph
commit id: "a1" tag: "v0.0.0"
commit id: "a2"
commit id: "a3"
a1
) is tagged with the semantic version v0.0.0
.semver-git
to find the most recent semantic version tag searching back from the latest commit:# defaults to using the current working directory as the repository, searching backwards from the current HEAD commit
> semver-git fetch-tag
# semver-git prints out JSON formatted information about the discovered semantic version tag
{
"tag": "v0.0.0",
"version": "0.0.0",
"commit": "a1"
}
semver-git fetch-tag
without any parameters which means it uses defaults:a3
and searched backwards until it found commit a1
which had the tag v0.0.0
.fetch-tag
through the following parameters:Flag | Description | Default |
---|---|---|
--repo | Path to the Git repository to be searched | . |
--commit | Git reference for the commit to begin searching from | HEAD |
--exact | If specified, only tags on the exact --commit are checked | false |
create-tag
command is used to create a new semantic version tag on a specified commit. It auto-discovers the most recent semantic version by searching using the same logic as in fetch-tag
above and then creates a new tag by incrementing the desired semantic version component.# defaults to using the current working directory as the repository, searching backwards from the current HEAD commit
> semver-git create-tag
# semver-git prints out JSON formatted information about the newly created semantic version tag
{
"tag": "v0.0.1",
"version": "0.0.1",
"commit": "a3"
}
gitGraph
commit id: "a1" tag: "v0.0.0"
commit id: "a2"
commit id: "a3" tag: "v0.0.1"
a3
and searched backwards for a semantic versionv0.0.0
as the most recent version against commit a1
v0.0.1
v0.0.1
on commit a3
create-tag
command, we can affect the behavior of create-tag in quite a few ways:Flag | Description | Default |
---|---|---|
--repo | Path to the Git repository to be searched | . |
--commit | Git reference for the commit to begin searching from | HEAD |
--increment-type | Which component of the version to increment for new tags: major , minor , or patch | patch |
--annotated | If specified, creates an annotated Git tag | false |
--prerelease | Pre-release identifier to set on the new semver tag. For example: 1.2.3-alpha | none |
--build-metadata | Build metadata string to set on the created semver tag For example: 1.2.3+extended | none |
--push | If specified, the new tag will be immediately pushed to a remote repository | false |
--upstream | The name of the repository upstream where the tag should be pushed | origin |
--create-initial-version | If specified, and no previous semantic tag can be found, a new one will be created | false |
--initial-version | When using --create-initial-version , this flag specifies the newly created semantic (e.g., 0.0.0 ). | none |
semver-git create-tag
command into our automated pipelines including:fetch-tag
and create-tag
both operate on semantic version tags on a git repository with the format vX.Y.Z
, we refer to these as versions without a prefix.fetch-tag
and create-tag
commands can take a parameter named --prefix
. This parameter defaults to none
.--prefix
is not specified, the tool will search for (and create) semantic version tags with the format vX.Y.Z
--prefix
is specified (e.g., --prefix=foo
), the tool will search for (and create) semantic version tags in the format foo/vX.Y.Z
--prefix
value, giving you flexibility in how you structure them.gitGraph
commit id: "a1" tag: "foo/v0.0.0" tag: "bar/v0.0.0"
commit id: "a2"
commit id: "a3" tag: "foo/v0.0.1"
commit id: "a4"
commit id: "a5"
commit id: "a6" tag: "foo/v1.0.0" tag: "bar/v1.0.0"
semver-utils
useful. If you want to find more about CECG's approach to solving problems or how we can help you with all things Platform Engineering and Delivery, feel free to contact us.This article is provided as a general guide for general information purposes only. It does not constitute advice. CECG disclaims liability for actions taken based on the materials.
Discover more insights from our blog collection
The client is a large multinational that operates in different parts of the world with different products, requiring a flexible solution with configurable rules and integrations per region.
Learn how we implemented identity-based authentication for a developer platform using Google Identity-Aware Proxy (IAP) on GKE. This post covers our technical approach, from ingress architecture to overcoming IAP limitations, to provide secure, seamless access to internal services.
Explore the benefits and challenges of multi-tenancy in Kubernetes, with a detailed comparison of different models like multiple clusters, multiple control planes, and shared control planes. This post dives into frameworks such as Vcluster, Kamaji, HNC, and Capsule to help you choose the right approach for your organization.