Skip to content

Instantly share code, notes, and snippets.

@ChrisXu
Last active January 16, 2019 22:14
Show Gist options
  • Star 14 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChrisXu/23e05c6fe469c6a8aaf6 to your computer and use it in GitHub Desktop.
Save ChrisXu/23e05c6fe469c6a8aaf6 to your computer and use it in GitHub Desktop.
Deploy an app automatically to Fabric Beta using Travis-CI.
language: objective-c
osx_image: xcode7.2
xcode_sdk: iphonesimulator9.2
env:
global:
- LANG=en_US.UTF-8
- WORKSPACE="YOUR_APP_WORKSPACE/YOUR_APP_PROJECT.xcworkspace"
- SCHEME="YOUR_BUILDSCHEME"
- APP_NAME="YOUR_APP_NAME"
- EMAILS="tester@mail, someone@mail"
- GROUP_ALIASES="$FABRIC_GROUP"
- PROFILE_NAME="distribution_profile"
- 'DEVELOPER_NAME="iPhone Distribution: NAME_OF_THE_DEVELOPER (CODE)"'
matrix:
- DESTINATION="generic/platform=iOS" SDK="iphoneos"
before_script:
- "./travis/scripts/add-key.sh"
script:
- xctool clean build -workspace "$WORKSPACE" -scheme
"$SCHEME" -sdk "$SDK" -destination "$DESTINATION" -configuration Release OBJROOT=$PWD/build
SYMROOT=$PWD/build ONLY_ACTIVE_ARCH=NO 'CODE_SIGN_RESOURCE_RULES_PATH=$(SDKROOT)/ResourceRules.plist'
after_success:
- "./travis/scripts/sign-and-upload.sh"
after_script:
- "./travis/scripts/remove-key.sh"

Ref

Instructions

####Deploy an app automatically to Fabric Beta using Travis-CI.

  1. Copy the .travis.yml into your repo
  2. Replace the following fields
    • WORKSPACE
    • SCHEME (build scheme)
    • APP_NAME
    • DEVELOPER_NAME
    • PROFILE_NAME
    • EMAILS (those who you want to notify)
    • GROUP_ALIASES (group for tester on Fabric)
  3. Create the folder "travis/certs"
  4. Export the following things from the Keychain app
    • "Apple Worldwide Developer Relations Certification Authority" into travis/certs/apple.cer
    • Your iPhone Distribution certificate into travis/certs/ios_distribution.cer
    • Your iPhone Distribution private key into travis/certs/ios_distribution.p12 (choose a password)
  5. Create the folder "travis/profile"
  6. Export iOS Provisioning Profile (Distribution) into travis/profile/distribution_profile.mobileprovision
  7. Create the folder "travis/scripts"
  8. Copy add-key.sh, remove-key.sh and sign-and-upload.sh into travis/scripts
  9. Download submit into travis/.
    • I manually pull out the 'submit' file in Crashlytics.framework(3.6.0). Please let me know if it has new update, I will renew the file
  10. Execute travis encrypt "DIST_PWD=YOUR_DISTRIBUTION_PASSWORD" --add
  11. Execute travis encrypt "FABRIC_API_KEY=YOUR_FABRIC_API_KEY" --add
  12. Execute travis encrypt "FABRIC_BUILD_SECRET=YOUR_FABRIC_BUILD_SECRET" --add
  13. Commit

Files structure

Your files will look like this

  • Repo Root
    • Project folder
    • .travis.yml
    • travis
      • submit
      • certs
        • ios_distribution.cet
        • ios_distribution.p12
      • profile
        • distribution_profile.mobileprovision
      • scripts
        • add-key.sh
        • remove-key.sh
        • sign-and-upload.sh
# Create a custom keychain
security create-keychain -p travis ios-build.keychain
# Make the custom keychain default
security default-keychain -s ios-build.keychain
# Unlock the keychain
security unlock-keychain -p travis ios-build.keychain
# Set keychain timeout to 1 hour for long builds
security set-keychain-settings -t 3600 -l ~/Library/Keychains/ios-build.keychain
# Add certificates to keycahin adn allow codesign to access them
security import ./travis/certs/apple.cer -k ~/Library/Keychains/ios-build.keychain -T /usr/bin/codesign
security import ./travis/certs/ios_distribution.cer -k ~/Library/Keychains/ios-build.keychain -T /usr/bin/codesign
security import ./travis/certs/ios_distribution.p12 -k ~/Library/Keychains/ios-build.keychain -P $DIST_PWD -T /usr/bin/codesign
# Put the provisioning profile in place
mkdir -p ~/Library/MobileDevice/Provisioning\ Profiles
cp ./travis/profile/* ~/Library/MobileDevice/Provisioning\ Profiles/
# Delete keychain
security delete-keychain ios-build.keychain
# Remove provisioning profile
rm -f ~/Library/MobileDevice/Provisioning\ Profiles/*
#!/bin/sh
# Skip uploading if it is a pull request. you can mark this if you don't need it
if [[ "$TRAVIS_PULL_REQUEST" != "false" ]]; then
echo "This is a pull request. No deployment will be done."
exit 0
fi
# Skip uploading if it is not on master. you can mark this if you don't need it
if [[ "$TRAVIS_BRANCH" != "master" ]]; then
echo "Testing on a branch other than master. No deployment will be done."
exit 0
fi
# Construct the infomation for this build
COMMIT_MESSAGE=`git log -1 --no-merges --pretty="%h - %s"`
GIT_REVISION=$(git rev-parse --short HEAD)
RELEASE_DATE=`date '+%Y-%m-%d %H:%M:%S'`
echo "********************"
echo "* Signing *"
echo "********************"
PROVISIONING_PROFILE="$HOME/Library/MobileDevice/Provisioning Profiles/$PROFILE_NAME.mobileprovision"
OUTPUTDIR="$PWD/build/Release-iphoneos"
# Package the ipa
xcrun -log -sdk iphoneos PackageApplication "$OUTPUTDIR/$APP_NAME.app" -o "$OUTPUTDIR/$APP_NAME.ipa" -sign "$DEVELOPER_NAME" -embed "$PROVISIONING_PROFILE"
# Create release note file
echo "Build: $GIT_REVISION\nDate: $RELEASE_DATE\nNote: $COMMIT_MESSAGE" > $OUTPUTDIR/release_note.txt
RELEASE_NOTES_PATH="$OUTPUTDIR/release_note.txt"
IPA_PATH="$OUTPUTDIR/$APP_NAME.ipa"
echo "********************"
echo "* Uploading *"
echo "********************"
# Upload the file to Fabric
# Note: I manually pull out the 'submit' file in Crashlytics.framework(3.6.0). You might need to check the updated framework
./travis/submit $FABRIC_API_KEY $FABRIC_BUILD_SECRET \
-ipaPath $IPA_PATH -emails $EMAILS \
-notesPath $RELEASE_NOTES_PATH \
-groupAliases $GROUP_ALIASES \
-notifications YES
@alonecuzzo
Copy link

Hey I was reading through this. The submit link is broken. I went through your revision history and got the dropbox url https://www.dropbox.com/s/3aa8pj4bhknwjg3/submit?dl=0 but that's not working.

Please advise.

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