Skip to content

Instantly share code, notes, and snippets.

@abury
Created November 29, 2011 11:44
Show Gist options
  • Save abury/1404526 to your computer and use it in GitHub Desktop.
Save abury/1404526 to your computer and use it in GitHub Desktop.
An extended iOS build Script showing a range of functions
#!/bin/sh
# Extended iOS Build Script
# Written by Aron Bury, 29/11/2011
#==== Script Params =====
# App params
appname="AwesomeApp"
target_name="$appname"
sdk="iphoneos"
configuration="Test"
app_version="1.0"
info_plist_name="$appname-info.plist"
#certificate params
certificate="iPhone Distribution: Awesome App Company"
identity="Awesome App Company"
# To use as a fixed script use the first project_dir varirable.
# If you are including it as a build step with Hudson, use the second variable passing in $WORKSPACE as the variable
#project_dir="$HOME/Documents/apps/$appname"
projet_dir="$1/$appname"
build_location="$HOME/Builds/$appname"
#testflight upload params
TESTFLIGHT_APIKEY="AAAAAAAAAAA"
TESTFLIGHT_TEAM="AAAAAAAAAAAA"
function makeBuild
{
#navigate to project directory
cd "$project_dir"
#get the current app version from the info.plist file
app_version=$(/usr/libexec/PlistBuddy -c "Print :CFBundleVersion" "$info_plist_name" || die "Failed to read version from $info_plist_name")
#Create folder location for build files if they dont exist
if [ ! -d "$build_location/$app_version/$configuration" ]; then
mkdir -p "$build_location/$app_version/$configuration"
fi
#Perform the build
xcodebuild -target "$appname" -configuration "$configuration" OBJROOT="$build_location/$app_version/$configuration/obj.root" SYMROOT="$build_location/$app_version/$configuration/sym.root"
#zip dYSM file for distribution
cd "$build_location/$app_version/$configuration/sym.root/$configuration-$sdk/" || die "Cannot locate .dysm file, no such directory"
rm -f "$appname.app.dSYM.zip"
zip -r "$appname.app.dSYM.zip" "$appname.app.dSYM"
#Sign and package
xcrun -sdk iphoneos PackageApplication -v "$build_location/$app_version/$configuration/sym.root/$configuration-$sdk/$appname.app" -o "$build_location/$app_version/$configuration/$appname.ipa" --sign "$certificate"
}
function deployToTestFlight
{
notifyTeam=$1
/usr/bin/curl "http://testflightapp.com/api/builds.json" \
-F file=@"$build_location/$app_version/$configuration/$appname.ipa" \
-F dsym=@"$build_location/$app_version/$configuration/sym.root/$configuration-$sdk/$appname.app.dSYM.zip" \
-F api_token="$TESTFLIGHT_APIKEY" \
-F team_token="$TESTFLIGHT_TEAM" \
-F notes="$appname uploaded via the testflight upload API"\
-F notify="$notifyTeam"
}
#import the certificate into the keychain
security import "$cert_file.p12" -P "supersecretpassword" -A -k ~/Library/Keychains/login.keychain || die "Failed to import security"
#Make the build
makeBuild
#Deploy to test flight and do not notify the team
deployToTestFlight "False"
#Remove the certificate from the keychain
security delete-certificate -c "$identity"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment