Skip to content

Instantly share code, notes, and snippets.

@icheko
Forked from pete-otaqui/bumpversion.sh
Last active August 29, 2015 14:09
Show Gist options
  • Save icheko/101b38c18b2a29c01831 to your computer and use it in GitHub Desktop.
Save icheko/101b38c18b2a29c01831 to your computer and use it in GitHub Desktop.
Bump version for PHP projects
#!/bin/bash
# works with a file called VERSION in the current directory,
# the contents of which should be a semantic version number
# such as "1.2.3"
# this script will display the current version, automatically
# suggest a "minor" version update, and ask for input to use
# the suggestion, or a newly entered value.
# once the new version number is determined, the script will
# commit the version change.
#
# Hat tip: https://gist.github.com/pete-otaqui/4188238
PHP_VERSION_FILE=app_version.php
PHP_VERSION_ENV_NAME=APP_VERSION
if [ -f VERSION ]; then
BASE_STRING=`cat VERSION`
BASE_LIST=(`echo $BASE_STRING | tr '.' ' '`)
V_MAJOR=${BASE_LIST[0]}
V_MINOR=${BASE_LIST[1]}
V_PATCH=${BASE_LIST[2]}
echo "Current version : $BASE_STRING"
V_MINOR=$((V_MINOR + 1))
V_PATCH=0
SUGGESTED_VERSION="$V_MAJOR.$V_MINOR.$V_PATCH"
read -p "Enter a version number [$SUGGESTED_VERSION]: " INPUT_STRING
if [ "$INPUT_STRING" = "" ]; then
INPUT_STRING=$SUGGESTED_VERSION
fi
echo "Will set new version to be $INPUT_STRING"
echo $INPUT_STRING > VERSION
echo -e "<?php\ndefine('$PHP_VERSION_ENV_NAME', '$INPUT_STRING');" > $PHP_VERSION_FILE
git add VERSION $PHP_VERSION_FILE
git commit -m "Version bump to $INPUT_STRING"
else
echo "Could not find a VERSION file"
read -p "Do you want to create a version file and start from scratch? [y] " RESPONSE
if [ "$RESPONSE" = "" ]; then RESPONSE="y"; fi
if [ "$RESPONSE" = "Y" ]; then RESPONSE="y"; fi
if [ "$RESPONSE" = "Yes" ]; then RESPONSE="y"; fi
if [ "$RESPONSE" = "yes" ]; then RESPONSE="y"; fi
if [ "$RESPONSE" = "YES" ]; then RESPONSE="y"; fi
if [ "$RESPONSE" = "y" ]; then
echo "0.1.0" > VERSION
echo -e "<?php\ndefine('$PHP_VERSION_ENV_NAME', '0.1.0');" > $PHP_VERSION_FILE
git add VERSION $PHP_VERSION_FILE
git commit -m "Added VERSION files, Version bump to 0.1.0"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment