With this small cli tool, you can compare two versions with each other. Or perform other operations around the version number. Currently, it is important to know that we only compare the version core x.y.z
. This means that currently the pre-releases and the meta information are not taken into account. But you can read pre-releases and metadata from a version using our tool. For this you can use the core command.
Our version specifications are based on semantic versioning. Here you can find the corresponding definition. So that major, minor and patch can be read correctly, we use regex. You can find here at regex101 once the used expression.
If you have Go installed on your local machine, you can install the tool via the following command.
go install github.com/gowizzard/compver/v5@latest
If you don't want to install Go on your local machine, you can also use the binary. In order to install the tool correctly, you need to download it here and make it executable. After that you can move the binary into the application folder and use it via the terminal.
# Download the binary
curl -L -o compver https://github.com/gowizzard/compver/releases/latest/download/compver-<ARCH>-<OS>
# Make the binary executable
chmod +x compver
# Move to application directory
sudo mv compver /usr/local/bin
Here you can find the different statements you can use.
Actually, you don't need to know much to execute the command. You actually only compare the newest version with the older version. We assume that VERSION1
is the newer version and VERSION2
is the older one. But downgrades of versions can also be recorded.
compver -compare -version1 <VERSION1> -version2 <VERSION2>
If this command is executed now, we get an information back, this can contain the following information: no changes
, major update
, major downgrade
, minor update
, minor downgrade
, patch update
& patch downgrade
.
If you want to read a block of the version core, you can do this with the following command. You will receive the number of the block as an answer. You can read and return the blocks major
, minor
, patch
, prerelease
and buildmetadata
.
compver -core -block major -version1 <VERSION1>
So that you can also read versions that do not directly correspond to the semantic versioning, we have added the trim function. So you can also read and compare a version with a preceding v
by calling the prefix with the trim command as follows.
compver -core -block minor -version1 <VERSION1> -trim -prefix <PREFIX>
Here you can find an example if you want to use CompVer as a GitHub Action. In the example the action is only triggered when a new release is created.
I use this example a lot when I need to maintain major branches. Especially when developing Golang libraries this is very important. The action takes the release version and determines the major block of the version core. Then the version branch, for example v3
, is merged with the default branch, so that the version branch is always up-to-date. So you only have to create the branch once and don't have to worry about it not being maintained.
name: CompVer
on:
push:
tags:
- "v*.*.*"
env:
USER_NAME: "GitHub Action"
USER_EMAIL: "actions@github.com"
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
COMMIT_MESSAGE: "ci: The data of the master branch was merged automatically."
jobs:
version:
runs-on: ubuntu-latest
steps:
- name: Clone repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Get the major version
id: compver
env:
GITHUB_TOKEN: ${{ github.token }}
uses: gowizzard/compver@v5
with:
args: "-core -block major -version1 ${{ github.ref_name }} -trim -prefix v"
- name: Set git config
run: |
git config --local user.name "$USER_NAME"
git config --local user.email "$USER_EMAIL"
- name: Merge data from default branch
run: |
git fetch
git checkout v${{ steps.compver.outputs.core_result }}
git pull
git merge --no-ff "origin/$DEFAULT_BRANCH" -m "$COMMIT_MESSAGE"
git push
Thanks to JetBrains for supporting me with this and other open source projects.