Skip to content

Instantly share code, notes, and snippets.

@nrutman
Last active November 19, 2020 20:20
Show Gist options
  • Save nrutman/af3a5dfbc35ff4e9a08c88554d986eae to your computer and use it in GitHub Desktop.
Save nrutman/af3a5dfbc35ff4e9a08c88554d986eae to your computer and use it in GitHub Desktop.
A quick bash script to display the latest release and release candidate from a git repo (based on semver tagging)
#!/usr/bin/env bash
# Parses semantic tags from Git and displays the most recent release and the
# most recent release candidate
# Get up to date with origin
git fetch origin &> /dev/null
# Find the latest release tag and the latest RC tag
release=$(git tag --sort=v:refname | grep "^\\d\{1,4\}\.\\d\{1,4\}\.\\d\{1,4\}\$" | tail -1)
candidate=$(git tag --sort=v:refname | grep "^\\d\{1,4\}\.\\d\{1,4\}\.\\d\{1,4\}\-rc" | tail -1)
# Error if no versions were found
if [ -z "$release$candidate" ]
then
echo -e "\033[91mNo versions exist in this repository!"
exit 1
fi
# Display the latest versions
echo -e "\033[36m\033[1m* Release:\033[0m ${release}"
echo -e "\033[36m\033[1m* Candidate:\033[0m ${candidate}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment