|
#!/bin/sh - |
|
|
|
# build data file that is included in the source |
|
# so we can automatically report Git repo information |
|
# in the application |
|
|
|
if [[ ! -d ".git" ]]; then |
|
versionNumber=`cat VERSION | grep version | awk '{print $2}'` |
|
lastCommitHash=`cat VERSION | grep commit | awk '{print $2}'` |
|
else |
|
echo "Building file" |
|
|
|
# cd ${PROJECT_DIR}/${PROJECT_NAME} |
|
gitDataFile="${CONFIGURATION_TEMP_DIR}/gitDataAutoGenerated.h" |
|
|
|
echo "Get Information from system" |
|
|
|
# Date and time that we are running this build |
|
buildDate=`date "+%F %H:%M:%S"` |
|
|
|
# Current branch in use |
|
currentBranchTemp=`git rev-parse --abbrev-ref HEAD` |
|
if [ -n "$currentBranchTemp" ] |
|
then |
|
currentBranch=$currentBranchTemp |
|
else |
|
currentBranch="" |
|
fi |
|
|
|
# Last hash from the current branch |
|
lastCommitHashTemp=`git rev-parse --short HEAD` |
|
if [ -n "$lastCommitHashTemp" ] |
|
then |
|
lastCommitHash=$lastCommitHashTemp |
|
else |
|
lastCommitHash="" |
|
fi |
|
|
|
# Date and time of the last commit on this branch |
|
lastCommitDateTemp=`git log --pretty=format:"%ad" --date=short -1` |
|
if [ -n "$" ] |
|
then |
|
lastCommitDate=$lastCommitDateTemp |
|
else |
|
lastCommitDate="" |
|
fi |
|
|
|
# Comment from the last commit on this branch |
|
lastCommitCommentTemp=`git log --pretty=format:"%s" -1` |
|
if [ -n "$" ] |
|
then |
|
lastCommitComment=$lastCommitCommentTemp |
|
else |
|
lastCommitComment="" |
|
fi |
|
|
|
# Last tag applied to this branch |
|
lastRepoTagTemp=`git describe --abbrev=0 --tags` |
|
if [ -n "$lastRepoTagTemp" ] |
|
then |
|
lastRepoTag=$lastRepoTagTemp |
|
else |
|
lastRepoTag="0.0.0" |
|
fi |
|
|
|
# Version number from VERSIONS file |
|
versionFileVersionTemp=`cat VERSION | grep version | awk '{print $2}'` |
|
if [ -n "$versionFileVersionTemp" ] |
|
then |
|
versionFileVersion=$versionFileVersionTemp |
|
else |
|
versionFileVersion="0.0.0" |
|
fi |
|
|
|
# Test version numbers |
|
vertest=`perl -e '($a,$b)=@ARGV; for ($a,$b) {s/(\d+)/sprintf "%5d", $1/ge}; print $a cmp $b;' $lastRepoTag $versionFileVersionTemp` |
|
|
|
if [[ "$vertest" -eq -1 ]]; then |
|
versionNumber=$versionFileVersionTemp |
|
else |
|
versionNumber=$lastRepoTag |
|
fi |
|
|
|
# Build the file with all the information in it |
|
echo "Create header file" |
|
|
|
echo "//-----------------------------------------" > $gitDataFile |
|
echo "// Auto generated file" >> $gitDataFile |
|
echo "// Created $buildDate" >> $gitDataFile |
|
echo "//-----------------------------------------" >> $gitDataFile |
|
echo "" >> $gitDataFile |
|
echo "#define BUILD_DATE @ \"$buildDate\"" >> $gitDataFile |
|
echo "#define GIT_CURRENT_BRANCH @ \"$currentBranch\"" >> $gitDataFile |
|
echo "#define GIT_LAST_COMMIT_HASH @ \"$lastCommitHash\"" >> $gitDataFile |
|
echo "#define GIT_LAST_COMMIT_DATE @ \"$lastCommitDate\"" >> $gitDataFile |
|
echo "#define GIT_LAST_COMMIT_COMMENT @ \"$lastCommitComment\"" >> $gitDataFile |
|
echo "#define GIT_LAST_REPO_TAG @ \"$lastRepoTag\"" >> $gitDataFile |
|
echo "#define VERSION_FILE_VERSION @ \"$versionFileVersion\"" >> $gitDataFile |
|
echo "#define AUTOVERSION $versionNumber" >> $gitDataFile |
|
fi |
|
|
|
|
|
echo "Create temporary Info.plist" |
|
# Make my own Info.plist file |
|
PLIST="${PROJECT_DIR}/${PROJECT_NAME}/Info" |
|
cp "${PROJECT_DIR}/${PROJECT_NAME}/Info-template.plist" ${PLIST}.plist |
|
|
|
# defaults write "${PLIST}" CFBundleShortVersionString ${lastRepoTag} |
|
# defaults write "${PLIST}" CFBundleVersion ${lastCommitHash} |
|
/usr/libexec/PlistBuddy -c "Set CFBundleShortVersionString ${versionNumber}" "${PLIST}.plist" |
|
/usr/libexec/PlistBuddy -c "Set CFBundleVersion ${lastCommitHash}" "${PLIST}.plist" |
|
|
|
defaults read "${PLIST}" |