Skip to content

Commit 6d2441a

Browse files
nan-liclaude
andcommitted
fix: update_swift_package.sh matches binary targets by name, not line number
The script rewrote Package.swift by hardcoded line numbers. When #1667 added 3 dependency lines above the binary targets, those numbers drifted and the 5.5.2 release overwrote the .binaryTarget boundaries, producing an unparseable manifest that broke SwiftPM consumers. Locate each .binaryTarget by the framework name in its url line and rewrite only the version and the following checksum in place, preserving structure so layout shifts can't corrupt it. Add fail-loud guards (empty checksum, missing url/checksum) so a future mismatch errors instead of silently corrupting. Verified end-to-end: reproduces the known-good 5.5.2 manifest byte-for-byte and a missing target now exits non-zero. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent dc7bf7e commit 6d2441a

1 file changed

Lines changed: 47 additions & 17 deletions

File tree

iOS_SDK/OneSignalSDK/update_swift_package.sh

Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,43 +36,73 @@ update_framework() {
3636
# Compute the checksum for the Zipped framework
3737
echo "Computing package checksum and updating Package.swift ${SWIFT_PACKAGE_PATH}"
3838
CHECKSUM=$(swift package compute-checksum "${FRAMEWORK_ZIP_PATH}")
39-
SWIFT_PM_CHECKSUM_LINE=" checksum: \"${CHECKSUM}\""
40-
41-
# Use sed to remove line from the Swift.package and replace it with the new checksum
42-
sed -i '' "$3s/.*/$SWIFT_PM_CHECKSUM_LINE/" "${SWIFT_PACKAGE_PATH}"
43-
SWIFT_PM_URL_LINE=" url: \"https:\/\/github.com\/OneSignal\/OneSignal-iOS-SDK\/releases\/download\/${VERSION_NUMBER}\/${FRAMEWORK_NAME}.xcframework.zip\","
44-
#Use sed to remove line from the Swift.package and replace it with the new URL for the new release
45-
sed -i '' "$4s/.*/$SWIFT_PM_URL_LINE/" "${SWIFT_PACKAGE_PATH}"
39+
if [ -z "${CHECKSUM}" ]; then
40+
echo "ERROR: empty checksum computed for ${FRAMEWORK_NAME}" >&2
41+
exit 1
42+
fi
43+
# Update this framework's .binaryTarget in place, located by the framework
44+
# name in its url line (NOT by hardcoded line number). Only the version in the
45+
# url and the hash in the following checksum line are rewritten; surrounding
46+
# structure/formatting is preserved. Matching by name keeps this correct even
47+
# when the manifest layout shifts -- the previous line-number approach silently
48+
# corrupted Package.swift once unrelated lines moved (broke 5.5.2 SPM).
49+
awk -v fw="${FRAMEWORK_NAME}" -v ver="${VERSION_NUMBER}" -v chk="${CHECKSUM}" '
50+
$0 ~ ("url: \"https://github.com/OneSignal/OneSignal-iOS-SDK/releases/download/[^/]*/" fw "\\.xcframework\\.zip\"") {
51+
sub("download/[^/]*/", "download/" ver "/")
52+
print
53+
in_target = 1
54+
next
55+
}
56+
in_target && /checksum: "/ {
57+
sub("checksum: \"[0-9a-fA-F]*\"", "checksum: \"" chk "\"")
58+
print
59+
in_target = 0
60+
next
61+
}
62+
{ print }
63+
' "${SWIFT_PACKAGE_PATH}" > "${SWIFT_PACKAGE_PATH}.tmp"
64+
mv "${SWIFT_PACKAGE_PATH}.tmp" "${SWIFT_PACKAGE_PATH}"
65+
66+
# Fail loudly if the entry was not found/updated, instead of silently leaving
67+
# the manifest stale or malformed.
68+
if ! grep -q "releases/download/${VERSION_NUMBER}/${FRAMEWORK_NAME}.xcframework.zip" "${SWIFT_PACKAGE_PATH}"; then
69+
echo "ERROR: could not find/update url for ${FRAMEWORK_NAME} in Package.swift" >&2
70+
exit 1
71+
fi
72+
if ! grep -q "checksum: \"${CHECKSUM}\"" "${SWIFT_PACKAGE_PATH}"; then
73+
echo "ERROR: could not update checksum for ${FRAMEWORK_NAME} in Package.swift" >&2
74+
exit 1
75+
fi
4676
#Open XCFramework folder to drag zip into new release
4777
open "${WORKING_DIR}/${FRAMEWORK_FOLDER_NAME}"
4878
}
4979

5080
## OneSignal LiveActivities ##
51-
update_framework "OneSignal_LiveActivities" "OneSignalLiveActivities" "163" "162"
81+
update_framework "OneSignal_LiveActivities" "OneSignalLiveActivities"
5282

5383
## OneSignal Core ##
54-
update_framework "OneSignal_Core" "OneSignalCore" "158" "157"
84+
update_framework "OneSignal_Core" "OneSignalCore"
5585

5686
## OneSignal OSCore ##
57-
update_framework "OneSignal_OSCore" "OneSignalOSCore" "153" "152"
87+
update_framework "OneSignal_OSCore" "OneSignalOSCore"
5888

5989
## OneSignal Outcomes ##
60-
update_framework "OneSignal_Outcomes" "OneSignalOutcomes" "148" "147"
90+
update_framework "OneSignal_Outcomes" "OneSignalOutcomes"
6191

6292
## OneSignal Extension ##
63-
update_framework "OneSignal_Extension" "OneSignalExtension" "143" "142"
93+
update_framework "OneSignal_Extension" "OneSignalExtension"
6494

6595
## OneSignal Notifications ##
66-
update_framework "OneSignal_Notifications" "OneSignalNotifications" "138" "137"
96+
update_framework "OneSignal_Notifications" "OneSignalNotifications"
6797

6898
## OneSignal User ##
69-
update_framework "OneSignal_User" "OneSignalUser" "133" "132"
99+
update_framework "OneSignal_User" "OneSignalUser"
70100

71101
## OneSignal Location ##
72-
update_framework "OneSignal_Location" "OneSignalLocation" "128" "127"
102+
update_framework "OneSignal_Location" "OneSignalLocation"
73103

74104
## OneSignal InAppMessages ##
75-
update_framework "OneSignal_InAppMessages" "OneSignalInAppMessages" "123" "122"
105+
update_framework "OneSignal_InAppMessages" "OneSignalInAppMessages"
76106

77107
## OneSignal ##
78-
update_framework "OneSignal_XCFramework" "OneSignalFramework" "118" "117"
108+
update_framework "OneSignal_XCFramework" "OneSignalFramework"

0 commit comments

Comments
 (0)