Skip to content

Instantly share code, notes, and snippets.

@Nikoloutsos
Created November 16, 2023 12:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nikoloutsos/e517fed50fd5360c6b31720fb851d498 to your computer and use it in GitHub Desktop.
Save Nikoloutsos/e517fed50fd5360c6b31720fb851d498 to your computer and use it in GitHub Desktop.
Update all spm packages
#!/bin/bash
# Author: Konstantinos Nikoloutsos
# Specify the directory where your packages are organized inside
search_directory="."
echo "This script will iteratively update all dependencies in SPM Packages"
echo "❗️XCode will be forced quit & DerivedData will be cleaned if you continue.."
echo "(By doing that we guarantee that will not be any caches/conflicts with XCode)"
while true; do
read -n1 -p "Do you want to continue? (y/n): " answer
case $answer in
[Yy])
break
;;
[Nn])
echo "See ya next time 👋"
exit
;;
*)
echo "Invalid input. Please enter 'y' or 'n'."
;;
esac
done
# Force quiting XCode & Delete derived data
kill $(ps aux | grep "Xcode" | awk "{print $2}")
rm -rf ~/Library/Developer/Xcode/DerivedData
start_time=$(date +%s)
# Iterate through each subdirectory in the search_directory
for dir in "$search_directory"/*/; do
# Check if the directory contains a "Package.swift" file (indicating it's a Swift package)
if [ -f "$dir/Package.swift" ]; then
echo "Updating Swift package in $dir"
cd "$dir"
# Execute the 'swift package update' command
swift package update
# Change back to the original directory
cd -
fi
done
end_time=$(date +%s)
elapsed_time=$((end_time - start_time))
echo "Elapsed time: $elapsed_time seconds"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment