Skip to content

Commit 5cbf6e5

Browse files
committed
[TECH] optimize swiftformat script
1 parent efca4fd commit 5cbf6e5

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

scripts/runSwiftFormat.sh

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ SWIFT_VERSION=5.9
55
cd "$(dirname "$0")"
66

77
function downloadAndUnzip {
8-
curl -L -o tool.zip $2
8+
echo "Downloading SwiftFormat from: $2"
9+
curl -L -f --retry 3 --retry-delay 1 -o tool.zip "$2"
10+
echo "Downloaded file size: $(ls -lh tool.zip | awk '{print $5}')"
911
unzip -o -d $1/ tool.zip
1012
rm tool.zip
1113
}
@@ -17,13 +19,44 @@ if ! which bin/swiftformat >/dev/null; then
1719
cd bin
1820
rm -r ./*
1921

22+
# Try downloading SwiftFormat 0.57.2 bundle
2023
downloadAndUnzip "SwiftFormatTmp" "https://github.com/nicklockwood/SwiftFormat/releases/download/0.57.2/swiftformat.artifactbundle.zip"
21-
mv -f ./SwiftFormatTmp/swiftformat.artifactbundle/swiftformat-0.57.2-macos/bin/swiftformat .
24+
25+
# Verify the correct version was downloaded
26+
if [ ! -d "./SwiftFormatTmp/swiftformat.artifactbundle/swiftformat-0.57.2-macos" ]; then
27+
echo "ERROR: Expected SwiftFormat 0.57.2 but got different version!"
28+
echo "Available versions in bundle:"
29+
find ./SwiftFormatTmp -name "swiftformat-*" -type d
30+
echo ""
31+
echo "This is likely a GitHub CDN/redirect issue. Trying alternative download method..."
32+
33+
# Clean up failed download
34+
rm -rf ./SwiftFormatTmp
35+
36+
# Try downloading the macOS binary directly from releases
37+
echo "Downloading macOS binary directly..."
38+
curl -L -f --retry 3 --retry-delay 1 -o swiftformat.zip "https://github.com/nicklockwood/SwiftFormat/releases/download/0.57.2/swiftformat.zip"
39+
if [ $? -ne 0 ]; then
40+
echo "ERROR: Failed to download SwiftFormat binary directly"
41+
exit 1
42+
fi
43+
44+
# Extract the binary from the zip
45+
unzip -o swiftformat.zip
46+
rm swiftformat.zip
47+
chmod +x swiftformat
48+
else
49+
# Bundle download succeeded, extract as normal
50+
mv -f ./SwiftFormatTmp/swiftformat.artifactbundle/swiftformat-0.57.2-macos/bin/swiftformat .
51+
fi
2252
find . -name "*Tmp" -type d -prune -exec rm -rf '{}' +
2353
for entry in ./*
2454
do
2555
chmod +x "$entry"
2656
done
57+
58+
# Verify the installed version
59+
echo "Installed SwiftFormat version: $(./swiftformat --version)"
2760
cd ../
2861
fi
2962

0 commit comments

Comments
 (0)