Skip to content

Instantly share code, notes, and snippets.

@AlejandroJL
Last active February 26, 2022 23:55
Show Gist options
  • Save AlejandroJL/8155286 to your computer and use it in GitHub Desktop.
Save AlejandroJL/8155286 to your computer and use it in GitHub Desktop.
Xcode 5 automatic TestFlight build uploading and ready for Xcode Server CI Bots.

TestFlight Tokens

cd /var

sudo mkdir teamsserver

sudo chown _teamsserver teamsserver

https://www.testflightapp.com/account/#api

sudo -H -u _teamsserver git config --global testflight.apitoken YOUR_APITOKEN

https://www.testflightapp.com/dashboard/team/edit/

sudo -H -u _teamsserver git config --global testflight.teamtoken YOUR_TEAMTOKEN

In my case use different names to use different teams: testflight.teamOne, testflight.teamTwo

I use the latest commints from a date to implement them as a note TestFlight

git config --global testflight.teamOneLastUpdate "$(date +"%d/%m/%Y %T")"

Xcode

#!/bin/bash
#
# Based on the version of @mattvlasach https://gist.github.com/mattvlasach/7220329
#
# Valid and working as of 12/28/2013
# Xcode 5.0.2, Xcode Server
#
API_TOKEN=$(git config testflight.apitoken)
TEAM_TOKEN=$(git config testflight.teamtoken)
DISTRIBUTION_LISTS="Inytel"
PROVISIONING_PROFILE="/Library/Server/Xcode/Data/ProvisioningProfiles/Example.mobileprovision"
#EXAMPLE:"/Library/Server/Xcode/Data/ProvisioningProfiles/DocLink_InHouse_2013.mobileprovision"
SIGNING_IDENTITY="iPhone Developer: Example Inc"
#EXAMPLE:"iPhone Distribution: Unwired Revolution, LLC."
COMMITS_SINCE=$(git config testflight.teamOneLastUpdate)
# DO NOT EDIT BELOW HERE!
########################################
DSYM="/tmp/Archive.xcarchive/dSYMs/${PRODUCT_NAME}.app.dSYM"
IPA="/tmp/${PRODUCT_NAME}.ipa"
APP="/tmp/Archive.xcarchive/Products/Applications/${PRODUCT_NAME}.app"
# Clear out any old copies of the Archive
echo "Removing old Archive files from /tmp...";
/bin/rm -rf /tmp/Archive.xcarchive*
#Copy over the latest build the bot just created
echo "Copying latest Archive to /tmp/...";
LATESTBUILD=$(ls -1rt /Library/Server/Xcode/Data/BotRuns | tail -1)
/bin/cp -Rp "/Library/Server/Xcode/Data/BotRuns/${LATESTBUILD}/output/Archive.xcarchive" "/tmp/"
echo "Creating .ipa for ${PRODUCT_NAME}"
/bin/rm "${IPA}"
/usr/bin/xcrun -sdk iphoneos PackageApplication -v "${APP}" -o "${IPA}" --sign "${SIGNING_IDENTITY}" --embed "${PROVISIONING_PROFILE}"
echo "Done with IPA creation."
echo "Zipping .dSYM for ${PRODUCT_NAME}"
/bin/rm "${DSYM}.zip"
/usr/bin/zip -r "${DSYM}.zip" "${DSYM}"
echo "Created .dSYM for ${PRODUCT_NAME}"
echo "*** Preparing notes ***"
NOTES=$(git --git-dir /Library/Server/Xcode/Data/BotRuns/Cache/c5f9b6k9-966a-966a-931d-6535c78c1dbd/source/.git log --since="${COMMITS_SINCE}" --pretty=format:"%h %ad%d %s" | cat)
#EXPLAIN: c5f9b6k9-966a-966a-931d-6535c78c1dbd is the "bot" temp folder
echo "*** Prepared notes ***"
echo "*** Uploading ${PRODUCT_NAME} to TestFlight ***"
/usr/bin/curl "http://testflightapp.com/api/builds.json" \
-F file=@"${IPA}" \
-F dsym=@"${DSYM}.zip" \
-F api_token="${API_TOKEN}" \
-F team_token="${TEAM_TOKEN}" \
-F distribution_lists="${DISTRIBUTION_LISTS}" \
-F notify=False \
-F notes="${NOTES}"
git config --global testflight.teamOneLastUpdate "$(date +"%d/%m/%Y %T")"
echo "TestFlight upload finished!"
@kikolobo
Copy link

Hello.. Is this still valid for XCode7?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment