Skip to content

Commit

Permalink
Merge pull request #274 from Countly/updated-script
Browse files Browse the repository at this point in the history
Updated upload script
  • Loading branch information
ArtursKadikis authored Jan 12, 2024
2 parents e451b10 + 8fcb99f commit a94b08d
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 48 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
153 changes: 105 additions & 48 deletions countly_dsym_uploader.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
{
Expand Down Expand Up @@ -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

0 comments on commit a94b08d

Please sign in to comment.