Skip to content

Instantly share code, notes, and snippets.

@mamaz
Last active December 7, 2023 07:53
Show Gist options
  • Save mamaz/f68df8bb08bd7e865069 to your computer and use it in GitHub Desktop.
Save mamaz/f68df8bb08bd7e865069 to your computer and use it in GitHub Desktop.
iOS build script for building and uploading to Fabric
#!/bin/sh
#
# Simple script for uploading binaries to Fabric (d/h Crashlytics)
#
# written by @taufik_obet
# modified for pushing to fabric by @hismamaz
#
#
# How to use:
# 1. Make sure you insert your certs on ./Scripts/certs/,
# apple.cert->Apple Worldwide Developer Relations Certificate Authority
# distr.cer->Your distribution Certificate
# distr.p12->Your distribution private key
# use Password01 for your private key password
# 2. Place your prov profiles in ./Scripts/profile/
# 3. Update your command line tools.
# 4. Install xctool.
# 5. Install Crashlytics.framework on your root project dir.
# 6. Specify $(SDKROOT)/ResourceRules.plist as Code Signing Resource Rules Path.
# 7. Create Internal group in fabric dashboard.
# 8. Run this on your root project dir.
# 9. Profit
ROOT_DIR_CONTAINS_XCWORKSPACE=$(find . -name *.xcwork*)
if [[ $ROOT_DIR_CONTAINS_XCWORKSPACE = "" ]]; then
echo "You should run this on your root directory"
exit 0
fi
XCODE_PROJECT_NAME="Shulupust"
XCODE_PROJECT_SCHEME="Shulupust-Staging"
XCODE_PROJECT_CONFIGURATION="Debug"
APPNAME="Shulupust Staging"
SCHEME="Shulupust-Staging"
PLIST_NAME="Shulupust-Info"
PLIST_PATH="${PWD}/${XCODE_PROJECT_NAME}/Resources/Other-Sources/${PLIST_NAME}.plist"
DEVELOPER_NAME="iPhone Distribution: Mamazo Pallazo (xxxxxxxxxx)"
KEYCHAIN_NAME=$(uuidgen)
KEYCHAIN_PATH="$HOME/Library/Keychains/$KEYCHAIN_NAME.keychain"
PROFILE_NAME="prov_profile_name"
OUTPUTDIR="$PWD/build/$XCODE_PROJECT_CONFIGURATION-iphoneos"
API_KEY="crashlytics API KEY"
BUILD_SECRET="crashlytics BUILD SECRET"
echo "********************"
echo "* Keychain *"
echo "********************"
security create-keychain -p jenkins $KEYCHAIN_PATH
security import ./Scripts/certs/apple.cer -k $KEYCHAIN_PATH -T /usr/bin/codesign
security import ./Scripts/certs/distr.cer -k $KEYCHAIN_PATH -T /usr/bin/codesign
security import ./Scripts/certs/distr.p12 -k $KEYCHAIN_PATH -P Password01 -T /usr/bin/codesign
security list-keychain -s $KEYCHAIN_PATH
security unlock-keychain -p jenkins $KEYCHAIN_PATH
security set-keychain-settings -t 3600 -l $KEYCHAIN_PATH
cp "./Scripts/profile/$PROFILE_NAME.mobileprovision" $HOME/Library/MobileDevice/Provisioning\ Profiles/
echo "********************"
echo "* Building *"
echo "********************"
CUSTOM_BUILD_NUMBER=`/bin/date +%Y%m%d%H%M`
HEX_NUMBER=`echo "obase=16;ibase=10; $CUSTOM_BUILD_NUMBER" | bc`
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $HEX_NUMBER" "$PLIST_PATH"
xctool -workspace ${XCODE_PROJECT_NAME}.xcworkspace \
-scheme ${XCODE_PROJECT_SCHEME} \
-configuration ${XCODE_PROJECT_CONFIGURATION} \
PROVISIONING_PROFILE="$PROFILE_NAME" \
OTHER_CODE_SIGN_FLAGS="--keychain $KEYCHAIN_PATH" \
OBJROOT=$PWD/build \
SYMROOT=$PWD/build
echo "********************"
echo "* Signing *"
echo "********************"
xcrun -log -sdk iphoneos PackageApplication "$OUTPUTDIR/$APPNAME.app" -o "$OUTPUTDIR/$APPNAME.ipa" \
-sign "$DEVELOPER_NAME" \
-embed "$PROVISIONING_PROFILE"
zip -r -9 "$OUTPUTDIR/$APPNAME.app.dSYM.zip" "$OUTPUTDIR/$APPNAME.app.dSYM"
echo "********************"
echo "* Sending *"
echo "********************"
RELEASE_DATE=`date '+%Y-%m-%d %H:%M:%S'`
COMMIT_HASH=$(git rev-parse HEAD)
COMMENTS=$(curl "${BUILD_URL}api/xml?wrapper=changes&xpath=//changeSet//comment" | sed -e 's/<[^>]*>//g' | sed '/^$/d' | sed 's/^/- /')
RELEASE_NOTES="Build: $HEX_NUMBER\nUploaded: $RELEASE_DATE\nCommit Hash: $COMMIT_HASH\n\n$COMMENTS"
NOTES_PATH="./notes.txt"
echo "$RELEASE_NOTES" > $NOTES_PATH
IPA_FILE=$(find $OUTPUTDIR -name *.ipa)
if [[ $IPA_FILE = "" ]]; then
echo "Error, no ipa produced"
exit 1
fi
# Also invite group (configured from fabric.io dahsboard), for list of testers, and auto notify testers
./Crashlytics.framework/submit API_KEY BUILD_SECRET -ipaPath "$OUTPUTDIR/$APPNAME.ipa" -groupAliases Internal -notifications YES -notesPath "$NOTES_PATH"
echo "********************"
echo "* Cleanup *"
echo "********************"
security delete-keychain $KEYCHAIN_NAME.keychain
rm -f "$HOME/Library/MobileDevice/Provisioning Profiles/$PROFILE_NAME.mobileprovision"
rm $NOTES_PATH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment