Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a shell script to automatically update the version number #69

Merged
merged 2 commits into from
Mar 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions updateVersion.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/bash

# This script is used for automating the process of updating patch numbers.
# Specifically, it updates the version number in setup.cfg (Line 3) and setup.py (Line 12 & 13)
# You can provide the script with either major, minor or patch (Case sensitive)
# Example usage:
# If the current version is 1.4.0, running './updateVersion.sh major' will change
# the current version to 2.0.0

if [ "$1" = "" ]; then
echo "You must provide an argument for this script"
echo "Your argument must be either major, minor or patch"
echo "See version semantics for more"
exit
fi

if [ "$1" != "major" ] && [ "$1" != "minor" ] && [ "$1" != "patch" ]; then
echo "Incorrect argument provided"
echo "Your argument must be either major, minor or patch (Case sensivite)"
exit
fi

VERSION_STRING=$(cat setup.cfg | grep "version")

IFS=' '
read -ra VERSION_STRING_ARR <<< $VERSION_STRING

VERSION="${VERSION_STRING_ARR[@]:2:2}"

echo "Current Version: $VERSION"

IFS='.'

read -ra VERSION_NUMBERS <<< $VERSION

MAJOR=${VERSION_NUMBERS[@]::1}
MINOR=${VERSION_NUMBERS[@]:1:1}
PATCH=${VERSION_NUMBERS[@]:2:2}

if [ "$1" = "major" ]; then
PATCH="0"
MINOR="0"
MAJOR=$(( $MAJOR + 1))
fi

if [ "$1" = "minor" ]; then
PATCH="0"
MINOR=$(( $MINOR + 1))
fi

if [ "$1" = "patch" ]; then
PATCH=$(( $PATCH + 1))
fi

UPDATED_VERSION="${MAJOR}.${MINOR}.${PATCH}"

echo "Updated Version: $UPDATED_VERSION"

sed -i "s/version = ${VERSION}/version = ${UPDATED_VERSION}/" setup.cfg
sed -i "s/^ version=\"${VERSION}\",/ version=\"${UPDATED_VERSION}\",/" setup.py
sed -i "s/^ download_url=\"https:\/\/github.com\/Milind220\/Ozone\/archive\/refs\/tags\/v${VERSION}.tar.gz\",/ download_url=\"https:\/\/github.com\/Milind220\/Ozone\/archive\/refs\/tags\/v${UPDATED_VERSION}.tar.gz\",/" setup.py