Skip to content

Instantly share code, notes, and snippets.

@mtinsley
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mtinsley/9977fb3211f43e71a32a to your computer and use it in GitHub Desktop.
Save mtinsley/9977fb3211f43e71a32a to your computer and use it in GitHub Desktop.
#!/bin/sh
# The following demonstrates how to add build numbers to your project.
# This script can be added to your .git/hooks/pre-commit file. Alternatively
# you can add it as a separate shell script and call it from your pre-commit
# file.
# Fetch and increment the build number
buildnumber=`git rev-list HEAD --count`
((buildnumber++))
# Write the build number to a file
echo $buildnumber > build
# Update a PHP class constant with the build number
sed -i "s/const BUILD.*/const BUILD = $buildnumber;/" Class.php>/dev/null 2>&1
# Add the modified files
git add build
git add Class.php
echo "Build Number: $buildnumber"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment