Skip to content

Instantly share code, notes, and snippets.

@adamkaplan
Last active January 4, 2016 04:29
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 adamkaplan/8568901 to your computer and use it in GitHub Desktop.
Save adamkaplan/8568901 to your computer and use it in GitHub Desktop.
See installation instructions in the comment below
# Copyright 2014 Gilt Groupe, Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -e
set -u
LOG="${USER_LIBRARY_DIR}/Logs/${PRODUCT_NAME}-publish.log"
exec >> $LOG 2>&1
log() {
DATE=$(/bin/date +"[%Y-%m-%d %H:%m:%S]")
echo "$DATE $1"
}
alert() {
/usr/bin/osascript -e "display notification \"$3\" with title \"$1\" subtitle \"$2\""
}
gitlog() {
/usr/bin/env git --git-dir="$1" log -n1 --pretty=format:"$2"
}
log "----- Publishing beta release -----"
APP_TOKEN= [ HOCKEY APP TOKEN ]
APP_ID= [HOCKEY APP ID HERE]
APP_GIT_DIR="${PROJECT_DIR}/.git"
## Find the most recent xcarchive in today's folder
DATE=$( /bin/date +"%Y-%m-%d" )
# Archives are placed in a folder with today's date
ARCHIVE_NAME=$( /bin/ls -t "${USER_LIBRARY_DIR}/Developer/Xcode/Archives/${DATE}" | /usr/bin/grep xcarchive | /usr/bin/sed -n 1p )
ARCHIVE_PATH="${USER_LIBRARY_DIR}/Developer/Xcode/Archives/${DATE}/${ARCHIVE_NAME}"
APP="${ARCHIVE_PATH}/Products/Applications/${PRODUCT_NAME}.app"
DSYM_NAME="${PRODUCT_NAME}.app.dSYM"
DSYM_PATH="${ARCHIVE_PATH}/dSYMs/${PRODUCT_NAME}.app.dSYM"
log "Publishing archive at $ARCHIVE_PATH"
# Set the build number in Info.plist & dSYM to a unique reproducible value based on Git hashes
BUILD_NUMBER=$( /bin/date "+%Y.%m%d.%H%M%S" )
/usr/bin/defaults write "${APP}/Info" CFBundleVersion "$BUILD_NUMBER" 2>&1 | /usr/bin/tee $LOG
/usr/bin/defaults write "${DSYM_PATH}/Contents/Info" CFBundleVersion "$BUILD_NUMBER" 2>&1 | /usr/bin/tee $LOG
# iOS apps must be in an ipa
TMP_IPA_PATH="/tmp/${PRODUCT_NAME}.ipa"
SDK=$( echo "$EFFECTIVE_PLATFORM_NAME" | /usr/bin/sed 's/^-//' )
log "Will package for $SDK sdk into $TMP_IPA_PATH"
alert "Publish Beta App" "Packaging IPA" $PRODUCT_NAME
/usr/bin/xcrun -v -sdk $SDK PackageApplication "$APP" -o "$TMP_IPA_PATH" -s "$CODE_SIGN_IDENTITY" 2>&1 | /usr/bin/tee $LOG
# dSYM must be zipped
TMP_DSYM_PATH="/tmp/${DSYM_NAME}.dSYM.zip"
log "Compressing dSYM to $TMP_DSYM_PATH"
alert "Publish Beta App" "Compressing dSYM" $PRODUCT_NAME
/usr/bin/zip -r9 "$TMP_DSYM_PATH" "$DSYM_PATH" 2>&1 | /usr/bin/tee $LOG
# Compile release notes consisting of the various commits used for this release
APP_COMMIT_HASH=$( gitlog $APP_GIT_DIR "%H" )
APP_COMMIT_AUTHOR=$( gitlog $APP_GIT_DIR "%aN" )
APP_COMMIT_DATE=$( gitlog $APP_GIT_DIR "%aD" )
RELEASE_NOTES="
## Beta Release Notes
### General Information
* **Releaser:** ${USER}
### Source Versions
* **Commit:** *${APP_COMMIT_HASH}*
* **Author:** *${APP_COMMIT_AUTHOR}*
* **Date:** *${APP_COMMIT_DATE}*
# Publish to Hockey
# Note: status=2 will not actually do anything with the upload-only token
log "Publishing to Hockey..."
alert "Publish Beta App" "Uploading to Hockey" $PRODUCT_NAME
RESPONSE=$( curl \
-F "notes=${RELEASE_NOTES}" \
-F "notes_type=1" \
-F "status=2" \
-F "commit_sha=${APP_COMMIT_HASH}" \
-F "ipa=@${TMP_IPA_PATH}" \
-F "dsym=@${TMP_DSYM_PATH}" \
-H "X-HockeyAppToken: ${APP_TOKEN}" \
"https://rink.hockeyapp.net/api/2/apps/${APP_ID}/app_versions/upload" )
log "Hockey API response: $RESPONSE"
alert "Publish Beta App" "Beta Published!" $PRODUCT_NAME
# Clean up
log "Cleaning up temporary files..."
/bin/rm "$TMP_DSYM_PATH" 2>&1 | /usr/bin/tee $LOG
/bin/rm "$TMP_IPA_PATH" 2>&1 | /usr/bin/tee $LOG
URL=$(echo "$RESPONSE" | /usr/bin/tr '\n' ' ' | python -c 'import sys, json; print json.load(sys.stdin)["config_url"]')
/usr/bin/open "$URL"
log "publish complete!"
@adamkaplan
Copy link
Author

HockeyApp publish script for Xcode.

Xcode 5 Installation Instructions

  • Open the Edit Scheme dialog press Command + <
  • Expand the Archive task
  • Click on Post-actions
  • Paste the contents of this Gist into the script editor

Optional

  • Select the Archive step under the Archive task
  • Uncheck Reveal Archive In Organizer

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