Skip to content

Instantly share code, notes, and snippets.

@bnickel
Created June 16, 2017 17:36
Show Gist options
  • Save bnickel/4d4b53bf80b06b0c3976837f6aa87a78 to your computer and use it in GitHub Desktop.
Save bnickel/4d4b53bf80b06b0c3976837f6aa87a78 to your computer and use it in GitHub Desktop.
I ran out of space on my build server because I was saving archives of every build. This script removed all archives with a given bundle ID, broken archives, and subsequent archives for a given bundle version. (Version bumps only happen on release builds for me.) It assumes that files are returned alphabetically and names have sortable dates.
#!/bin/sh
ARCHIVES="$HOME/Library/Developer/Xcode/Archives"
seen=()
for group in "$ARCHIVES"/*
do
for archive in "$group"/*
do
if [ "$archive" == "$group/*" ]
then
echo "DELETING empty folder $group"
rm -rf "$group"
continue
fi
plist="$archive"/Info.plist
if [ ! -f "$plist" ]
then
echo "DELETING $archive"
rm -rf "$archive"
continue
fi
bundle_name="$(/usr/libexec/PlistBuddy "$plist" -c "print :ApplicationProperties:CFBundleIdentifier")"
bundle_version="$(/usr/libexec/PlistBuddy "$plist" -c "print :ApplicationProperties:CFBundleVersion")"
key="$bundle_name-$bundle_version"
echo "$bundle_name $bundle_version"
if [[ "$bundle_name" == "com.stackexchange.stackexchange-debug" ]]
then
echo "DELETING $archive"
rm -rf "$archive"
continue
fi
if [[ " ${seen[@]} " =~ " ${key} " ]]
then
echo "SEEN BEFORE"
echo "DELETING $archive"
rm -rf "$archive"
continue
fi
seen=(${seen[@]} "$key")
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment