Post

Oneliner to compare software versions

A bash one-liner that compares local git tags against the latest GitHub release version to check if you are up to date.

This script fetches git tags from your local repository and compares them against the latest stable release from the GitHub API. It uses jq to filter out pre-releases and grep to extract the semantic version. If the latest release version is found among your local tags, it prints “match”.

1
2
3
4
5
6
export _tags=$(git tag --list  | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+')
export _current=$(curl -s  https://api.github.com/repos/hashicorp/vault/releases | \
jq -r '[.[] | select(.prerelease != true) | .name ] | first' | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+')

[[ $_tags =~ $_current ]] && echo "match" || echo "no match"

This post is licensed under CC BY 4.0 by the author.