Skip to content

Instantly share code, notes, and snippets.

@nico-martin
Last active November 9, 2018 07:16
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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