Skip to content

Commit

Permalink
Add SPM build workflow for CrowdinSDK
Browse files Browse the repository at this point in the history
Small fixes for macOS build.
Disable XCTestScreenshotsFeature for watchOS and tvOS.
  • Loading branch information
serhii-londar committed Dec 5, 2024
1 parent 5ded9d6 commit a2a2aa2
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 19 deletions.
35 changes: 32 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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? {
Expand All @@ -78,4 +96,10 @@ extension Label {
}
}

extension CWScreen {
static func scale() -> CGFloat {
return WKInterfaceDevice.current().screenScale
}
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import SafariServices
import AppKit
#endif
import Foundation
import WebKit


final class BrowserLoginFeature: NSObject, AnyLoginFeature {
var config: CrowdinLoginConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<XCUIElement>
Expand Down Expand Up @@ -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())
}
}

Expand All @@ -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: {
Expand All @@ -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)
Expand Down Expand Up @@ -134,3 +135,5 @@ extension CrowdinSDK {
_ = semaphore.wait(timeout: .distantFuture)
}
}

#endif

0 comments on commit a2a2aa2

Please sign in to comment.