Skip to content

Instantly share code, notes, and snippets.

@andrealufino
Created June 12, 2023 08:18
Show Gist options
  • Save andrealufino/6560a36271025619a214ba3fece175cc to your computer and use it in GitHub Desktop.
Save andrealufino/6560a36271025619a214ba3fece175cc to your computer and use it in GitHub Desktop.
PATH=$PATH:/opt/homebrew/bin
# This script recognize the most recent xcresult file and copy to the clipboard a command that can be executed right away in the terminal to extract attachment from it.
# Create logs folder if not already present
logsFolder=${PROJECT_DIR}/Scripts/Logs
mkdir -p ${PROJECT_DIR}/Scripts/Logs
# Create log file in the Logs folder
myNameWithExtension=$(basename "$0")
myNameClean=${myNameWithExtension%.*}
exec > "$logsFolder/$myNameClean.log" 2>&1
set -o pipefail
set -e
# Put current date as yyyy-mm-dd HH:MM:SS in $date.
date=$(date '+%Y-%m-%d %H:%M:%S')
# Get the test result folder
subparent="$(dirname "$BUILD_DIR")"
derivedData="$(dirname "$subparent")"
testResultFolder="$derivedData/Logs/Test"
# Cycle all the files
files=($testResultFolder/*.xcresult)
# Get the most recent one (the last one)
mostRecentFilePath=${files[@]: -1}
mostRecentFileName=$(basename $mostRecentFilePath)
echo "$date"
echo "DerivedData path: $derivedData"
echo "Test result folder: $testResultFolder"
# echo "Files:"
# printf '%s\n' "${files[@]}"
echo "\nMost recent is $mostRecentFilePath"
screenshotsFolder=${PROJECT_DIR}/Screenshots
# This copy the command to the clipboard to quickly run it in a terminal session.
echo /opt/homebrew/bin/xcparse attachments $mostRecentFilePath $screenshotsFolder | pbcopy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment