Commit Script

Simple script to update the version number of a WordPress theme or plugin and commit it to a git repository.

#!/bin/bash

# Update version number and commit WordPress theme
# Uses https://gist.github.com/siddharthkrish/32072e6f97d7743b1a7c47d76d2cb06c
# Usage commit.sh style.css minor|build|major or commit.sh [pluginname.php] minor|build|major

fname=$1
semversion=$2

if [[ ! $fname ]]; then
  echo "usage: ./commit.sh [filename] [major/minor/build]"
  exit -1
fi

version=`grep 'Version' ${fname}`
major=0
minor=0
build=0

# break down the version number into it's components
regex="(Version: )([0-9]+).([0-9]+).([0-9]+)"
if [[ $version =~ $regex ]]; then
  major="${BASH_REMATCH[2]}"
  minor="${BASH_REMATCH[3]}"
  build="${BASH_REMATCH[4]}"
fi

old_version="${major}.${minor}.${build}"
# check paramater to see which number to increment
if [[ "$semversion" == "minor" ]]; then
  minor=$(echo $minor + 1 | bc)
elif [[ "$semversion" == "build" ]]; then
  build=$(echo $build + 1 | bc)
elif [[ "$semversion" == "major" ]]; then
  major=$(echo $major+1 | bc)
else
  echo "usage: ./commit.sh $fname [major/minor/build]"
  exit -1
fi
new_version="${major}.${minor}.${build}"
# echo the new version number
echo "Old version: ${old_version}"
echo "New version: ${new_version}"
sed -i "s/${old_version}/${new_version}/" ${fname}

# git
git tag $new_version
git add -A
git commit --all
git push origin $new_version
git push
echo "Completed"

Submit a comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s