Skip to content

Instantly share code, notes, and snippets.

@nico-martin
Last active November 9, 2018 07:16
Show Gist options
  • Save nico-martin/4a1b8aeb24ddd4937a2dde95f077c76b to your computer and use it in GitHub Desktop.
Save nico-martin/4a1b8aeb24ddd4937a2dde95f077c76b to your computer and use it in GitHub Desktop.
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