Skip to content

Instantly share code, notes, and snippets.

@sergiocampama
Last active January 12, 2024 23:21
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sergiocampama/5f7132d3bc2ddf67811c601519e38326 to your computer and use it in GitHub Desktop.
Save sergiocampama/5f7132d3bc2ddf67811c601519e38326 to your computer and use it in GitHub Desktop.
#!/bin/bash -eu
if [[ $# -ne 2 ]]; then
echo "usage: mac-release semversion channel"
exit 1
fi
TOOLS_DIR="$(dirname $(realpath $0))"
PROJECT_DIR="$(dirname $TOOLS_DIR)"
VERSION="$1"
CHANNEL="$2"
OLD_BUILD_NUMBER=$(<<API CALL WITH CURL>>)
BUILD_NUMBER="$(( $OLD_BUILD_NUMBER + 1 ))"
DMG_NAME="<<DMG_NAME>>"
ARCHIVE_NAME="<<ARCHIVE_NAME>>"
APP_NAME="<<APP_NAME>>"
SCHEME="<<SCHEME>>"
VOLUME_NAME="<<VOLUME NAME>>"
BUNDLE_ID="<<BUNDLE_ID>>"
OUTPUT_PATH=$(mktemp -d -t "${ARCHIVE_NAME}-${VERSION}-${BUILD_NUMBER}")
echo "Updating dependencies"
pod install --deployment || pod install --repo-update --deployment
echo "Starting build with directory ${OUTPUT_PATH}"
set -o pipefail && \
xcodebuild archive \
-workspace <<WORKSPACE>> \
-scheme "${SCHEME}" \
-destination "generic/platform=macOS,variant=Mac Catalyst" \
-derivedDataPath "${OUTPUT_PATH}" \
-archivePath "${OUTPUT_PATH}/${ARCHIVE_NAME}.xcarchive" \
"CURRENT_PROJECT_VERSION=${BUILD_NUMBER}" \
"MARKETING_VERSION=${VERSION}" \
| xcbeautify
if [[ -e "/Volumes/${DMG_NAME}" ]]; then
hdiutil detach "/Volumes/${DMG_NAME}"
fi
hdiutil \
create \
-srcfolder "${OUTPUT_PATH}/${ARCHIVE_NAME}.xcarchive/Products/Applications" \
-volname "${VOLUME_NAME}" \
-fs HFS+ \
-fsargs "-c c=64,a=16,e=16" \
-format UDRW \
-size 500000k \
"${OUTPUT_PATH}/${DMG_NAME}-inprogress.dmg"
DEVICE=$(
hdiutil attach -readwrite -noverify -noautoopen "${OUTPUT_PATH}/${DMG_NAME}-inprogress.dmg" | \
egrep '^/dev/' | \
sed 1q | \
awk '{print $1}'
)
mkdir "/Volumes/${DMG_NAME}/.background"
cp "Tools/Resources/dmgBackground.png" "/Volumes/${DMG_NAME}/.background/background.png"
echo '
tell application "Finder"
tell disk "'${DMG_NAME}'"
open
set current view of container window to icon view
set toolbar visible of container window to false
set statusbar visible of container window to false
set the bounds of container window to {400, 100, 1000, 524}
set theViewOptions to the icon view options of container window
set arrangement of theViewOptions to not arranged
set icon size of theViewOptions to 100
set background picture of theViewOptions to file ".background:background.png"
make new alias file at container window to POSIX file "/Applications" with properties {name:"Applications"}
set position of item "'${APP_NAME}'" of container window to {160, 200}
set position of item "Applications" of container window to {440, 200}
update without registering applications
delay 5
close
end tell
end tell
' | osascript
chmod -Rf go-w "/Volumes/${DMG_NAME}"
sync
sync
sleep 5
hdiutil detach "/Volumes/${DMG_NAME}"
sleep 5
hdiutil convert \
"${OUTPUT_PATH}/${DMG_NAME}-inprogress.dmg" \
-format UDZO \
-imagekey zlib-level=9 \
-o "${OUTPUT_PATH}/${DMG_NAME}-${VERSION}-${BUILD_NUMBER}.dmg"
rm -rf "${OUTPUT_PATH}/${DMG_NAME}-inprogress.dmg"
codesign -s "Developer ID" "${OUTPUT_PATH}/${DMG_NAME}-${VERSION}-${BUILD_NUMBER}.dmg"
# Install missing dependencies if any.
cd "${PROJECT_DIR}/fastlane"; asdf exec bundle install
cd "${PROJECT_DIR}/fastlane"; asdf exec bundle exec fastlane run \
notarize \
api_key_path:"${FASTLANE_AUTH_JSON}" \
package:"${OUTPUT_PATH}/${DMG_NAME}-${VERSION}-${BUILD_NUMBER}.dmg" \
verbose:true \
print_log:true \
bundle_id:"${BUNDLE_ID}"
# Force return to the project directory.
cd "${PROJECT_DIR}"
# Just in case
if [[ -e "/Volumes/${DMG_NAME}" ]]; then
hdiutil detach "/Volumes/${DMG_NAME}"
fi
SHA_ARRAY=($(shasum -a 256 "${OUTPUT_PATH}/${DMG_NAME}-${VERSION}-${BUILD_NUMBER}.dmg"))
FULL_SHA_256=$(echo "${SHA_ARRAY[0]}")
SHA_256=$(echo "${FULL_SHA_256}" | head -c8)
set +x
STORAGE_AUTH_TOKEN=$(<<API CALL WITH CURL FOR CLOUD STORAGE TOKEN>>)
UPLOAD_URL="https://storage.googleapis.com/<<BUCKET NAME>>/images/${DMG_NAME}-${VERSION}-${BUILD_NUMBER}-${SHA_256}.dmg"
curl "${UPLOAD_URL}" \
-s \
-X PUT \
-H "Authorization: Bearer ${STORAGE_AUTH_TOKEN}" \
-H "Content-Type: application/x-diskcopy" \
--upload-file "${OUTPUT_PATH}/${DMG_NAME}-${VERSION}-${BUILD_NUMBER}.dmg"
<<API CALL TO CREATE RELEASE ENTRY ON INTERNAL SYSTEM>>
pushd "${OUTPUT_PATH}/${ARCHIVE_NAME}.xcarchive/dSYMs"
zip -r "${OUTPUT_PATH}/appDsyms.zip" *.dSYM
popd
"${TOOLS_DIR}/upload-dsyms" "${OUTPUT_PATH}/appDsyms.zip"
GIT_TAG="<<TAG NAME FOR RELEASE>>"
if [ $(git tag -l "$GIT_TAG") ]; then
echo "Git tag exists"
else
git tag "${GIT_TAG}"
git push origin "${GIT_TAG}"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment