Last active
November 9, 2018 07:16
-
-
Save nico-martin/4a1b8aeb24ddd4937a2dde95f077c76b to your computer and use it in GitHub Desktop.
pre-commit hook that increases the version of a WP-Theme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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