Skip to content

Commit e9bbd09

Browse files
committed
Adding build script to update the Package.swift file
Creating update_swift_package.sh. This script relies on the OneSignal-XCFramework repo being in the same location as the OneSignal-iOS-SDK repo. The script zips the XCFramework in the OneSignal-iOS-SDK, computes its checksum (your command line must be using Swift tools 5.3 or later which comes with Xcode 12), writes the new checksum to the Package.swift file, then prompts for the new SDK version and updates the Package.swift file with the new version number. The zipped framework can then be dragged into the GitHub repo as a release asset
1 parent 7316e68 commit e9bbd09

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed
Binary file not shown.

Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ let package = Package(
1313
targets: [
1414
.binaryTarget(
1515
name: "OneSignal",
16-
url: "https://github.com/OneSignal/OneSignal-XCFramework/releases/download/3.1.0/OneSignal.xcframework.zip",
17-
checksum: "3f36d8f8f3bde549ae4409972b09088fe969c1845d3419dccf2e8a56ebeac25f"
16+
url: "https://github.com/OneSignal/OneSignal-iOS-SDK/releases/download/3.1.0/OneSignal.xcframework.zip",
17+
checksum: "b7a4bd8bc44bdca452dd19055e7efa20bb3c889a246ad824ba49cd0cbc9b3d86"
1818
)
1919
]
2020
)

update_swift_package.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/bash
2+
set -e
3+
4+
WORKING_DIR="../OneSignal-iOS-SDK/iOS_SDK/OneSignalSDK/"
5+
6+
FRAMEWORK_FOLDER_NAME="OneSignal_XCFramework"
7+
8+
FRAMEWORK_NAME="OneSignal"
9+
10+
FRAMEWORK_PATH="${WORKING_DIR}/${FRAMEWORK_FOLDER_NAME}/${FRAMEWORK_NAME}.xcframework"
11+
12+
FRAMEWORK_ZIP_PATH="${WORKING_DIR}/${FRAMEWORK_FOLDER_NAME}/${FRAMEWORK_NAME}.xcframework.zip"
13+
14+
SIMULATOR_ARCHIVE_PATH="${WORKING_DIR}/${FRAMEWORK_FOLDER_NAME}/simulator.xcarchive"
15+
16+
IOS_DEVICE_ARCHIVE_PATH="${WORKING_DIR}/${FRAMEWORK_FOLDER_NAME}/iOS.xcarchive"
17+
18+
CATALYST_ARCHIVE_PATH="${WORKING_DIR}/${FRAMEWORK_FOLDER_NAME}/catalyst.xcarchive"
19+
20+
SWIFT_PACKAGE_DIRECTORY=$(pwd)
21+
22+
SWIFT_PACKAGE_PATH="${SWIFT_PACKAGE_DIRECTORY}/Package.swift"
23+
24+
# Remove the old Zipped XCFramework and create a new Zip
25+
echo "Removing old Zipped XCFramework ${FRAMEWORK_ZIP_PATH}"
26+
rm -rf "${FRAMEWORK_ZIP_PATH}"
27+
echo "Creating new Zipped XCFramework ${FRAMEWORK_ZIP_PATH}"
28+
ditto -c -k --sequesterRsrc --keepParent "${FRAMEWORK_PATH}" "${FRAMEWORK_ZIP_PATH}"
29+
30+
# Compute the checksum for the Zipped framework
31+
echo "Computing package checksum and updating Package.swift ${SWIFT_PACKAGE_PATH}"
32+
CHECKSUM=$(swift package compute-checksum "${FRAMEWORK_ZIP_PATH}")
33+
SWIFT_PM_CHECKSUM_LINE=" checksum: \"${CHECKSUM}\""
34+
# Use sed to remove line 17 from the Swift.package and replace it with the new checksum
35+
sed -i '' "17s/.*/$SWIFT_PM_CHECKSUM_LINE/" "${SWIFT_PACKAGE_PATH}"
36+
#Ask for the new release version number to be placed in the package URL
37+
echo -e "\033[1mEnter the new SDK release version number\033[0m"
38+
read VERSION_NUMBER
39+
SWIFT_PM_URL_LINE=" url: \"https:\/\/github.com\/OneSignal\/OneSignal-iOS-SDK\/releases\/download\/${VERSION_NUMBER}\/OneSignal.xcframework.zip\","
40+
# Use sed to remove line 16 from the Swift.package and replace it with the new URL for the new release
41+
sed -i '' "16s/.*/$SWIFT_PM_URL_LINE/" "${SWIFT_PACKAGE_PATH}"
42+
#Open XCFramework folder to drag zip into new release
43+
open "${WORKING_DIR}/${FRAMEWORK_FOLDER_NAME}"
44+

0 commit comments

Comments
 (0)