Skip to content

Instantly share code, notes, and snippets.

@cerupcat
Forked from JagCesar/.travis.yml
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cerupcat/579a08030971537bb937 to your computer and use it in GitHub Desktop.
Save cerupcat/579a08030971537bb937 to your computer and use it in GitHub Desktop.
language: objective-c
before_script:
- chmod +x scripts/travis/add-key.sh
- chmod +x scripts/travis/remove-key.sh
- chmod +x scripts/travis/testflight.sh
- ./scripts/travis/add-key.sh
script: xctool -workspace [Workspace name].xcworkspace -scheme '[Scheme to use]' -configuration [Build configuration name] -sdk iphoneos7.1 CONFIGURATION_BUILD_DIR='~/build/' build
after_success:
- ./scripts/travis/testflight.sh
after_script:
- ./scripts/travis/remove-key.sh
env:
global:
- DISTRIBUTION_LISTS="[Comma separated Testflight distributions lists]"
- APPNAME="[Name of .app file]"
- 'DEVELOPER_NAME="iPhone Distribution: [Organization name] ([User ID])"'
- PROFILE_NAME=[Name of provisioning file]

How to automagically deploy to Testflight using Travis-CI

  1. Copy the .travis.yml into your repo and edit it
    1. Replace [Workspace name] with your workspace name. If you don't have a .workspace file and wish to use your .xcodeproj file replace the -workspace flag with a -project flag followed by your project name.
    2. Replace [Scheme to use] with the Scheme you wish to use.
    3. Replace [Build configuration name] with the build configuration you want to use.
    4. Replace [Comma separated Testflight distributions lists] with the Testflight distributions lists.
    5. Replace [Name of .app file] with the name of your App. In most cases it's same name as your project name.
    6. Replace [Organization name] with the name of the organization defined in the certificate you will use to sign this App. You'll find this in your keychain. If the certificate has ([User ID]) at the end, don't forget to update [User ID]. If not, delete ([User ID]) and the brackets surrounding it.
    7. Replace [Name of provisioning file] with the file name of your provisioning file name without the extension.
  2. Create the folders "scripts/travis/profile"
  3. Export the following things from the Keychain app
    1. "Apple Worldwide Developer Relations Certification Authority" to scripts/travis/apple.cer
    2. Your iPhone Distribution certificate to scripts/travis/dist.cer
    3. Your iPhone Distribution private key to scripts/travis/dist.p12 (Important to choose a proper password)
  4. Execute travis encrypt "KEY_PASSWORD=[Your .p12 password]" --add
  5. Execute travis encrypt "TEAM_TOKEN=[Testflight team token]" --add
    1. You'll find your Team token here
  6. Execute travis encrypt "API_TOKEN=[Testflight API token]" --add
    1. You'll find your API token here
  7. Copy add-key.sh, remove-key.sh and testflight.sh to scripts/travis
  8. Copy your mobile provisioning profile to scripts/travis/profile/
  9. Stage all the new files, it should be:
    • .travis.yml
    • apple.cer
    • dist.cer
    • dist.p12
    • [Name of provisioning file].mobileprovision
    • add-key.sh
    • remove-key.sh
    • testflight.sh
  10. Commit and push!
  11. That's a Wrapp! ;)

Only sending to Testflight if branch is "build_testflight"

In testflight.sh on row 6 we check which branch is being built. At the moment it will only send it to Testflight if the current branch is named "build_testflight". Feel free to remove this if it doesn't suit your needs :)

security create-keychain -p travis ios-build.keychain
security default-keychain -s ios-build.keychain
security unlock-keychain -p travis ios-build.keychain
security -v set-keychain-settings -lut 86400 ios-build.keychain
security import ./scripts/travis/apple.cer -k ~/Library/Keychains/ios-build.keychain -T /usr/bin/codesign
security import ./scripts/travis/dist.cer -k ~/Library/Keychains/ios-build.keychain -T /usr/bin/codesign
security import ./scripts/travis/dist.p12 -k ~/Library/Keychains/ios-build.keychain -P $KEY_PASSWORD -T /usr/bin/codesign
mkdir -p ~/Library/MobileDevice/Provisioning\ Profiles
cp ./scripts/travis/profile/* ~/Library/MobileDevice/Provisioning\ Profiles/
security delete-keychain ios-build.keychain
rm -f ~/Library/MobileDevice/Provisioning\ Profiles/*
#!/bin/sh
if [[ "$TRAVIS_PULL_REQUEST" != "false" ]]; then
echo "This is a pull request. No deployment will be done."
exit 0
fi
if [[ "$TRAVIS_BRANCH" != "build_testflight" ]]; then
echo "Testing on a branch other than build_testflight. No deployment will be done."
exit 0
fi
# Thanks @djacobs https://gist.github.com/djacobs/2411095
PROVISIONING_PROFILE="$HOME/Library/MobileDevice/Provisioning Profiles/$PROFILE_NAME.mobileprovision"
RELEASE_DATE=`date '+%Y-%m-%d %H:%M:%S'`
OUTPUTDIR="/Users/travis/build"
echo "********************"
echo "* Signing *"
echo "********************"
xcrun -log -sdk iphoneos PackageApplication "$OUTPUTDIR/$APPNAME.app" -o "$OUTPUTDIR/$APPNAME.ipa" -sign "$DEVELOPER_NAME" -embed "$PROVISIONING_PROFILE"
RELEASE_NOTES="This version was uploaded automagically by Travis\nTravis Build number: $TRAVIS_BUILD_NUMBER\nUploaded: $RELEASE_DATE"
zip -r -9 "$OUTPUTDIR/$APPNAME.app.dSYM.zip" "$OUTPUTDIR/$APPNAME.app.dSYM"
echo "********************"
echo "* Uploading *"
echo "********************"
curl http://testflightapp.com/api/builds.json \
-F file="@$OUTPUTDIR/$APPNAME.ipa" \
-F dsym="@$OUTPUTDIR/$APPNAME.app.dSYM.zip" \
-F api_token="$API_TOKEN" \
-F team_token="$TEAM_TOKEN" \
-F distribution_lists=$DISTRIBUTION_LISTS \
-F notes="$RELEASE_NOTES" -v \
-F notify="FALSE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment