Skip to content

Commit f7e23f8

Browse files
committed
Adds a script to detect and return the latest point release for a given major.minor version.
1 parent f4145fa commit f7e23f8

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

semver-get-pointrelease.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env bash
2+
# Search a list of local git tags for the "latest" matching the input argument.
3+
# Input must be in the form of: x.y
4+
# Can't rely on `sort -V` since it requires GNU coreutils.
5+
6+
if [ -z $1 ]; then
7+
exit 1
8+
fi
9+
10+
if [ -z $2 ]; then
11+
REPO_DIR=.
12+
else
13+
REPO_DIR=$2
14+
fi
15+
16+
git --work-tree="$REPO_DIR" --git-dir="$REPO_DIR/.git" tag -l 1>&2
17+
18+
MAJOR_MINOR=$1
19+
POINTRELEASE=$( git --work-tree="$REPO_DIR" --git-dir="$REPO_DIR/.git" tag -l | grep "^$MAJOR_MINOR" | sed "s/$MAJOR_MINOR\.//" | sort -n | tail -1 )
20+
21+
22+
if [ -z $POINTRELEASE ]; then
23+
exit 2
24+
fi
25+
26+
echo "$MAJOR_MINOR.$POINTRELEASE"

0 commit comments

Comments
 (0)