Skip to content

Instantly share code, notes, and snippets.

@nico-martin nico-martin/pre-commit
Last active Nov 9, 2018

Embed
What would you like to do?
pre-commit hook that increases the version of a WP-Theme
#!/bin/bash
FILE=style.css
BRANCH=`git rev-parse --abbrev-ref HEAD`
# read every line and serach Version
while read line; do
if [[ $line == *"Version: "* ]]; then
VERSION=${line/Version: /}
fi
done < $FILE
# strip linebreak and non version chars from $VERSION
VERSIONNUM="${VERSION//[!0-9.-]/}"
# generate new version
NEWVERSION="${VERSIONNUM%.*}.$((${VERSIONNUM##*.}+1))"
# add BRANCH to version if not master
if [[ $BRANCH != "master" ]]; then
NEWVERSION="$BRANCH$NEWVERSION"
fi
# replace
sed -i -e 's/'"$VERSION"'/'"$NEWVERSION"'/g' $FILE
git add $FILE
# replace package.json
if [ -e package.json ]; then
sed -i '/version/s/[(0-9.",a-zA-Z)]*$/'"\"${NEWVERSION}\",/" package.json
git add package.json
fi
# replace composer.json
if [ -e composer.json ]; then
sed -i '/version/s/[(0-9.",a-zA-Z)]*$/'"\"${NEWVERSION}\",/" composer.json
git add composer.json
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.