Created
May 12, 2014 14:10
-
-
Save coderaaron/cd38146fe1cc321675d3 to your computer and use it in GitHub Desktop.
Pre-commit hook to bump version number
This file contains hidden or 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/sh | |
# Standard WUSM version numbering: | |
# year.month.day.commit | |
# | |
# This script searches all files in the git repo | |
# and bumps the version number | |
new=$(date +"%y.%m.%d.0") | |
a=( ${new//./ } ) | |
file=$(grep -lir "Version:" *.php) | |
while read -r line | |
do | |
if [[ $line == *Version:* ]]; | |
then | |
old=$line | |
c=${line#Version:} | |
b=( ${c//./ } ) | |
if [ ${a[0]} == ${b[0]} ] && [ ${a[1]} == ${b[1]} ] && [ ${a[2]} == ${b[2]} ]; then | |
# already had a commit today, just bump commit number | |
((b[3]++)) | |
new="${a[0]}.${a[1]}.${a[2]}.${b[3]}" | |
else | |
# first commit of the day | |
new="${a[0]}.${a[1]}.${a[2]}.0" | |
fi | |
fi | |
done <$file | |
find_this=$c | |
replace_with=$new | |
echo "Incrementing version from $c to $new\n" | |
ag -l $find_this $* | xargs sed -i '' "s/$find_this/$replace_with/g" | |
#this is kinda annoying, but it works | |
git add . |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment