Created
November 11, 2014 22:51
-
-
Save aijaz/03fb77a81bb9dbcb2f7f to your computer and use it in GitHub Desktop.
Pre-compile build phase for archives
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 | |
# prepareForArchive.sh | |
# ViewFinder | |
# | |
# Created by Aijaz Ansari on 10/13/13. | |
# Released under the MIT License | |
# This script should be run in a build phase that should occur | |
# before the 'Compile Sources' build phase for your target. | |
# Make sure to check the checkbox that says: | |
# "Run script only when installing." | |
# You only want to do this when making an archive for ad hoc distribution | |
# Expected environment variables | |
# From XCode: | |
# * PROJECT_DIR | |
# * PROJECT_NAME | |
# * TARGET_NAME | |
# From User-defined Build Settings: | |
# * JIRA_PREFIX - A string like 'MYPROJ' that starts every JIRA issue. | |
############################################################################################ | |
## STEP 1: Update the build version number in the plist files BEFORE building | |
# The main Plist | |
MASTERPLIST=${PROJECT_DIR}/${PROJECT_NAME}/${PROJECT_NAME}-Info.plist | |
# This target's plist | |
TARGETPLIST=${PROJECT_DIR}/${PROJECT_NAME}/${TARGET_NAME}-Info.plist | |
# This file is over-written on every archive | |
RELEASENOTES=${PROJECT_DIR}/Build/releaseNotes.md | |
# This file is used for the git commit | |
COMMITMESSAGE=${PROJECT_DIR}/Build/commit.md | |
# This is a list of Jira issues done since the last build | |
JIRAISSUES=${PROJECT_DIR}/Build/jira.md | |
# Every release's release notes are appended to this file | |
CHANGELOG=${PROJECT_DIR}/Build/changeLog.md | |
# temp file for atomic changes | |
TEMP=${PROJECT_DIR}/Build/changeLog.md.temp | |
# current date stamp | |
NOW=`date +"%Y/%m/%d %H:%M"` | |
# Adapted From: http://stackoverflow.com/a/15483906/772526 | |
# This splits a two-decimal version string, such as "0.45.123", allowing us to increment the third position. | |
# get the full version string FROM THE MASTER PLIST | |
VERSIONNUM=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$MASTERPLIST") | |
# extract the third part | |
NEWSUBVERSION=`echo $VERSIONNUM | awk -F "." '{print $3}'` | |
# increment it by 1 | |
NEWSUBVERSION=$(($NEWSUBVERSION + 1)) | |
# reconstruct the new version string | |
NEWVERSIONSTRING=`echo $VERSIONNUM | awk -F "." '{print $1 "." $2 ".'$NEWSUBVERSION'" }'` | |
# ...as well as CFBundleVersion | |
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $NEWVERSIONSTRING" "$MASTERPLIST" | |
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $NEWVERSIONSTRING" "$TARGETPLIST" | |
############################################################################################ | |
## STEP 2: Create a release note entry prepopulated from git logs. Insert that into | |
## the changelog file | |
# Get JIRA issues resolved | |
cd ${PROJECT_DIR} | |
/bin/rm $JIRAISSUES 2>/dev/null | |
# Look at all git commit logs until the last build | |
# Extract all lines that start with the JIRA_PREFIX or with a '!' | |
# Insert a '* ' in the beginning of every extracted line (slurping the '!', if present) | |
git log | perl -pe 'last if /^ *Build/' | grep -e "^ *${JIRA_PREFIX}" -e '^ *!' | perl -pe 's /^[ !]+/* /' > $JIRAISSUES | |
/bin/rm $TEMP 2>/dev/null | |
echo "## Build $NEWVERSIONSTRING :: $NOW :: $TARGET_NAME ####################" > $TEMP | |
echo "" >> $TEMP | |
cat $JIRAISSUES >> $TEMP | |
echo "" >> $TEMP | |
cat $CHANGELOG >> $TEMP | |
/bin/mv $TEMP $CHANGELOG | |
############################################################################################ | |
## STEP 3: Open the changelog file, giving the user to update the option of changing the | |
## release notes | |
# open with TextEdit, -W => Wait till exit, -n => open as a new app even if the app is already running | |
open -a /Applications/TextEdit.app -W -n $CHANGELOG | |
############################################################################################ | |
## STEP 4: Create a separate releaseNotes file. This will be used for the HockeyApp upload | |
/bin/rm $RELEASENOTES | |
# Take the first chunk of text out and put it into the release notes | |
perl -ne 'if (/^\#\#\s*Build\s/i) { exit if $found++ == 1; $first = 1} elsif ($first && !/\S/) { $first = 0; } else { print; }' $CHANGELOG > $RELEASENOTES | |
############################################################################################ | |
## STEP 5: Final git commit. Commit changes to the plist files, changelog and releasenote | |
## files. | |
# now make a git commit | |
/bin/rm $COMMITMESSAGE 2>/dev/null | |
echo "Build $NEWVERSIONSTRING :: $NOW" > $COMMITMESSAGE; | |
echo "" >> $COMMITMESSAGE; | |
cat $JIRAISSUES >> $COMMITMESSAGE | |
cd ${PROJECT_DIR} | |
git add $CHANGELOG $COMMITMESSAGE $JIRAISSUES $RELEASENOTES $MASTERPLIST $TARGETPLIST | |
git commit -q -F $COMMITMESSAGE | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment