Simple script for creating a zip and DMG, uploading to S3, and posting a new build to an Appcaster instance.
#!/bin/sh | |
# UploadBuild.sh | |
# Aether | |
# | |
# Created by Andrew Madsen on 11/7/15. | |
# Copyright © 2015 Open Reel Software. All rights reserved. | |
S3BucketName=<redacted> | |
username="<redacted>" | |
key="<redacted>" | |
baseURL="http://$username:$key@buildserver.yourwebsite.com" | |
buildsURLSlug="yourappname" | |
# confirm we are building a release style build | |
if [ $CONFIGURATION != 'Release' ]; then | |
echo "Upload Build target should only be built with Release configuration. This build will not be uploaded." | |
exit | |
fi | |
cd "${PROJECT_DIR}" | |
# Get version numbers | |
shortVersionString=$(/usr/libexec/PlistBuddy -c Print:CFBundleShortVersionString ${PROJECT_DIR}/${INFOPLIST_FILE}) | |
buildNumber=$(agvtool vers -terse) | |
# Create a DMG | |
cd "${PROJECT_DIR}"/"Disk Images" | |
masterDMGZip="${PRODUCT_NAME} Master.dmg.zip" | |
masterDMG="${PRODUCT_NAME} Master.dmg" | |
outputDMGFileName="${PRODUCT_NAME}_$shortVersionString($buildNumber).dmg" | |
echo "Creating DMG $outputDMGFileName" | |
unzip "$masterDMGZip" | |
success=$? | |
if [ $success -ne 0 ] | |
then | |
echo "Failed to unzip master disk image." | |
exit $success | |
fi | |
hdiutil attach "$masterDMG" -mountpoint "${PRODUCT_NAME}" | |
success=$? | |
if [ $success -ne 0 ] | |
then | |
echo "Failed to mount master disk image" | |
rm "$masterDMG" | |
exit $success | |
fi | |
rm -r "${PRODUCT_NAME}"/"${PRODUCT_NAME}".app | |
cp -R "${TARGET_BUILD_DIR}/${PRODUCT_NAME}.app" "${PRODUCT_NAME}"/ | |
hdiutil detach "${PRODUCT_NAME}" | |
hdiutil convert "$masterDMG" -format UDZO -imagekey zlib-level=9 -ov -o "${TARGET_BUILD_DIR}"/"$outputDMGFileName" | |
success=$? | |
if [ $success -ne 0 ] | |
then | |
echo "Failed to convert and compress DMG" | |
rm "$masterDMG" | |
exit $success | |
fi | |
rm "$masterDMG" | |
echo "Finished DMG $outputDMGFileName" | |
# Create zip files | |
cd "${TARGET_BUILD_DIR}" | |
zipFileName="${PRODUCT_NAME}_$shortVersionString($buildNumber).zip" | |
dsymZipFileName="${PRODUCT_NAME}_$shortVersionString($buildNumber) dSYM.zip" | |
echo "Creating zip file $zipFileName" | |
zip -q -y -r "$zipFileName" "${PRODUCT_NAME}.app" | |
echo "Creating zip file $dsymZipFileName" | |
zip -q -y -r "$dsymZipFileName" *.dSYM | |
fileSize=$(stat -f %z $zipFileName) | |
# Generate signature | |
dsaSignature=$(openssl dgst -sha1 -binary < "$zipFileName" | openssl dgst -dss1 -sign "${PROJECT_DIR}/Scripts/dsa_priv.pem" | openssl enc -base64) | |
# Allow suppressing the confirmation alert e.g. when building on the command-line | |
# Add SUPPRESS_UPLOAD_CONFIRMATION=1 to xcodebuild's arguments to supress | |
if [ -z "$SUPPRESS_UPLOAD_CONFIRMATION" ]; then | |
confirmationScript=$(cat <<EOF | |
on run | |
tell application "SystemUIServer" | |
activate | |
display dialog "Are you sure you want to upload to the Open Reel Software build hub?" buttons {"Don't Upload", "Upload"} default button 2 with icon caution giving up after 15 | |
set dialogResult to the result | |
set theButton to button returned of dialogResult | |
if (gave up of dialogResult) then | |
set theButton to "Don't Upload" | |
end if | |
end tell | |
tell application "Xcode" to activate | |
return theButton | |
end run | |
EOF | |
) | |
# ask user to confirm upload | |
confirmation=$(echo "$confirmationScript" | osascript) | |
if [ "$confirmation" != "Upload" ] | |
then | |
echo "Not uploading to build hub" | |
exit 0 | |
fi | |
fi #SUPPRESS_UPLOAD_CONFIRMATION | |
# Upload to S3 | |
echo "Uploading $outputDMGFileName to S3." | |
aws s3 cp "$outputDMGFileName" "s3://$S3BucketName/" --acl public-read | |
success=$? | |
if [ $success -ne 0 ] | |
then | |
echo "Failed to upload to Amazon S3" | |
exit $success | |
fi | |
echo "Uploading $zipFileName to S3." | |
aws s3 cp "$zipFileName" "s3://$S3BucketName/" --acl public-read | |
success=$? | |
if [ $success -ne 0 ] | |
then | |
echo "Failed to upload to Amazon S3" | |
exit $success | |
fi | |
aws s3 cp "$dsymZipFileName" "s3://$S3BucketName/" --acl private | |
success=$? | |
if [ $success -ne 0 ] | |
then | |
echo "Failed to upload to Amazon S3" | |
exit $success | |
fi | |
s3URL="https://s3.amazonaws.com/$S3BucketName/$zipFileName" | |
# Add build to build hub | |
buildJson=$(cat <<SETVAR | |
{ | |
"title": "${PRODUCT_NAME} $shortVersionString ($buildNumber)", | |
"filename": "$zipFileName", | |
"identifier": "$buildNumber", | |
"version": "$buildNumber", | |
"version_string": "$shortVersionString ($buildNumber)", | |
"minimum_system_version": "${MACOSX_DEPLOYMENT_TARGET}", | |
"length": "$fileSize", | |
"download_url": "$s3URL", | |
"signature": "$dsaSignature", | |
"channels": ["developer"] | |
} | |
SETVAR) | |
uploadURL="$baseURL/apps/$buildsURLSlug/builds" | |
echo "Uploading $zipFileName to $uploadURL. ($buildJson)" | |
curl -H "Content-Type: application/json" -X POST -d "$buildJson" $uploadURL | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment