Last active
February 9, 2024 11:37
-
-
Save litoarias/c0bfc784ab115ba06a8565703266b499 to your computer and use it in GitHub Desktop.
Archive, make XCFramework, manage Github Release and distribute XCFramework
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Check for arguments | |
if [ $# -eq 0 ]; then | |
echo "No arguments provided. First argument has to be version, e.g. '1.8.1', and second one the name of framework, e.g. 'NetworkModule'" | |
exit 1 | |
fi | |
# Set properties | |
FRAMEWORK_VERSION=$1 | |
FRAMEWORK_NAME=$2 | |
# 1. Remove old data for prevent issues for the new data | |
echo "Remove old xcframework resources..." | |
rm -rf "$FRAMEWORK_NAME.xcframework" | |
rm -rf "$FRAMEWORK_NAME.xcframework.zip" | |
rm -rf archives | |
rm -rf NetworkModuleDistribution | |
# 2. Archive framework (iOS) | |
echo "Building for iOS..." | |
xcodebuild archive -quiet \ | |
-scheme $FRAMEWORK_NAME \ | |
-sdk iphoneos \ | |
-archivePath "archives/ios_devices.xcarchive" \ | |
BUILD_LIBRARY_FOR_DISTRIBUTION=YES \ | |
SKIP_INSTALL=NO | |
# 3. Archive framework (iOS Simulators) | |
echo "Building for iOS Simulator..." | |
xcodebuild archive -quiet \ | |
-scheme $FRAMEWORK_NAME \ | |
-sdk iphonesimulator \ | |
-archivePath "archives/ios_simulators.xcarchive" \ | |
-arch x86_64 -arch arm64 \ | |
BUILD_LIBRARY_FOR_DISTRIBUTION=YES \ | |
SKIP_INSTALL=NO | |
# 4. Archive framework (Catalyst) | |
# echo "Building for Catalyst..." | |
# xcodebuild archive -quiet \ | |
# -scheme $FRAMEWORK_NAME \ | |
# MACOSX_DEPLOYMENT_TARGET=10.15 \ | |
# -destination "platform=macOS,variant=Mac Catalyst" \ | |
# -archivePath "archives/maccatalyst.xcarchive" \ | |
# BUILD_LIBRARY_FOR_DISTRIBUTION=YES \ | |
# SKIP_INSTALL=NO | |
# 4. Archive framework (macOS) | |
# echo "Building for macOS..." | |
# xcodebuild archive -quiet \ | |
# -scheme $FRAMEWORK_NAME \ | |
# -sdk macosx MACOSX_DEPLOYMENT_TARGET=11.0 \ | |
# -arch x86_64 -arch arm64 \ | |
# -archivePath "archives/macosx.xcarchive" \ | |
# BUILD_LIBRARY_FOR_DISTRIBUTION=YES \ | |
# SKIP_INSTALL=NO | |
# 5. Build XCFramework | |
echo "Building XCFramework..." | |
xcodebuild -create-xcframework -output "$FRAMEWORK_NAME.xcframework" \ | |
-framework "archives/ios_devices.xcarchive/Products/Library/Frameworks/$FRAMEWORK_NAME.framework" \ | |
-framework "archives/ios_simulators.xcarchive/Products/Library/Frameworks/$FRAMEWORK_NAME.framework" | |
# -framework "archives/maccatalyst.xcarchive/Products/Library/Frameworks/$FRAMEWORK_NAME.framework" \ | |
# -framework "archives/macosx.xcarchive/Products/Library/Frameworks/$FRAMEWORK_NAME.framework" | |
# 6. Compress XCframework for distribute on a hosted way | |
echo "Compressing XCFramework..." | |
zip -r -X "$FRAMEWORK_NAME.xcframework.zip" "$FRAMEWORK_NAME.xcframework" | |
# 7. Commit of all the changes generated in the creation of the XCFramework | |
echo "git commit and push" | |
git add . | |
git commit -m "New $FRAMEWORK_NAME.xcframework version $FRAMEWORK_VERSION" | |
git push | |
# 8. Github Release a new version | |
echo "Releasing the new version..." | |
gh release create "$FRAMEWORK_VERSION" --generate-notes | |
# 9. Clone distribution framework to manage from here the release and distribution via SPM | |
echo "Cloning distribution framework..." | |
git clone https://github.com/litoarias/${FRAMEWORK_NAME}Distribution ./${FRAMEWORK_NAME}Distribution | |
# 10. Move XCFramework generated to the Distribution repository | |
echo "Move XCFramework inside cloned repo..." | |
mv ${FRAMEWORK_NAME}.xcframework.zip ${FRAMEWORK_NAME}Distribution | |
# 11. Place to the cloned repo directory | |
echo "cd ${FRAMEWORK_NAME}Distribution..." | |
cd ${FRAMEWORK_NAME}Distribution | |
# 12. Launch prepare_package script within cloned repo | |
echo "sh prepare_package.sh $FRAMEWORK_VERSION $FRAMEWORK_NAME..." | |
sh prepare_package.sh $FRAMEWORK_VERSION $FRAMEWORK_NAME |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment