Skip to content

Commit

Permalink
Adding the automatic next version detection
Browse files Browse the repository at this point in the history
  • Loading branch information
brahle committed Sep 8, 2023
1 parent 631fdb3 commit b04794f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
34 changes: 34 additions & 0 deletions next_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash

# Get the list of tags and sort them in version order
LATEST_TAG=$(git tag -l | sort -V | tail -n1)

# Split the tag into major, minor, and patch versions
IFS='.' read -ra ADDR <<< "$LATEST_TAG"
MAJOR=${ADDR[0]}
MINOR=${ADDR[1]}
PATCH=${ADDR[2]}

# Decide which part to increment based on the passed argument
case "$1" in
--major)
MAJOR=$((MAJOR+1))
MINOR=0
PATCH=0
;;
--minor)
MINOR=$((MINOR+1))
PATCH=0
;;
--patch)
PATCH=$((PATCH+1))
;;
*)
# By default increment minor version
MINOR=$((MINOR+1))
PATCH=0
;;
esac

# Print the next version
echo "$MAJOR.$MINOR.$PATCH"
4 changes: 2 additions & 2 deletions release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
# Display warning
echo "WARNING: This operation will create a version tag and push to GitHub"

# Ask for version input
read -p "Version? (provide the next x.y.z semver) : " TAG
# Get the next version
TAG=$(./next_version.sh "$@")

# Display the version
echo "Releasing version '${TAG}'"
Expand Down

0 comments on commit b04794f

Please sign in to comment.