Skip to content

Instantly share code, notes, and snippets.

@flovilmart
Last active December 28, 2015 03:19
Show Gist options
  • Save flovilmart/7434106 to your computer and use it in GitHub Desktop.
Save flovilmart/7434106 to your computer and use it in GitHub Desktop.
The ultimate TestFlight automated distribution script

How to use?

Setup your variables (User defined build settings)

  • TF_API_TOKEN="YOUR API TOKEN"
  • TF_TEAM_TOKEN="YOUR TEAM TOKEN"
  • TF_DISTRIBUTION_LISTS="Comma separated list for distribution"
  • TF_NOTIFY=True|False -> Notify the distribution list that a new build is available
  • TF_USE_GIT_LOG=0-n -> Will use the last n git logs (pretty) as note for distribution

Edit your scheme

  • go to Archive and drop the post-archive.sh script in there :)

Archive your project, sit back, relax and enjoy the ride!

# redirect to the log file
exec > /tmp/tf_upload.log 2>&1
# Open terminal window for tracking the logs
osascript <<EOF
tell app "Terminal"
activate
do script ("tail -f /tmp/tf_upload.log")
end tell
EOF
# Ultra verbose mode
set -x
# Print env variables
printenv
# Setup the terminal notifier (requires https://github.com/alloy/terminal-notifier)
# Allows showing poping notifications from Terminal
GROWL="terminal-notifier -title Testflight -message"
#setup the vars
DSYM="${ARCHIVE_DSYMS_PATH}/${PRODUCT_NAME}.app.dSYM"
APP="${ARCHIVE_PRODUCTS_PATH}/Applications/${PRODUCT_NAME}.app"
PROVISIONING_PROFILE="${APP}/${EMBEDDED_PROFILE_NAME}"
# Send to Notification Center
${GROWL} "Creating .ipa for ${PRODUCT_NAME}"
# Remove previous build
/bin/rm "/tmp/${PRODUCT_NAME}.ipa"
# Package and Sign
/usr/bin/xcrun -sdk iphoneos PackageApplication -v "${APP}" -o "/tmp/${PRODUCT_NAME}.ipa" --sign "${CODE_SIGN_IDENTITY}" --embed "${PROVISIONING_PROFILE}";
${GROWL} "Created .ipa for ${PRODUCT_NAME}"
${GROWL} "Zipping .dSYM for ${PRODUCT_NAME}"
/bin/rm "/tmp/${PRODUCT_NAME}.dSYM.zip"
/usr/bin/zip -r "/tmp/${PRODUCT_NAME}.dSYM.zip" "${DSYM}"
${GROWL} "Created .dSYM for ${PRODUCT_NAME}"
${GROWL} "Uploading to TestFlight"
NOTES="Build uploaded automatically from Xcode."
if [[ "$TF_USE_GIT_LOG" -ne 0 ]]
then
PWD=$(pwd)
cd ${PROJECT_DIR}
# Read the last archive Key
LAST_ARCHIVE_KEY=TFLastArchive
# Read the last archive time
LAST_ARCHIVE=$(defaults read ${PROJECT_DIR}/${INFOPLIST_FILE} ${LAST_ARCHIVE_KEY})
if [ -z "$LAST_ARCHIVE" ]
then
LAST_ARCHIVE=$(date -v "-4w" "+%Y-%m-%d %H:%M");
fi
# Get the notes
NOTES=$(git log --pretty="%h - %s" -${TF_USE_GIT_LOG} --since="${LAST_ARCHIVE}")
cd $PWD;
fi
/usr/bin/curl "http://testflightapp.com/api/builds.json" \
-F file=@"/tmp/${PRODUCT_NAME}.ipa" \
-F dsym=@"/tmp/${PRODUCT_NAME}.dSYM.zip" \
-F api_token="${TF_API_TOKEN}" \
-F team_token="${TF_TEAM_TOKEN}" \
-F distribution_lists="${TF_DISTRIBUTION_LISTS}" \
-F notify="${TF_NOTIFY}" \
-F notes="${NOTES}"
${GROWL} "Uploaded to TestFlight"
NOW=$(date "+%Y-%m-%d %H:%M");
#Update the last archive key
$(defaults write ${PROJECT_DIR}/${INFOPLIST_FILE} "${LAST_ARCHIVE_KEY}" "${NOW}");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment