Reworked the script to remove old simulators instead

pull/959/head
Morgan Pretty 3 months ago
parent d56a674816
commit 38bd14240c

@ -92,6 +92,13 @@ local update_cocoapods_cache(depends_on) = {
// Unit tests
//
// The following 4 steps need to be run in order to run the unit tests
local clean_up_old_test_simulators = {
name: 'Clean Up Old Test Simulators',
commands: [
'./Scripts/clean-up-old-test-simulators.sh'
]
};
local pre_boot_test_sim = {
name: 'Pre-Boot Test Simulator',
commands: [
@ -105,35 +112,6 @@ local pre_boot_test_sim = {
]
};
local clean_up_test_simulator = {
name: 'Clean Up Test Simulator',
commands: [
|||
function handle_exit() {
xcrun simctl delete unavailable
if [ -e build/artifacts/sim_uuid ]; then
xcrun simctl delete $(<./build/artifacts/sim_uuid)
echo -e "\n\n\n\n\e[32mSimulator $(<./build/artifacts/sim_uuid) deleted.\e[0m\n\n\n"
else
echo -e "\n\n\n\n\e[31mSimulator not deleted.\e[0m\n\n\n"
fi
exit 0
}
trap handle_exit EXIT
while true; do
sleep 10
done
|||
// './Scripts/clean-up-test-simulator.sh $(<./build/artifacts/sim_uuid)'
],
depends_on: [
'Pre-Boot Test Simulator',
]
};
local build_and_run_tests = {
name: 'Build and Run Tests',
commands: [
@ -175,8 +153,8 @@ local unit_test_summary = {
clone_submodules,
load_cocoapods_cache,
install_cocoapods,
clean_up_old_test_simulators,
pre_boot_test_sim,
clean_up_test_simulator,
build_and_run_tests,
unit_test_summary,
update_cocoapods_cache(['Build and Run Tests'])
@ -245,8 +223,8 @@ local unit_test_summary = {
clone_submodules,
load_cocoapods_cache,
install_cocoapods,
clean_up_old_test_simulators,
pre_boot_test_sim,
clean_up_test_simulator,
build_and_run_tests,
unit_test_summary,
update_cocoapods_cache(['Build and Run Tests']),

@ -0,0 +1,53 @@
#!/usr/bin/env bash
#
# Script used with Drone CI to delete any test simulators created by the pipeline that are older than 1
# hour (the timeout for iOS builds) to ensure we don't waste too much HDD space with test simulators.
dir="$HOME/Library/Developer/CoreSimulator/Devices"
# Plist file
plist="${dir}/device_set.plist"
if [[ ! -f ${plist} ]]; then
echo -e "\e[31;1mXCode Simulator list not found.\e[0m"
exit 1
fi
# Delete any unavailable simulators
xcrun simctl delete unavailable
# Convert the plist to JSON and get the UUIDs
uuids=$(plutil -convert json -o - "$plist" | jq -r '.. | select(type=="string")')
# Create empty arrays to store the outputs
uuids_to_leave=()
uuids_to_remove=()
# Find directories older than an hour
while read -r dir; do
# Get the last component of the directory path
dir_name=$(basename "$dir")
# Check if the directory name is in the list of UUIDs
if ! echo "$uuids" | grep -q "$dir_name"; then
uuids_to_remove+=("$dir_name")
else
uuids_to_leave+=("$dir_name")
fi
done < <(find "$dir" -maxdepth 1 -type d -not -path "$dir" -mmin +60)
# Delete the simulators
if [ ${#uuids_to_remove[@]} -eq 0 ]; then
echo "\e[31mNo simulators to delete\e[0m"
else
echo -e "\e[31mDeleting ${#uuids_to_remove[@]} old test Simulators:\e[0m"
for uuid in "${uuids_to_remove[@]}"; do
echo -e "\e[31m $uuid\e[0m"
# xcrun simctl delete "$uuid"
done
fi
echo -e "\e[32m\nLeaving ${#uuids_to_leave[@]} Xcode Simulators:\e[0m"
for uuid in "${uuids_to_leave[@]}"; do
echo -e "\e[32m $uuid\e[0m"
done

@ -1,23 +0,0 @@
#!/usr/bin/env bash
#
# Script used with Drone CI to delete the simulator created for the unit tests when the pipline ends.
if [[ -z "$1" ]]; then
echo -e "\n\n\n\n\e[31;1mSimulator UUID not provided.\e[0m\n\n\n"
exit 1
fi
SIM_UUID="$1"
function handle_exit() {
xcrun simctl delete unavailable
xcrun simctl delete ${SIM_UUID}
echo -e "\n\n\n\n\e[32mSimulator ${SIM_UUID} deleted.\e[0m\n\n\n"
exit 0
}
trap handle_exit EXIT
while true; do
sleep 10
done
Loading…
Cancel
Save