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"
Updated script for themes
This could be easily updated for plugins.
#!/bin/bash
# Update version number and commit WordPress theme
# Uses https://gist.github.com/siddharthkrish/32072e6f97d7743b1a7c47d76d2cb06c
# Usage commit-theme.sh style.css minor|build|major
# style.css
themename=$1
level=$2
currentdir=`pwd `
if [[ $themename ]]
then
cd "/srv/www/html/wordpress/wp-content/themes/${themename}"
fname="style.css"
else
echo "usage: ./commit-theme.sh [themename] [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 [[ "$level" == "minor" ]]; then
minor=$(echo $minor + 1 | bc)
build="0"
elif [[ "$level" == "build" ]]; then
build=$(echo $build + 1 | bc)
elif [[ "$level" == "major" ]]; then
major=$(echo $major+1 | bc)
build="0"
minor="0"
else
echo "usage: ./commit-theme.sh [theme] [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"
cd $currentdir