From a2a2aa28f6cff95e8ca45f750c78967da2aae91e Mon Sep 17 00:00:00 2001 From: Serhii Londar Date: Thu, 5 Dec 2024 23:00:16 +0100 Subject: [PATCH] Add SPM build workflow for CrowdinSDK Small fixes for macOS build. Disable XCTestScreenshotsFeature for watchOS and tvOS. --- .github/workflows/build.yml | 35 ++++++++++++++-- .../CrowdinSDK+PlatformsSupport.swift | 40 +++++++++++++++---- .../LoginFeature/BrowserLoginFeature.swift | 2 - .../ScreenshotFeature+XCTest.swift | 15 ++++--- 4 files changed, 73 insertions(+), 19 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f1f4d988..fb232f72 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -47,6 +47,35 @@ jobs: - name: Lint pod library run: pod lib lint --skip-tests --platforms=macos,ios,tvos + spm-build: + name: Build Swift Package + runs-on: macos-latest + strategy: + matrix: + platform: [iOS, macOS, tvOS, watchOS] + include: + - platform: iOS + destination: 'platform=iOS Simulator,name=iPhone 15' + - platform: macOS + destination: 'platform=macOS' + - platform: tvOS + destination: 'platform=tvOS Simulator,name=Apple TV' + - platform: watchOS + destination: 'platform=watchOS Simulator,name=Apple Watch Ultra 2 (49mm)' + steps: + - uses: actions/checkout@v4 + + - uses: maxim-lobanov/setup-xcode@v1 + with: + xcode-version: 15.4.0 + + - name: Install xcbeautify + run: brew install xcbeautify + + - name: Build Package for ${{ matrix.platform }} + run: | + xcodebuild build -scheme CrowdinSDK -destination '${{ matrix.destination }}' | xcbeautify && exit ${PIPESTATUS[0]} + build: name: Build runs-on: macos-latest @@ -57,8 +86,8 @@ jobs: working-directory: Example run: pod install - - name: Install xcpretty - run: gem install xcpretty + - name: Install xcbeautify + run: brew install xcbeautify - uses: maxim-lobanov/setup-xcode@v1 with: @@ -71,7 +100,7 @@ jobs: -workspace ./AppleReminders.xcworkspace \ -scheme AppleReminders \ -configuration Debug \ - -destination 'platform=iOS Simulator,name=iPhone SE (3rd generation)' | xcpretty && exit ${PIPESTATUS[0]} + -destination 'platform=iOS Simulator,name=iPhone SE (3rd generation)' | xcbeautify && exit ${PIPESTATUS[0]} # TODO: ObjCExample diff --git a/Sources/CrowdinSDK/CrowdinSDK/PlatformsSupport/CrowdinSDK+PlatformsSupport.swift b/Sources/CrowdinSDK/CrowdinSDK/PlatformsSupport/CrowdinSDK+PlatformsSupport.swift index 03f1f52c..1d598dd6 100644 --- a/Sources/CrowdinSDK/CrowdinSDK/PlatformsSupport/CrowdinSDK+PlatformsSupport.swift +++ b/Sources/CrowdinSDK/CrowdinSDK/PlatformsSupport/CrowdinSDK+PlatformsSupport.swift @@ -11,11 +11,12 @@ import Foundation import AppKit -typealias Label = NSTextField - public typealias View = NSView -typealias ViewController = NSViewController public typealias Image = NSImage +public typealias CWScreen = NSScreen + +typealias Label = NSTextField +typealias ViewController = NSViewController typealias Control = NSControl typealias Window = NSWindow typealias Application = NSApplication @@ -45,27 +46,44 @@ extension Label { } } } + +extension CWScreen { + static func scale() -> CGFloat { + return NSScreen.main?.backingScaleFactor ?? 1 + } +} + + #elseif os(iOS) || os(tvOS) import UIKit -typealias Label = UILabel public typealias View = UIView -typealias ViewController = UIViewController public typealias Image = UIImage +public typealias CWScreen = UIScreen + +typealias Label = UILabel +typealias ViewController = UIViewController typealias Window = UIWindow typealias Application = UIApplication +extension CWScreen { + static func scale() -> CGFloat { + return UIScreen.main.scale + } +} + #elseif os(watchOS) import WatchKit -typealias Label = WKInterfaceLabel public typealias View = WKInterfaceObject -typealias ViewController = WKInterfaceController public typealias Image = WKImage +public typealias CWScreen = WKInterfaceDevice + +typealias Label = WKInterfaceLabel +typealias ViewController = WKInterfaceController typealias Window = WKInterfaceController -//typealias Application = WKApplication extension Label { var text: String? { @@ -78,4 +96,10 @@ extension Label { } } +extension CWScreen { + static func scale() -> CGFloat { + return WKInterfaceDevice.current().screenScale + } +} + #endif diff --git a/Sources/CrowdinSDK/Features/LoginFeature/BrowserLoginFeature.swift b/Sources/CrowdinSDK/Features/LoginFeature/BrowserLoginFeature.swift index 30b35097..7492fec2 100644 --- a/Sources/CrowdinSDK/Features/LoginFeature/BrowserLoginFeature.swift +++ b/Sources/CrowdinSDK/Features/LoginFeature/BrowserLoginFeature.swift @@ -12,8 +12,6 @@ import SafariServices import AppKit #endif import Foundation -import WebKit - final class BrowserLoginFeature: NSObject, AnyLoginFeature { var config: CrowdinLoginConfig diff --git a/Sources/CrowdinSDK/Features/XCTestScreenshotFeature/ScreenshotFeature+XCTest.swift b/Sources/CrowdinSDK/Features/XCTestScreenshotFeature/ScreenshotFeature+XCTest.swift index bb3aaaa7..82927360 100644 --- a/Sources/CrowdinSDK/Features/XCTestScreenshotFeature/ScreenshotFeature+XCTest.swift +++ b/Sources/CrowdinSDK/Features/XCTestScreenshotFeature/ScreenshotFeature+XCTest.swift @@ -5,12 +5,13 @@ // Created by Serhii Londar on 27.11.2024. // import XCTest -import UIKit #if CrowdinSDKSPM import CrowdinSDK #endif +#if !os(watchOS) && !os(tvOS) + #if compiler(>=6.0) extension XCUIElementQuery: @retroactive Sequence { public typealias Iterator = AnyIterator @@ -71,7 +72,7 @@ extension XCUIElement { let end = CGPoint(x: start.x + frame.width, y: start.y + frame.height) let rect = CGRect(origin: start, size: CGSize(width: end.x - start.x, height: end.y - start.y)) - return rect.apply(scale: UIScreen.main.scale) + return rect.apply(scale: CWScreen.scale()) } } @@ -83,12 +84,12 @@ extension CGRect { extension CrowdinSDK { - public class func captureScreenshot(name: String, image: UIImage, application: XCUIApplication, success: @escaping (() -> Void), errorHandler: @escaping ((Error?) -> Void)) { + public class func captureScreenshot(name: String, image: Image, application: XCUIApplication, success: @escaping (() -> Void), errorHandler: @escaping ((Error?) -> Void)) { CrowdinSDK.captureScreenshot(name: name, screenshot: image, controlsInformation: application.getControlsInformation(), success: success, errorHandler: errorHandler) } - public class func captureScreenshotSync(name: String, image: UIImage, application: XCUIApplication) -> Error? { + public class func captureScreenshotSync(name: String, image: Image, application: XCUIApplication) -> Error? { var error: Error? let semaphore = DispatchSemaphore(value: 0) CrowdinSDK.captureScreenshot(name: name, screenshot: image, controlsInformation: application.getControlsInformation(), success: { }, errorHandler: { @@ -99,11 +100,11 @@ extension CrowdinSDK { return error } - public class func captureOrUpdateScreenshot(name: String, image: UIImage, application: XCUIApplication, success: @escaping ((ScreenshotUploadResult) -> Void), errorHandler: @escaping ((Error?) -> Void)) { + public class func captureOrUpdateScreenshot(name: String, image: Image, application: XCUIApplication, success: @escaping ((ScreenshotUploadResult) -> Void), errorHandler: @escaping ((Error?) -> Void)) { CrowdinSDK.captureOrUpdateScreenshot(name: name, screenshot: image, controlsInformation: application.getControlsInformation(), success: success, errorHandler: errorHandler) } - public class func captureOrUpdateScreenshotSync(name: String, image: UIImage, application: XCUIApplication) -> (result: ScreenshotUploadResult?, error: Error?) { + public class func captureOrUpdateScreenshotSync(name: String, image: Image, application: XCUIApplication) -> (result: ScreenshotUploadResult?, error: Error?) { var result: ScreenshotUploadResult? var error: Error? let semaphore = DispatchSemaphore(value: 0) @@ -134,3 +135,5 @@ extension CrowdinSDK { _ = semaphore.wait(timeout: .distantFuture) } } + +#endif