From 8fcb99fdbc25f27ab079c1408a5a960e99adc71b Mon Sep 17 00:00:00 2001 From: turtledreams Date: Fri, 12 Jan 2024 21:25:35 +0900 Subject: [PATCH] script --- CHANGELOG.md | 4 + countly_dsym_uploader.sh | 153 +++++++++++++++++++++++++++------------ 2 files changed, 109 insertions(+), 48 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ff45c57..389757ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 23.12.1 +* dSYM uploading script now can upload multiple dSYM files if their location is provided +* Added support for Xcode 15 DWARF file environment variable changes while using dSYM upload script + ## 23.12.0 * Added `disableLocation` initial config property to disable location tracking * Added `addSegmentationToViewWithID:` in view interface for adding segmentation to an ongoing view diff --git a/countly_dsym_uploader.sh b/countly_dsym_uploader.sh index 0423d59a..04a32797 100755 --- a/countly_dsym_uploader.sh +++ b/countly_dsym_uploader.sh @@ -21,12 +21,16 @@ # Notes: # Do not forget to replace YOUR_COUNTLY_SERVER and YOUR_APP_KEY with real values. # If your project setup and/or CI/CD flow requires a custom path for the generated dSYMs, you can specify it as third argument. +# Third argument is optional. If you do not provide it, the script will try to use Xcode Environment Variables to find the dSYM. +# If you provide it, the script will use the provided path to find the dSYM. +# The path should be absolute and point to the .dSYM file or the folder containing the .dSYM files. # Common functions countly_log () { echo "[Countly] $1"; } countly_fail () { countly_log "$1"; exit 0; } +countly_pass () { countly_log "$1"; DSYM_FILE_NAME=$INITIAL_DSYM_FILE_NAME; DSYM_FOLDER_PATH=$INITIAL_FOLDER_PATH; continue; } countly_usage () { @@ -60,70 +64,123 @@ if [[ -z $CUSTOM_DSYM_PATH ]]; then fi DSYM_FOLDER_PATH=${DWARF_DSYM_FOLDER_PATH} + countly_log "dSYM folder path:[$DSYM_FOLDER_PATH]" DSYM_FILE_NAME=${DWARF_DSYM_FILE_NAME} + countly_log "dSYM file name:[$DSYM_FILE_NAME]" else DSYM_FOLDER_PATH=$(dirname "${CUSTOM_DSYM_PATH}") + countly_log "dSYM folder path:[$DSYM_FOLDER_PATH]" DSYM_FILE_NAME=$(basename "${CUSTOM_DSYM_PATH}") + countly_log "dSYM file name:[$DSYM_FILE_NAME]" fi +INITIAL_DSYM_FILE_NAME=$DSYM_FILE_NAME +INITIAL_FOLDER_PATH=$DSYM_FOLDER_PATH +DSYM_PATH="${DSYM_FOLDER_PATH}/${DSYM_FILE_NAME}" + +for file in "$DSYM_PATH"/*; do +printf "======\n[Countly] Processing $file \n" + + if [[ ! $INITIAL_DSYM_FILE_NAME == *.dSYM ]]; then + countly_log "Provided file is not a ,dSYM file!" + if [[ ! $INITIAL_DSYM_FILE_NAME == *.app ]]; then + countly_log "Provided file is not an .app file!" + if [[ $file == *.dSYM ]]; then + countly_log "Using files inside the folder!" + DSYM_FILE_NAME=$(basename "${file}") + DSYM_PATH="${CUSTOM_DSYM_PATH}/${DSYM_FILE_NAME}" + else + countly_pass "File inside the folder is not a dSYM file!" + fi + else + countly_log "Provided file is an app file!" + FILE_LENGTH=${#INITIAL_DSYM_FILE_NAME} + DSYM_INNER_FILE_NAME=${INITIAL_DSYM_FILE_NAME:0:FILE_LENGTH-4} + DSYM_PATH="${DSYM_FOLDER_PATH}/${INITIAL_DSYM_FILE_NAME}/${DSYM_INNER_FILE_NAME}" + fi + fi -DSYM_PATH="${DSYM_FOLDER_PATH}/${DSYM_FILE_NAME}"; -if [[ ! -d $DSYM_PATH ]]; then - countly_fail "dSYM path ${DSYM_PATH} does not exist!" -fi - -countly_log "Current dSYM path:[$DSYM_PATH]" - -# Extracting Build UUIDs from DSYM using dwarfdump -XCRUN_RES=$(xcrun dwarfdump --uuid "${DSYM_PATH}") -countly_log "Xcrun result:[$XCRUN_RES]" -RAW_UUID=$(echo "${XCRUN_RES}" | awk '{print $2}') -countly_log "Raw UUID:[$RAW_UUID]" -# Remove whitespace and such -BUILD_UUIDS=$(echo "${RAW_UUID}" | xargs | sed 's/ /,/g') -if [ $? -eq 0 ]; then - countly_log "Extracted Build UUIDs:[${BUILD_UUIDS}]" -else - countly_fail "Extracting Build UUIDs failed!" -fi + countly_log "Current dSYM path:[$DSYM_PATH]" + + # Extracting Build UUIDs from DSYM using dwarfdump + XCRUN_RES=$(xcrun dwarfdump --uuid "${DSYM_PATH}") + countly_log "Xcrun result:[$XCRUN_RES]" + RAW_UUID=$(echo "${XCRUN_RES}" | awk '{print $2}') + countly_log "Raw UUID:[$RAW_UUID]" + # Remove whitespace and such + BUILD_UUIDS=$(echo "${RAW_UUID}" | xargs | sed 's/ /,/g') + if [ $? -eq 0 ]; then + countly_log "Extracted Build UUIDs:[${BUILD_UUIDS}]" + # if UUIDs are empty and custom path is not provided it means that we are using new Xcode + # this means instead of a .app.dSYM we have a .app which has a symbol file inside without .dSYM extension + # TODO: create a function instead of repeating the code + if [ ! "$BUILD_UUIDS" ] && [ -z $CUSTOM_DSYM_PATH ];then + countly_log "Will try to extract UUIDs with .app extension for new Xcode" + FILE_LENGTH=${#DSYM_FILE_NAME} + APP_NAME=${DSYM_FILE_NAME:0:FILE_LENGTH-5} + countly_log "App name:[$APP_NAME]" + # removing .app from the end + DSYM_FILE_NAME=${DSYM_FILE_NAME:0:FILE_LENGTH-9} + DSYM_PATH="${DSYM_FOLDER_PATH}/${APP_NAME}/${DSYM_FILE_NAME}" + countly_log "New dSYM path:[$DSYM_PATH]" + XCRUN_RES=$(xcrun dwarfdump --uuid "${DSYM_PATH}") + countly_log "Xcrun result:[$XCRUN_RES]" + RAW_UUID=$(echo "${XCRUN_RES}" | awk '{print $2}') + countly_log "Raw UUID:[$RAW_UUID]" + # Remove whitespace and such + BUILD_UUIDS=$(echo "${RAW_UUID}" | xargs | sed 's/ /,/g') + if [ $? -eq 0 ]; then + countly_log "Extracted Build UUIDs:[${BUILD_UUIDS}]" + else + countly_pass "Extracting Build UUIDs failed!" + fi + fi + + else + countly_pass "Extracting Build UUIDs failed!" + fi -# Creating archive of DSYM folder using zip -DSYM_ZIP_PATH="/tmp/$(date +%s)_${DSYM_FILE_NAME}.zip" -pushd "${DSYM_FOLDER_PATH}" > /dev/null -zip -rq "${DSYM_ZIP_PATH}" "${DSYM_FILE_NAME}" -popd > /dev/null -if [ $? -eq 0 ]; then - countly_log "Created archive at $DSYM_ZIP_PATH" -else - countly_fail "Creating archive failed!" -fi + # Creating archive of DSYM folder using zip + DSYM_ZIP_PATH="/tmp/$(date +%s)_${DSYM_FILE_NAME}.zip" + pushd "${DSYM_FOLDER_PATH}" > /dev/null + zip -rq "${DSYM_ZIP_PATH}" . -i "${DSYM_FILE_NAME}" + popd > /dev/null + if [ $? -eq 0 ]; then + countly_log "Created archive at $DSYM_ZIP_PATH" + else + countly_pass "Creating archive failed!" + fi -# Preparing for upload -ENDPOINT="/i/crash_symbols/upload_symbol" + # Preparing for upload + ENDPOINT="/i/crash_symbols/upload_symbol" -PLATFORM="ios" #This value is common for all iOS/iPadOS/watchOS/tvOS/macOS + PLATFORM="ios" #This value is common for all iOS/iPadOS/watchOS/tvOS/macOS -EPN=${EFFECTIVE_PLATFORM_NAME:1} -if [[ -z $EPN ]]; then -EPN="macos" -fi + EPN=${EFFECTIVE_PLATFORM_NAME:1} + if [[ -z $EPN ]]; then + EPN="macos" + fi -QUERY="?platform=${PLATFORM}&epn=${EPN}&app_key=${APPKEY}&build=${BUILD_UUIDS}" -URL="${HOST}${ENDPOINT}${QUERY}" -countly_log "Uploading to:[${URL}]" + QUERY="?platform=${PLATFORM}&epn=${EPN}&app_key=${APPKEY}&build=${BUILD_UUIDS}" + URL="${HOST}${ENDPOINT}${QUERY}" + countly_log "Uploading to:[${URL}]" -# Uploading to server using curl -UPLOAD_RESULT=$(curl -s -F "symbols=@${DSYM_ZIP_PATH}" "${URL}") -if [ $? -eq 0 ] && [ "${UPLOAD_RESULT}" == "{\"result\":\"Success\"}" ]; then - countly_log "dSYM upload succesfully completed." -else - countly_fail "dSYM upload failed! Response from the server:[${UPLOAD_RESULT}]" -fi + # Uploading to server using curl + UPLOAD_RESULT=$(curl -s -F "symbols=@${DSYM_ZIP_PATH}" "${URL}") + if [ $? -eq 0 ] && [ "${UPLOAD_RESULT}" == "{\"result\":\"Success\"}" ]; then + countly_log "dSYM upload succesfully completed." + else + countly_pass "dSYM upload failed! Response from the server:[${UPLOAD_RESULT}]" + fi -# Removing artifacts -rm "${DSYM_ZIP_PATH}" + # Removing artifacts + rm "${DSYM_ZIP_PATH}" + # return variables to default + DSYM_FILE_NAME=$INITIAL_DSYM_FILE_NAME + DSYM_FOLDER_PATH=$INITIAL_FOLDER_PATH +done exit 0