Skip to content

Instantly share code, notes, and snippets.

@augustj
Created November 25, 2014 23:42
Show Gist options
  • Save augustj/4f2e0db660aec78150fa to your computer and use it in GitHub Desktop.
Save augustj/4f2e0db660aec78150fa to your computer and use it in GitHub Desktop.
A script to build, sign and upload to TestFlight
#!/bin/bash
#
# testflightapp.com tokens
# This one is per user (and is August's)
API_TOKEN="XXX"
TEAM_TOKEN="XXX"
PRODUCT_NAME="myAppName"
BUNDLE_IDENTIFIER="com.carbonfive.foo"
PROJECT_DIR="$PWD"
INFOPLIST_FILE="myApp/myApp-Info.plist"
INFO_PLIST=${PROJECT_DIR}/${INFOPLIST_FILE}
ARTIFACTS="$PROJECT_DIR/Artifacts"
#SIGNING_IDENTITY="iPhone Developer: $1"
NOTES="$1"
if [[ `whoami` == "august" ]]; then
SIGNING_IDENTITY="iPhone Developer: August Jaenicke (XXXXXX)"
echo $SIGNING_IDENTITY
fi
echo -e "testflight.sh: Will sign code as $SIGNING_IDENTITY\n"
function write_bundle_identifier {
identifier=$1
/usr/libexec/Plistbuddy -c "Set CFBundleIdentifier ${identifier}" "${INFO_PLIST}"
}
function write_bundle_display_name {
bundle_name="\""$1"\""
echo $bundle_name
/usr/libexec/Plistbuddy -c "Set CFBundleDisplayName ${bundle_name}" "${INFO_PLIST}"
}
function write_build_number {
buildnum=$1
versionstring=$2
/usr/libexec/Plistbuddy -c "Set CFBundleVersion $buildnum" "${INFO_PLIST}"
/usr/libexec/Plistbuddy -c "Set CFBundleShortVersionString $versionstring" "${INFO_PLIST}"
echo "testflight.sh: Wrote build number=$buildnum version string=$versionstring"
}
# Externally facing versions (i.e. versions expressed in App Store marketing
# terms should look like: 1.0.0 and get generated by setting an annotated
# tag on the commit that got pushed, i.e.:
#
# $ git tag -a 1.0.0 -m 'Release 1.0!'
# Internally facing version, i.e. for us, look something like:
#
# $ git describe
# v0.1.179 (2b265b9)
function set_build_number {
configuration=$1 # e.g. "Developer" or "Acceptance"
versionstring=`git describe --dirty` # e.g. "1.0-8-4gvbgfa+"
versionnum=`git describe --abbrev=0` # e.g. "1.0"
datestamp=`/bin/date "+%y%m%d.%H%M"`
buildnum="$versionnum.$datestamp"
write_build_number $buildnum "$configuration-$versionstring"
}
function reset_build_number {
write_build_number "1" "2.0.5"
}
function build_and_upload {
configuration=$1
bundle_identifier="${BUNDLE_IDENTIFIER}.$1"
product_name_with_target="myApp $1"
# calculated vars
OUT_IPA="${ARTIFACTS}/${product_name_with_target}.ipa"
OUT_DSYM="${ARTIFACTS}/${product_name_with_target}.dSYM.zip"
# kill artifacts directory
rm -rf $ARTIFACTS
mkdir $ARTIFACTS
# compile
echo "testflight.sh: Compilation Started compiler='xcodebuild'"
set_build_number $configuration
write_bundle_identifier $bundle_identifier
write_bundle_display_name "$product_name_with_target"
xcodebuild -workspace myApp.xcworkspace -scheme myApp -sdk iphoneos8.1 -configuration $configuration CODE_SIGN_IDENTITY="${SIGNING_IDENTITY}" clean build archive
buildSucess=$?
reset_build_number
write_bundle_identifier $BUNDLE_IDENTIFIER
write_bundle_display_name "myApp"
if [[ $buildSucess != 0 ]] ; then
echo "testflight.sh: compiler error"
exit $buildSucess
fi
echo "testflight.sh: compilation Finished"
#ipa
echo "testflight.sh: Creating .ipa for ${PRODUCT_NAME}"
DATE=$( /bin/date +"%Y-%m-%d" )
ARCHIVE=$( /bin/ls -t "${HOME}/Library/Developer/Xcode/Archives/${DATE}" | /usr/bin/grep xcarchive | /usr/bin/sed -n 1p )
DSYM="Build/Products/${configuration}-iphoneos/myApp.app.dSYM"
APP="Build/Products/${configuration}-iphoneos/myApp.app"
PROVISIONING_PROFILE="$PROJECT_DIR/provisioning_profiles/myApp_TestFlight_${configuration}.mobileprovision"
/usr/bin/xcrun -sdk iphoneos PackageApplication -v "${APP}" -o "${OUT_IPA}" --sign "${SIGNING_IDENTITY}" --embed "${PROVISIONING_PROFILE}"
#symbols
echo "testflight.sh: Zipping .dSYM for ${PRODUCT_NAME}"
/usr/bin/zip -r "${OUT_DSYM}" "${DSYM}"
# prepare build notes
if [ -z "$NOTES" ]; then
NOTES='Add some notes'
fi
echo "Testflight build notes are [${NOTES}]"
#upload
echo "testflight.sh: Uploading ${PRODUCT_NAME} to TestFlight"
/usr/bin/curl "http://testflightapp.com/api/builds.json" \
-F file=@"${OUT_IPA}" \
-F dsym=@"${OUT_DSYM}" \
-F api_token="${API_TOKEN}" \
-F team_token="${TEAM_TOKEN}" \
-F notes="${NOTES}" \
-F notify="True" \
-F distribution_lists="${configuration}"
}
#build_and_upload "Developer" "${BUNDLE_IDENTIFIER}.developer"
build_and_upload "Acceptance"
build_and_upload "TestFlightRelease"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment