Skip to content

Instantly share code, notes, and snippets.

@xslim
Created June 9, 2011 13:44
Show Gist options
  • Save xslim/1016752 to your computer and use it in GitHub Desktop.
Save xslim/1016752 to your computer and use it in GitHub Desktop.
Xcode Continuous integration build script
#!/bin/bash
SDK='iphoneos'
CONFIGURATION='Release'
IDENTITY="iPhone Developer"
GIT_BINARY='git'
REMOTE_HOST='http://hal.ciklum.net'
#http://github.com/baz/ios-build-scripts/raw/master/generate_manifest.py
MANIFEST_SCRIPT='/usr/local/bin/generate_manifest.py'
WEB_DIR="/Users/$USER/web"
WEB_BUILD_DIR='ios'
PROVISION_PATH="/Users/$USER/Library/MobileDevice/Provisioning Profiles"
MOBILEPROVISION_APP="/usr/local/bin/mobileprovisionParser";
KEYCHAIN_LOCATION="/Users/$USER/Library/Keychains/iccoss.keychain"
KEYCHAIN_PASSWORD='1cc0ss'
PROJECT_DIR=`dirname "$0"`
cd "$PROJECT_DIR"
PROJECT_DIR="$(pwd)"
XCODE_PROJECT_NAME="`basename -s .xcodeproj "${PROJECT_DIR}"`"
PROVISIONING_PROFILE="$PROJECT_DIR/provision.mobileprovision"
# Install the mobileprovision certificate
if [ -f "${PROVISIONING_PROFILE}" ]; then
UUID=`$MOBILEPROVISION_APP -f "$PROVISIONING_PROFILE" -o uuid`;
cp -Rfp "${PROVISIONING_PROFILE}" "${PROVISION_PATH}/$UUID.mobileprovision" || exit 1000;
fi
if [ -f "$KEYCHAIN_LOCATION" ]; then
security list-keychains -s "$KEYCHAIN_LOCATION"
security -v unlock-keychain -p $KEYCHAIN_PASSWORD "$KEYCHAIN_LOCATION"
security -v default-keychain -s "$KEYCHAIN_LOCATION"
fi
# Get VERSION_SHORT from pom.xml
VERSION_SHORT=`xpath pom.xml "project/version/text()" 2>/dev/null`
# For Hudson
if [ -n "${BUILD_NUMBER}" ]; then
VERSION_BUILD="${BUILD_NUMBER}"
if [ -n "${SVN_REVISION}" ]; then
VERSION_BUILD="${VERSION_BUILD}-${SVN_REVISION}"
fi
# For Git
elif [ -d ".git" ]; then
VERSION_BUILD="$($GIT_BINARY log --pretty=format:'' | wc -l)-$($GIT_BINARY rev-parse --short HEAD)"
VERSION_BUILD=${VERSION_BUILD//[[:space:]]}
else
VERSION_BUILD=1
fi
#CFBundleVersion
agvtool new-version -all "${VERSION_BUILD}"
#CFBundleShortVersionString
if [ -n "${VERSION_SHORT}" ]; then
agvtool new-marketing-version "${VERSION_SHORT}"
else
buildPlist="${XCODE_PROJECT_NAME}-Info.plist"
VERSION_SHORT=$(/usr/libexec/PlistBuddy -c "Print CFBuildNumber" $buildPlist)
fi
VERSION_FULL="${VERSION_SHORT}-${VERSION_BUILD}"
# Set options from Hudson
propertiesPlist="Properties.plist"
if [ -n "${iccoss_datahub_server}" ]; then
/usr/libexec/PlistBuddy -c "Set :DatahubServer ${iccoss_datahub_server}" $propertiesPlist
/usr/libexec/PlistBuddy -c "Set :ContentproxyServer ${iccoss_contentproxy_server}" $propertiesPlist
/usr/libexec/PlistBuddy -c "Set :WebgatewayServer ${iccoss_webgateway_server}" $propertiesPlist
fi
# Build project
xcodebuild -sdk "$SDK" -configuration "$CONFIGURATION" clean
xcodebuild -sdk "$SDK" -configuration "$CONFIGURATION" CODE_SIGN_IDENTITY="$IDENTITY" RUN_CLANG_STATIC_ANALYZER=NO GCC_TREAT_WARNINGS_AS_ERRORS=YES || exit 1000;
BUILD_DIRECTORY="$(pwd)/build/${CONFIGURATION}-iphoneos"
cd "$BUILD_DIRECTORY" || die "Build directory does not exist."
#MANIFEST_SCRIPT=$(curl -fsS $MANIFEST_SCRIPT_LOCATION)
MANIFEST_OUTPUT_HTML_FILENAME='index.html'
MANIFEST_OUTPUT_MANIFEST_FILENAME='manifest.plist'
for APP_FILENAME in *.app; do
APP_NAME=$(echo "$APP_FILENAME" | sed -e 's/.app//')
IPA_FILENAME="${APP_NAME}-${VERSION_FULL}.ipa"
DSYM_FILEPATH="$APP_FILENAME.dSYM"
/usr/bin/xcrun -sdk iphoneos PackageApplication -v "$APP_FILENAME" -o "$BUILD_DIRECTORY/$IPA_FILENAME" --sign "${IDENTITY}" --embed "$PROVISIONING_PROFILE" || exit 1000;
if [ "$HUDSON_URL" ]; then
ROOT_DEPLOYMENT_ADDRESS="${HUDSON_URL}""job/$JOB_NAME/$BUILD_NUMBER/artifact/$APP_NAME/release"
else
ROOT_DEPLOYMENT_ADDRESS="${REMOTE_HOST}/ci/$WEB_BUILD_DIR/$APP_NAME/$VERSION_FULL"
fi
echo "Will deploy to: $ROOT_DEPLOYMENT_ADDRESS"
# Output of this is index.html and manifest.plist
"$MANIFEST_SCRIPT" -f "$APP_FILENAME" -o "$IPA_FILENAME" -d "$ROOT_DEPLOYMENT_ADDRESS/$MANIFEST_OUTPUT_MANIFEST_FILENAME" -c "$ROOT_DEPLOYMENT_ADDRESS"
# Zip dSYM directory
DSYM_ARCHIVE_FILENAME="${APP_NAME}_dsym-${VERSION_FULL}.zip"
zip -r "$DSYM_ARCHIVE_FILENAME" "$DSYM_FILEPATH"
#QUOTE='"'
#ssh $REMOTE_HOST "cd $REMOTE_PARENT_PATH; rm -rf ${QUOTE}$APP_NAME${QUOTE}/$GIT_HASH; mkdir -p ${QUOTE}$APP_NAME${QUOTE}/$GIT_HASH;"
#scp "$PAYLOAD_FILENAME" "$REMOTE_HOST:$REMOTE_PARENT_PATH/${QUOTE}$APP_NAME${QUOTE}/$GIT_HASH"
#ssh $REMOTE_HOST "cd $REMOTE_PARENT_PATH/${QUOTE}$APP_NAME${QUOTE}/$GIT_HASH; tar -xf $PAYLOAD_FILENAME; rm $PAYLOAD_FILENAME"
# Copy to web server
if [ -d "$WEB_DIR" ]; then
APP_DEPLOY_DIR="$WEB_DIR/$WEB_BUILD_DIR/$APP_NAME/$VERSION_FULL"
rm -rf "$APP_DEPLOY_DIR"
mkdir -p "$APP_DEPLOY_DIR"
cp "$IPA_FILENAME" "$DSYM_ARCHIVE_FILENAME" "$MANIFEST_OUTPUT_HTML_FILENAME" "$MANIFEST_OUTPUT_MANIFEST_FILENAME" "$APP_DEPLOY_DIR"
# Clean up
rm "$IPA_FILENAME"
rm "$MANIFEST_OUTPUT_HTML_FILENAME"
rm "$MANIFEST_OUTPUT_MANIFEST_FILENAME"
rm "$DSYM_ARCHIVE_FILENAME"
else
APP_DEPLOY_DIR="$PROJECT_DIR/release"
rm -rf "$APP_DEPLOY_DIR"
mkdir -p "$APP_DEPLOY_DIR"
mv "$IPA_FILENAME" "$DSYM_ARCHIVE_FILENAME" "$MANIFEST_OUTPUT_HTML_FILENAME" "$MANIFEST_OUTPUT_MANIFEST_FILENAME" "$APP_DEPLOY_DIR"
fi
done
exit 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment