From 4ceefd6ac17cd7748a9d14fd00031fcccda93284 Mon Sep 17 00:00:00 2001 From: Jae Kim Date: Fri, 28 Apr 2023 19:01:48 -0700 Subject: [PATCH 1/4] fix import UIKit --- Sources/Protocols/BackgroundingCallbacks.swift | 4 +++- Sources/Utils/Utils.swift | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Sources/Protocols/BackgroundingCallbacks.swift b/Sources/Protocols/BackgroundingCallbacks.swift index fdfbb4550..f501afaa8 100644 --- a/Sources/Protocols/BackgroundingCallbacks.swift +++ b/Sources/Protocols/BackgroundingCallbacks.swift @@ -17,7 +17,9 @@ import Foundation #if os(macOS) import Cocoa -#else // iOS, tvOS +#elseif os(watchOS) +import WatchKit +#else import UIKit #endif diff --git a/Sources/Utils/Utils.swift b/Sources/Utils/Utils.swift index 60068f24a..6ce57f670 100644 --- a/Sources/Utils/Utils.swift +++ b/Sources/Utils/Utils.swift @@ -15,7 +15,9 @@ // import Foundation -#if os(watchOS) +#if os(macOS) +import Cocoa +#elseif os(watchOS) import WatchKit #else import UIKit From e3f5781bc821d58d45cb14e6dcc5236b6d2ef270 Mon Sep 17 00:00:00 2001 From: Jae Kim Date: Mon, 1 May 2023 13:27:35 -0700 Subject: [PATCH 2/4] support macOS/watchOS build --- Scripts/build_all.sh | 2 ++ Sources/Protocols/BackgroundingCallbacks.swift | 7 ++++--- Sources/Utils/Utils.swift | 11 ++++++++--- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Scripts/build_all.sh b/Scripts/build_all.sh index 5b7283976..f1fc8bdd0 100755 --- a/Scripts/build_all.sh +++ b/Scripts/build_all.sh @@ -32,6 +32,8 @@ main() { xcodebuild -workspace OptimizelySwiftSDK.xcworkspace -scheme OptimizelySwiftSDK-iOS -configuration Release "${action}" xcodebuild -workspace OptimizelySwiftSDK.xcworkspace -scheme OptimizelySwiftSDK-tvOS -configuration Release "${action}" + xcodebuild -workspace OptimizelySwiftSDK.xcworkspace -scheme OptimizelySwiftSDK-macOS -configuration Release "${action}" + xcodebuild -workspace OptimizelySwiftSDK.xcworkspace -scheme OptimizelySwiftSDK-watchOS -configuration Release "${action}" } main diff --git a/Sources/Protocols/BackgroundingCallbacks.swift b/Sources/Protocols/BackgroundingCallbacks.swift index f501afaa8..958c20236 100644 --- a/Sources/Protocols/BackgroundingCallbacks.swift +++ b/Sources/Protocols/BackgroundingCallbacks.swift @@ -15,10 +15,11 @@ // import Foundation -#if os(macOS) -import Cocoa -#elseif os(watchOS) + +#if os(watchOS) import WatchKit +#elseif os(macOS) +import Cocoa #else import UIKit #endif diff --git a/Sources/Utils/Utils.swift b/Sources/Utils/Utils.swift index 6ce57f670..62a907ca1 100644 --- a/Sources/Utils/Utils.swift +++ b/Sources/Utils/Utils.swift @@ -15,10 +15,11 @@ // import Foundation -#if os(macOS) -import Cocoa -#elseif os(watchOS) + +#if os(watchOS) import WatchKit +#elseif os(macOS) +import Cocoa #else import UIKit #endif @@ -46,6 +47,8 @@ class Utils { static var osVersion: String { #if os(watchOS) return WKInterfaceDevice.current().systemVersion + #elseif os(macOS) + return ProcessInfo().operatingSystemVersionString #else return UIDevice.current.systemVersion #endif @@ -54,6 +57,8 @@ class Utils { static var deviceModel: String { #if os(watchOS) return WKInterfaceDevice.current().model + #elseif os(macOS) + return "N/A" #else return UIDevice.current.model #endif From 424d3ee83e1eb329b495c6179fb03af63403704e Mon Sep 17 00:00:00 2001 From: Jae Kim Date: Mon, 1 May 2023 14:10:11 -0700 Subject: [PATCH 3/4] add version validation --- CHANGELOG.md | 2 +- Scripts/run_prep.sh | 4 ---- Sources/Utils/Utils.swift | 10 +++++++++- .../OptimizelyTests-Common/OdpEventManagerTests.swift | 4 ++-- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ef7eb4b34..b5b7f1f8b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ # Optimizely Swift SDK Changelog ## 4.0.0-beta -April 28, 2023 +May 1, 2023 ### New Features diff --git a/Scripts/run_prep.sh b/Scripts/run_prep.sh index ec1a03ff8..cf985c172 100755 --- a/Scripts/run_prep.sh +++ b/Scripts/run_prep.sh @@ -7,10 +7,6 @@ # Additionally, it needs the following environment variables: # VERSION - defined in swift.yml - -set -x - - COLOR_RESET='\033[0m' COLOR_MAGENTA='\033[0;35m' COLOR_CYAN='\033[0;36m' diff --git a/Sources/Utils/Utils.swift b/Sources/Utils/Utils.swift index 62a907ca1..480cf514d 100644 --- a/Sources/Utils/Utils.swift +++ b/Sources/Utils/Utils.swift @@ -112,7 +112,7 @@ class Utils { static func isStringType(_ value: Any) -> Bool { return (value is String) } - + // MARK: - NSNumber static func isNSNumberBoolType(_ value: Any) -> Bool { @@ -195,4 +195,12 @@ class Utils { } return "Invalid conditions format." } + + // valid versions: 3.0, 2.1.2, 1.0.0-beta, ... + // invalid versions: "mac os 10.3", ... + static func isValidVersion(_ version: String) -> Bool { + let comps = version.split(separator: ".") + return comps.count > 1 && Int(comps.first!) != nil + } + } diff --git a/Tests/OptimizelyTests-Common/OdpEventManagerTests.swift b/Tests/OptimizelyTests-Common/OdpEventManagerTests.swift index 4d4e24437..c6d16a873 100644 --- a/Tests/OptimizelyTests-Common/OdpEventManagerTests.swift +++ b/Tests/OptimizelyTests-Common/OdpEventManagerTests.swift @@ -559,8 +559,8 @@ class OdpEventManagerTests: XCTestCase { XCTAssert((data["idempotence_id"] as! String).count > 3) XCTAssert((data["data_source_type"] as! String) == "sdk") XCTAssert((data["data_source"] as! String) == "swift-sdk") - XCTAssert((data["data_source_version"] as! String).count > 3) - XCTAssert((data["os_version"] as! String).count > 3) + XCTAssert(Utils.isValidVersion(data["data_source_version"] as! String)) + XCTAssert(Utils.isValidVersion(data["os_version"] as! String)) // os-dependent From 78bfefce9a4cc0b9cf45bd948b2b4b2272c7ea53 Mon Sep 17 00:00:00 2001 From: Jae Kim Date: Mon, 1 May 2023 15:34:42 -0700 Subject: [PATCH 4/4] fix git describe error --- Scripts/run_release.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Scripts/run_release.sh b/Scripts/run_release.sh index 1a239b76d..2f284a4b1 100755 --- a/Scripts/run_release.sh +++ b/Scripts/run_release.sh @@ -8,7 +8,7 @@ set -e # COCOAPODS_TRUNK_TOKEN - should be defined in job settings so that we can `pod trunk push` function release_github { - LAST_RELEASE=$(git describe --abbrev=0 --tags) + LAST_RELEASE=$(git describe --abbrev=0 --tags --always) if [[ ${LAST_RELEASE} == "v${VERSION}" ]]; then echo "${LAST_RELEASE} tag exists already (probably created while in the current release process). Skipping..." return